fix: 修复评论/资料/导航胶囊/宠物档案/定位等多处问题,补全相关云函数
- 新增 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 报错
This commit is contained in:
@@ -1,7 +1,43 @@
|
||||
import { api } from '../../utils/api'
|
||||
import { formatTime, getAvatarGradient } from '../../utils/format'
|
||||
import { AppGlobalData } from '../../types/index'
|
||||
|
||||
const app = getApp<{ userInfo: any }>()
|
||||
const app = getApp<{ globalData: AppGlobalData }>()
|
||||
|
||||
function normalizeAuthor(author: any, authorId = '') {
|
||||
return {
|
||||
...(author || {}),
|
||||
nickName: author?.nickName || '匿名用户',
|
||||
avatarUrl: author?.avatarUrl || '',
|
||||
openid: author?.openid || authorId,
|
||||
}
|
||||
}
|
||||
|
||||
function normalizePost(post: any) {
|
||||
return {
|
||||
authorId: '',
|
||||
...(post || {}),
|
||||
author: normalizeAuthor(post?.author, post?.authorId),
|
||||
content: post?.content || '',
|
||||
images: Array.isArray(post?.images) ? post.images : [],
|
||||
hashtags: Array.isArray(post?.hashtags) ? post.hashtags : [],
|
||||
likeCount: typeof post?.likeCount === 'number' ? post.likeCount : 0,
|
||||
commentCount: typeof post?.commentCount === 'number' ? post.commentCount : 0,
|
||||
createdAt: post?.createdAt || '',
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeComment(comment: any) {
|
||||
return {
|
||||
authorId: '',
|
||||
...(comment || {}),
|
||||
author: normalizeAuthor(comment?.author, comment?.authorId),
|
||||
content: comment?.content || '',
|
||||
createdAt: comment?.createdAt || '',
|
||||
gradient: getAvatarGradient(comment?.authorId || ''),
|
||||
timeText: comment?.createdAt ? formatTime(comment.createdAt) : '',
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -14,15 +50,17 @@ Page({
|
||||
likeCount: 0,
|
||||
commentText: '',
|
||||
focusInput: false,
|
||||
pendingFocusComment: false,
|
||||
},
|
||||
|
||||
onLoad(query: { id?: string; focus?: string }) {
|
||||
const info = wx.getSystemInfoSync()
|
||||
this.setData({ statusBarHeight: info.statusBarHeight, postId: query.id || '' })
|
||||
this.setData({
|
||||
statusBarHeight: info.statusBarHeight,
|
||||
postId: query.id || '',
|
||||
pendingFocusComment: query.focus === 'comment',
|
||||
})
|
||||
this.loadPost(query.id || '')
|
||||
if (query.focus === 'comment') {
|
||||
this.setData({ focusInput: true })
|
||||
}
|
||||
},
|
||||
|
||||
async loadPost(id: string) {
|
||||
@@ -32,14 +70,19 @@ Page({
|
||||
name: 'getPost',
|
||||
data: { postId: id },
|
||||
}) as any
|
||||
const post = res.result?.data
|
||||
if (!post) return
|
||||
const post = normalizePost(res.result?.data)
|
||||
if (!post?._id) return
|
||||
this.setData({
|
||||
post,
|
||||
avatarGradient: getAvatarGradient(post.authorId),
|
||||
timeText: formatTime(post.createdAt),
|
||||
avatarGradient: getAvatarGradient(post.authorId || ''),
|
||||
timeText: post.createdAt ? formatTime(post.createdAt) : '',
|
||||
likeCount: post.likeCount,
|
||||
})
|
||||
if (this.data.pendingFocusComment) {
|
||||
wx.nextTick(() => {
|
||||
this.setData({ focusInput: true, pendingFocusComment: false })
|
||||
})
|
||||
}
|
||||
this.loadComments(id)
|
||||
} catch {}
|
||||
},
|
||||
@@ -47,11 +90,7 @@ Page({
|
||||
async loadComments(postId: string) {
|
||||
try {
|
||||
const res = await api.getComments(postId)
|
||||
const comments = res.list.map((c: any) => ({
|
||||
...c,
|
||||
gradient: getAvatarGradient(c.authorId),
|
||||
timeText: formatTime(c.createdAt),
|
||||
}))
|
||||
const comments = res.list.map(normalizeComment)
|
||||
this.setData({ comments })
|
||||
} catch {}
|
||||
},
|
||||
@@ -73,6 +112,10 @@ Page({
|
||||
this.setData({ commentText: e.detail.value })
|
||||
},
|
||||
|
||||
onCommentBlur() {
|
||||
this.setData({ focusInput: false })
|
||||
},
|
||||
|
||||
async onSend() {
|
||||
const text = this.data.commentText.trim()
|
||||
if (!text || !this.data.postId) return
|
||||
@@ -81,11 +124,7 @@ Page({
|
||||
await api.addComment(this.data.postId, text)
|
||||
const comments = await api.getComments(this.data.postId)
|
||||
this.setData({
|
||||
comments: comments.list.map((c: any) => ({
|
||||
...c,
|
||||
gradient: getAvatarGradient(c.authorId),
|
||||
timeText: formatTime(c.createdAt),
|
||||
})),
|
||||
comments: comments.list.map(normalizeComment),
|
||||
})
|
||||
} catch {
|
||||
wx.showToast({ title: '发送失败', icon: 'none' })
|
||||
|
||||
Reference in New Issue
Block a user