33 lines
925 B
TypeScript
33 lines
925 B
TypeScript
import { request } from '../../utils/request'
|
|
import { NotificationItem } from '../../types/models'
|
|
import { formatDateTime } from '../../utils/format'
|
|
import { syncTabBarUnread } from '../../utils/tabbar'
|
|
|
|
Page({
|
|
data: {
|
|
uuid: '',
|
|
item: {} as NotificationItem,
|
|
time: '',
|
|
},
|
|
|
|
onLoad(query: Record<string, string>) {
|
|
const uuid = query.uuid || ''
|
|
this.setData({ uuid })
|
|
if (uuid) {
|
|
this.fetchDetail()
|
|
request({ url: `/notification/${uuid}/read`, method: 'POST', showError: false })
|
|
.then(() => {
|
|
// 标记已读后同步红点:本页不是 tab 页,红点不会自动刷新
|
|
syncTabBarUnread(true)
|
|
})
|
|
.catch(() => {})
|
|
}
|
|
},
|
|
|
|
fetchDetail() {
|
|
request<NotificationItem>({ url: `/notification/${this.data.uuid}` })
|
|
.then((item) => this.setData({ item, time: formatDateTime(item.created_at) }))
|
|
.catch(() => {})
|
|
},
|
|
})
|