import { request } from '../../utils/request' import { NotificationItem } from '../../types/models' import { formatDateTime } from '../../utils/format' import { syncTabBarUnread } from '../../utils/tabbar' import { navPageScroll } from '../../utils/nav' import { logger } from '../../utils/logger' // 日志模块名 const LOG = 'notification-detail' Page({ data: { uuid: '', item: {} as NotificationItem, time: '', // 滚动收缩:由 utils/nav.ts 的共享 handler 驱动 navScrolled: false, }, // 页面级滚动 → 导航收缩为玻璃小标题 onPageScroll: navPageScroll, onLoad(query: Record) { const uuid = query.uuid || '' logger.debug(LOG, 'onLoad, uuid=', uuid) this.setData({ uuid }) if (!uuid) { logger.warn(LOG, 'onLoad 缺少 uuid 参数') return } this.fetchDetail() request({ url: `/notification/${uuid}/read`, method: 'POST', showError: false }) .then(() => { logger.debug(LOG, '标记已读成功') // 标记已读后同步红点:本页不是 tab 页,红点不会自动刷新 syncTabBarUnread(true) }) .catch((e: any) => logger.warn(LOG, '标记已读失败, code=', e && e.code)) }, fetchDetail() { request({ url: `/notification/${this.data.uuid}` }) .then((item) => { logger.debug(LOG, '详情加载成功') this.setData({ item, time: formatDateTime(item.created_at) }) }) .catch((e: any) => logger.warn(LOG, '详情加载失败, code=', e && e.code)) }, })