chore: 清理冗余代码并补全私信/搜索/故事/通知功能
- 删除未使用的空组件目录、死代码导出(clearAuth/calcDistance/COLORS/ AVATAR_GRADIENTS/Message/TabBarItem/deletePost/uploadImage/getFileURL/ _initLogin),确保程序仍可正常运行 - 新增 8 个云函数并补全对应页面逻辑:getMessages/sendMessage(私信聊天)、 getHotTopics/searchPosts/searchUsers(搜索)、getStory(故事,复用 posts 集合)、getNotifications/markAllRead(基于点赞评论聚合的通知系统) - 在 cloudbaserc.json 中注册全部新云函数,并通过 --deployMode zip 完成部署 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ Page({
|
||||
onLoad(query: { userId?: string }) {
|
||||
const info = wx.getSystemInfoSync()
|
||||
this.setData({ statusBarHeight: info.statusBarHeight, peerId: query.userId || '' })
|
||||
this.loadPeerInfo()
|
||||
this.loadMessages()
|
||||
this.subscribeRealtime()
|
||||
},
|
||||
@@ -26,9 +27,18 @@ Page({
|
||||
this._watcher?.close()
|
||||
},
|
||||
|
||||
async loadMessages() {
|
||||
async loadPeerInfo() {
|
||||
if (!this.data.peerId) return
|
||||
try {
|
||||
const res = await api.getMessages()
|
||||
const user = await api.getUserProfile(this.data.peerId)
|
||||
this.setData({ peerName: user.nickName || '宠物爱好者' })
|
||||
} catch {}
|
||||
},
|
||||
|
||||
async loadMessages() {
|
||||
if (!this.data.peerId) return
|
||||
try {
|
||||
const res = await api.getMessages(this.data.peerId)
|
||||
const msgs = res.list.map((m: any) => ({
|
||||
...m,
|
||||
isMe: m.fromId === app.globalData?.userInfo?._id,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { api } from '../../utils/api'
|
||||
import { getAvatarGradient, formatTime } from '../../utils/format'
|
||||
|
||||
Page({
|
||||
@@ -11,13 +12,13 @@ Page({
|
||||
|
||||
async loadNotifications() {
|
||||
try {
|
||||
const res = await wx.cloud.callFunction({ name: 'getNotifications', data: {} }) as any
|
||||
const list = (res.result?.data || []).map((n: any) => ({
|
||||
const list = await api.getNotifications()
|
||||
const enriched = (list || []).map((n: any) => ({
|
||||
...n,
|
||||
gradient: getAvatarGradient(n.fromId || ''),
|
||||
timeText: formatTime(n.createdAt),
|
||||
}))
|
||||
this.setData({ list })
|
||||
this.setData({ list: enriched })
|
||||
} catch {}
|
||||
},
|
||||
|
||||
@@ -27,7 +28,7 @@ Page({
|
||||
},
|
||||
|
||||
onReadAll() {
|
||||
wx.cloud.callFunction({ name: 'markAllRead', data: {} }).catch(() => {})
|
||||
api.markAllRead().catch(() => {})
|
||||
const list = this.data.list.map((n: any) => ({ ...n, isRead: true }))
|
||||
this.setData({ list })
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { api } from '../../utils/api'
|
||||
import { getAvatarGradient } from '../../utils/format'
|
||||
|
||||
Page({
|
||||
@@ -19,8 +20,8 @@ Page({
|
||||
|
||||
async loadHotTopics() {
|
||||
try {
|
||||
const res = await wx.cloud.callFunction({ name: 'getHotTopics', data: {} }) as any
|
||||
this.setData({ hotTopics: res.result?.data || [] })
|
||||
const topics = await api.getHotTopics()
|
||||
this.setData({ hotTopics: topics || [] })
|
||||
} catch {}
|
||||
},
|
||||
|
||||
@@ -38,12 +39,12 @@ Page({
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const [posts, users] = await Promise.all([
|
||||
wx.cloud.callFunction({ name: 'searchPosts', data: { keyword: kw } }) as any,
|
||||
wx.cloud.callFunction({ name: 'searchUsers', data: { keyword: kw } }) as any,
|
||||
api.searchPosts(kw),
|
||||
api.searchUsers(kw),
|
||||
])
|
||||
this.setData({
|
||||
postResults: posts.result?.data || [],
|
||||
userResults: (users.result?.data || []).map((u: any) => ({
|
||||
postResults: posts || [],
|
||||
userResults: (users || []).map((u: any) => ({
|
||||
...u,
|
||||
gradient: getAvatarGradient(u._id),
|
||||
})),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { api } from '../../utils/api'
|
||||
import { getAvatarGradient, formatTime } from '../../utils/format'
|
||||
|
||||
const DURATION = 5000
|
||||
@@ -22,15 +23,18 @@ Page({
|
||||
|
||||
async loadStory(id: string) {
|
||||
try {
|
||||
const res = await wx.cloud.callFunction({ name: 'getStory', data: { id } }) as any
|
||||
const stories = (res.result?.data || []).map((s: any) => ({
|
||||
const list = await api.getStory(id)
|
||||
const stories = (list || []).map((s: any) => ({
|
||||
...s,
|
||||
gradient: getAvatarGradient(s.authorId),
|
||||
timeText: formatTime(s.createdAt),
|
||||
}))
|
||||
this.setData({ stories, currentStory: stories[0] || {} })
|
||||
this.startProgress()
|
||||
} catch {}
|
||||
if (stories.length) this.startProgress()
|
||||
else wx.navigateBack()
|
||||
} catch {
|
||||
wx.navigateBack()
|
||||
}
|
||||
},
|
||||
|
||||
startProgress() {
|
||||
|
||||
Reference in New Issue
Block a user