feat(协议): 新增用户协议与隐私政策页面及入口
This commit is contained in:
@@ -42,31 +42,42 @@ Page({
|
||||
redirectToLogin()
|
||||
return
|
||||
}
|
||||
this.refresh()
|
||||
this.fetchUnread()
|
||||
// 先拉列表、再全部标记已读:本次进入仍保留未读标记,让用户看清哪些是新消息;
|
||||
// 服务端状态与红点在列表渲染后清零,下次进入即为已读样式。
|
||||
this.refresh().then(() => this.markAllRead())
|
||||
},
|
||||
|
||||
fetchUnread() {
|
||||
request<{ unread_count: number }>({
|
||||
url: '/notification/unread',
|
||||
// 全部标记已读:接口顺带返回最新未读数,直接用它刷新红点,省掉一次 /notification/unread
|
||||
markAllRead(): Promise<void> {
|
||||
return request<{ unread_count: number }>({
|
||||
url: '/notification/read-all',
|
||||
method: 'POST',
|
||||
showError: false,
|
||||
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
|
||||
const tabBar = getTabBarInstance()
|
||||
// 直接更新红点,避免 tabBar 内部再发一次请求
|
||||
if (tabBar && tabBar.setUnread) tabBar.setUnread(unread)
|
||||
logger.debug(LOG, '全部标记已读成功, unread=', unread)
|
||||
this.syncUnread(unread)
|
||||
})
|
||||
.catch((e: any) => {
|
||||
// 失败不阻塞列表展示,红点维持原状,等下次进入再补
|
||||
logger.warn(LOG, '全部标记已读失败(静默降级), code=', e && e.code)
|
||||
})
|
||||
.catch((e: any) => logger.warn(LOG, '未读数加载失败(静默降级), code=', e && e.code))
|
||||
},
|
||||
|
||||
refresh() {
|
||||
// 同步未读红点:本页不是 tab 页,getTabBar() 恒为 undefined,需从页面栈里取 tab 页的 tabBar
|
||||
syncUnread(unread: number) {
|
||||
wx.setStorageSync(STORAGE_KEYS.UNREAD, unread)
|
||||
const tabBar = getTabBarInstance()
|
||||
// 直接更新红点,避免 tabBar 内部再发一次请求
|
||||
if (tabBar && tabBar.setUnread) tabBar.setUnread(unread)
|
||||
},
|
||||
|
||||
// 返回列表请求的 Promise:onShow 需要等首页数据渲染完再标记全部已读
|
||||
refresh(): Promise<void> {
|
||||
this.setData({ page: 1, hasMore: true, loading: this.data.list.length === 0 })
|
||||
this.fetchList(1)
|
||||
return this.fetchList(1)
|
||||
},
|
||||
|
||||
onReachBottom() {
|
||||
@@ -74,7 +85,7 @@ Page({
|
||||
this.fetchList(this.data.page + 1)
|
||||
},
|
||||
|
||||
fetchList(page: number) {
|
||||
fetchList(page: number): Promise<void> {
|
||||
const params: Record<string, any> = { page, page_size: this.data.pageSize }
|
||||
const filter = this.data.activeFilter
|
||||
if (filter > 0) params.msg_type = filter
|
||||
@@ -84,7 +95,7 @@ Page({
|
||||
;(this as any).reqSeq = seq
|
||||
if (page > 1) this.setData({ loadingMore: true })
|
||||
|
||||
request<PagedResult<NotificationItem>>({ url: '/notification', data: params })
|
||||
return request<PagedResult<NotificationItem>>({ url: '/notification', data: params })
|
||||
.then((res) => {
|
||||
if ((this as any).reqSeq !== seq) return
|
||||
const { list: raw, total } = normalizePaged<NotificationItem>(res)
|
||||
|
||||
Reference in New Issue
Block a user