bugfix:ui
This commit is contained in:
@@ -3,7 +3,7 @@ import * as auth from '../../utils/auth'
|
||||
import { UserInfo, QuotaItem } from '../../types/models'
|
||||
import { QuotaType, STORAGE_KEYS } from '../../utils/config'
|
||||
import { formatDate } from '../../utils/format'
|
||||
import { setTabBarSelected } from '../../utils/tabbar'
|
||||
import { setTabBarSelected, setTabBarUnread } from '../../utils/tabbar'
|
||||
import { logger } from '../../utils/logger'
|
||||
|
||||
// 日志模块名
|
||||
@@ -31,6 +31,7 @@ Page({
|
||||
userInfo: {} as UserInfo,
|
||||
uploadRemain: 0,
|
||||
zodiac: '',
|
||||
unread: 0,
|
||||
editVisible: false,
|
||||
avatarUploading: false,
|
||||
avatarChanged: false,
|
||||
@@ -64,8 +65,46 @@ Page({
|
||||
redirectToLogin()
|
||||
return
|
||||
}
|
||||
this.consumeOpenEditMark()
|
||||
this.fetchUser()
|
||||
this.fetchQuota()
|
||||
this.fetchUnread()
|
||||
},
|
||||
|
||||
// 拉取未读数:与 tabBar 红点同源(/notification/unread),保证两处数量一致
|
||||
fetchUnread() {
|
||||
request<{ unread_count: number }>({ url: '/notification/unread', showError: false, silentAuth: true })
|
||||
.then((res) => {
|
||||
const unread = res.unread_count || 0
|
||||
logger.debug(LOG, '未读数加载成功, unread=', unread)
|
||||
// 写回缓存并同步 tabBar 红点(setUnread 内部只更新,不再发请求)
|
||||
wx.setStorageSync(STORAGE_KEYS.UNREAD, unread)
|
||||
this.setData({ unread })
|
||||
setTabBarUnread(unread)
|
||||
})
|
||||
.catch((e: any) => logger.warn(LOG, '未读数加载失败(静默降级), code=', e && e.code))
|
||||
},
|
||||
|
||||
// 消费「引导完善资料」标记:命中则自动弹出编辑弹窗(标记一次性,先清除再打开)
|
||||
consumeOpenEditMark() {
|
||||
if (!wx.getStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT)) return
|
||||
wx.removeStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT)
|
||||
logger.debug(LOG, '命中打开编辑弹窗标记,自动弹出资料编辑')
|
||||
// 首帧渲染未结束就 setData 会触发「Expected updated data but get first rendering data」,
|
||||
// 导致 webview 渲染失败(视觉上仍停留在上一页),故延迟到下一帧再打开
|
||||
wx.nextTick(() => this.openEditFromGuide())
|
||||
},
|
||||
|
||||
// 引导入口进入时自动打开编辑弹窗:fetchUser 未返回时用本地缓存兜底,避免表单为空
|
||||
openEditFromGuide() {
|
||||
if (!Object.keys(this.data.userInfo || {}).length) {
|
||||
const cached = wx.getStorageSync(STORAGE_KEYS.USER_INFO)
|
||||
if (cached && Object.keys(cached).length) {
|
||||
logger.debug(LOG, '用户信息未就绪,使用本地缓存预填编辑表单')
|
||||
this.setData({ userInfo: cached, zodiac: getZodiac(cached.birth_day) })
|
||||
}
|
||||
}
|
||||
this.onEdit()
|
||||
},
|
||||
|
||||
syncTabBar() {
|
||||
|
||||
Reference in New Issue
Block a user