- 新增 addComment/getComments/getFollowList/followUser/getUser/updateProfile/updatePet/deletePet 云函数并完成部署 - 统一通过 app.globalData.navBarInfo 避让系统胶囊按钮(编辑资料/编辑宠物等页面保存按钮被遮挡问题) - 编辑资料页所在城市改为省份 picker 选择 - 修复"我的"页动态为空(getUserPosts 应传 openid 而非数据库 _id) - 重构编辑宠物页:品种改用 picker 滚轮(替代有数量上限的 actionSheet),标签改用 selectedTagSet 映射 + 自定义标签输入(5字以内、仅中英文/数字、最多8个) - 接通宠物保存/删除真实云函数调用并同步本地缓存 - 移除 feed 页对不存在的 getStories 云函数调用,修复模拟器卡死 - 移除 post 页对不存在的 wx.reverseGeocoder API 的调用 - 统一扩展 AppGlobalData 类型并修正所有 getApp 调用的泛型,解决 TS 报错
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { UserProfile, AppGlobalData } from '../../types/index'
|
|
import { api } from '../../utils/api'
|
|
import { getAvatarGradient } from '../../utils/format'
|
|
|
|
const app = getApp<{ globalData: AppGlobalData }>()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 0,
|
|
navbarHeight: 44,
|
|
navbarPaddingRight: 0,
|
|
tabBarHeight: 56,
|
|
activeTab: 'following' as 'following' | 'followers',
|
|
list: [] as any[],
|
|
followingCount: 0,
|
|
followersCount: 0,
|
|
loading: false,
|
|
refreshing: false,
|
|
},
|
|
|
|
onLoad() {
|
|
const info = wx.getSystemInfoSync()
|
|
const { statusBarHeight, navbarHeight, navbarPaddingRight } = app.globalData.navBarInfo
|
|
this.setData({
|
|
statusBarHeight,
|
|
navbarHeight,
|
|
navbarPaddingRight,
|
|
tabBarHeight: info.windowHeight - (info.safeArea?.bottom ?? info.windowHeight) + 56,
|
|
})
|
|
this.loadList()
|
|
},
|
|
|
|
onShow() {
|
|
const tabBar = this.getTabBar() as any
|
|
tabBar?.setSelected?.(2)
|
|
},
|
|
|
|
async loadList() {
|
|
this.setData({ loading: true })
|
|
try {
|
|
const list = await api.getFollowList(this.data.activeTab)
|
|
const enriched = list.map(u => ({
|
|
...u,
|
|
gradient: getAvatarGradient(u._id),
|
|
isOnline: u.isOnline,
|
|
}))
|
|
this.setData({
|
|
list: enriched,
|
|
[this.data.activeTab === 'following' ? 'followingCount' : 'followersCount']: list.length,
|
|
})
|
|
} catch {
|
|
wx.showToast({ title: '加载失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false, refreshing: false })
|
|
}
|
|
},
|
|
|
|
switchTab(e: WechatMiniprogram.CustomEvent) {
|
|
const tab = e.currentTarget.dataset.tab as 'following' | 'followers'
|
|
if (tab === this.data.activeTab) return
|
|
this.setData({ activeTab: tab, list: [] })
|
|
this.loadList()
|
|
},
|
|
|
|
async onFollowTap(e: WechatMiniprogram.CustomEvent) {
|
|
const uid = e.currentTarget.dataset.uid as string
|
|
try {
|
|
await api.followUser(uid)
|
|
if (this.data.activeTab === 'following') {
|
|
const list = this.data.list.filter((u: any) => u._id !== uid)
|
|
this.setData({ list, followingCount: list.length })
|
|
}
|
|
} catch {
|
|
wx.showToast({ title: '操作失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
onItemTap(e: WechatMiniprogram.CustomEvent) {
|
|
const uid = e.currentTarget.dataset.uid
|
|
wx.navigateTo({ url: `/pages/pet-detail/pet-detail?userId=${uid}` })
|
|
},
|
|
|
|
onFindFriends() {
|
|
wx.switchTab({ url: '/pages/nearby/nearby' })
|
|
},
|
|
|
|
onGoNearby() {
|
|
wx.switchTab({ url: '/pages/nearby/nearby' })
|
|
},
|
|
|
|
async onRefresh() {
|
|
this.setData({ refreshing: true })
|
|
await this.loadList()
|
|
},
|
|
})
|