import { api } from '../../utils/api' import { getAvatarGradient, formatTime } from '../../utils/format' import { AppGlobalData } from '../../types/index' const app = getApp<{ globalData: AppGlobalData }>() Page({ data: { statusBarHeight: 0, navbarHeight: 44, navbarPaddingRight: 0, list: [] as any[], }, onLoad() { const { statusBarHeight, navbarHeight, navbarPaddingRight } = app.globalData.navBarInfo this.setData({ statusBarHeight, navbarHeight, navbarPaddingRight }) this.loadNotifications() }, async loadNotifications() { try { const list = await api.getNotifications() const enriched = (list || []).map((n: any) => ({ ...n, gradient: getAvatarGradient(n.fromId || ''), timeText: formatTime(n.createdAt), })) this.setData({ list: enriched }) } 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() { api.markAllRead().catch(() => {}) const list = this.data.list.map((n: any) => ({ ...n, isRead: true })) this.setData({ list }) }, onBack() { wx.navigateBack() }, })