This commit is contained in:
2026-09-13 02:28:46 +08:00
parent df5492a48a
commit 42f9530a59
27 changed files with 979 additions and 149 deletions
+14 -3
View File
@@ -5,6 +5,10 @@ import { STORAGE_KEYS } from '../../utils/config'
import { formatRelativeTime } from '../../utils/format'
import { normalizePaged, mergePaged, hasMorePaged } from '../../utils/paged'
import { getTabBarInstance } from '../../utils/tabbar'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'notification'
const FILTERS = [
{ name: '全部', value: 0 },
@@ -28,6 +32,7 @@ Page({
onShow() {
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
logger.debug(LOG, '未登录,跳转登录页')
redirectToLogin()
return
}
@@ -42,6 +47,7 @@ Page({
silentAuth: true,
})
.then((res) => {
logger.debug(LOG, '未读数加载成功, unread=', res.unread_count)
const unread = res.unread_count || 0
wx.setStorageSync(STORAGE_KEYS.UNREAD, unread)
// 本页不是 tab 页,getTabBar() 恒为 undefined,需从页面栈里取 tab 页的 tabBar
@@ -49,7 +55,7 @@ Page({
// 直接更新红点,避免 tabBar 内部再发一次请求
if (tabBar && tabBar.setUnread) tabBar.setUnread(unread)
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '未读数加载失败(静默降级), code=', e && e.code))
},
refresh() {
@@ -76,6 +82,7 @@ Page({
.then((res) => {
if ((this as any).reqSeq !== seq) return
const { list: raw, total } = normalizePaged<NotificationItem>(res)
logger.debug(LOG, '通知加载成功, 筛选=', filter, 'page=', page, '条数=', raw && raw.length)
const list = raw.map((it) => ({ ...it, _time: formatRelativeTime(it.created_at) }))
const merged = mergePaged(this.data.list, list, page === 1)
this.setData({
@@ -86,8 +93,9 @@ Page({
page,
})
})
.catch(() => {
.catch((e: any) => {
if ((this as any).reqSeq !== seq) return
logger.warn(LOG, '通知加载失败, page=', page, 'code=', e && e.code)
this.setData({ loading: false, loadingMore: false })
})
},
@@ -101,6 +109,9 @@ Page({
onItemTap(e: WechatMiniprogram.TouchEvent) {
const uuid = e.currentTarget.dataset.uuid as string
wx.navigateTo({ url: `/pages/notification-detail/notification-detail?uuid=${uuid}` })
wx.navigateTo({
url: `/pages/notification-detail/notification-detail?uuid=${uuid}`,
fail: (e) => logger.warn(LOG, 'navigateTo 通知详情失败, err=', e && e.errMsg),
})
},
})