- 删除未使用的空组件目录、死代码导出(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>
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { api } from '../../utils/api'
|
|
import { getAvatarGradient, formatTime } from '../../utils/format'
|
|
|
|
const DURATION = 5000
|
|
|
|
Page({
|
|
data: {
|
|
stories: [] as any[],
|
|
current: 0,
|
|
progress: 0,
|
|
currentStory: {} as any,
|
|
},
|
|
|
|
_timer: null as any,
|
|
|
|
onLoad(query: { id?: string }) {
|
|
this.loadStory(query.id || '')
|
|
},
|
|
|
|
onUnload() {
|
|
if (this._timer) clearInterval(this._timer)
|
|
},
|
|
|
|
async loadStory(id: string) {
|
|
try {
|
|
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] || {} })
|
|
if (stories.length) this.startProgress()
|
|
else wx.navigateBack()
|
|
} catch {
|
|
wx.navigateBack()
|
|
}
|
|
},
|
|
|
|
startProgress() {
|
|
if (this._timer) clearInterval(this._timer)
|
|
const interval = 100
|
|
let elapsed = 0
|
|
this._timer = setInterval(() => {
|
|
elapsed += interval
|
|
const pct = Math.min(100, (elapsed / DURATION) * 100)
|
|
this.setData({ progress: pct })
|
|
if (elapsed >= DURATION) this.onNext()
|
|
}, interval)
|
|
},
|
|
|
|
onNext() {
|
|
const { current, stories } = this.data
|
|
if (current + 1 >= stories.length) {
|
|
wx.navigateBack()
|
|
return
|
|
}
|
|
const next = current + 1
|
|
this.setData({ current: next, progress: 0, currentStory: stories[next] })
|
|
this.startProgress()
|
|
},
|
|
|
|
onClose() { wx.navigateBack() },
|
|
})
|