37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { getAvatarGradient, formatTime } from '../../utils/format'
|
|
|
|
Page({
|
|
data: { statusBarHeight: 0, list: [] as any[] },
|
|
|
|
onLoad() {
|
|
const info = wx.getSystemInfoSync()
|
|
this.setData({ statusBarHeight: info.statusBarHeight })
|
|
this.loadNotifications()
|
|
},
|
|
|
|
async loadNotifications() {
|
|
try {
|
|
const res = await wx.cloud.callFunction({ name: 'getNotifications', data: {} }) as any
|
|
const list = (res.result?.data || []).map((n: any) => ({
|
|
...n,
|
|
gradient: getAvatarGradient(n.fromId || ''),
|
|
timeText: formatTime(n.createdAt),
|
|
}))
|
|
this.setData({ list })
|
|
} catch {}
|
|
},
|
|
|
|
onItemTap(e: WechatMiniprogram.CustomEvent) {
|
|
const item = e.currentTarget.dataset.item as any
|
|
if (item?.postId) wx.navigateTo({ url: `/pages/post-detail/post-detail?id=${item.postId}` })
|
|
},
|
|
|
|
onReadAll() {
|
|
wx.cloud.callFunction({ name: 'markAllRead', data: {} }).catch(() => {})
|
|
const list = this.data.list.map((n: any) => ({ ...n, isRead: true }))
|
|
this.setData({ list })
|
|
},
|
|
|
|
onBack() { wx.navigateBack() },
|
|
})
|