44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { request } from '../../utils/request'
|
|
import { NotificationItem } from '../../types/models'
|
|
import { formatDateTime } from '../../utils/format'
|
|
import { syncTabBarUnread } from '../../utils/tabbar'
|
|
import { logger } from '../../utils/logger'
|
|
|
|
// 日志模块名
|
|
const LOG = 'notification-detail'
|
|
|
|
Page({
|
|
data: {
|
|
uuid: '',
|
|
item: {} as NotificationItem,
|
|
time: '',
|
|
},
|
|
|
|
onLoad(query: Record<string, string>) {
|
|
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<NotificationItem>({ 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))
|
|
},
|
|
})
|