bugfix:ui
This commit is contained in:
@@ -3,6 +3,7 @@ import * as auth from '../../utils/auth'
|
||||
import { HoroscopeData } from '../../types/models'
|
||||
import { setTabBarSelected } from '../../utils/tabbar'
|
||||
import { logger } from '../../utils/logger'
|
||||
import { STORAGE_KEYS } from '../../utils/config'
|
||||
|
||||
// 日志模块名
|
||||
const LOG = 'horoscope'
|
||||
@@ -117,9 +118,15 @@ Page({
|
||||
},
|
||||
|
||||
onGoProfile() {
|
||||
// switchTab 不支持 query 传参,用 storage 标记让「我的」页 onShow 自动弹出编辑弹窗
|
||||
wx.setStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT, 1)
|
||||
wx.switchTab({
|
||||
url: '/pages/profile/profile',
|
||||
fail: (e) => logger.warn(LOG, 'switchTab 个人资料失败, err=', e && e.errMsg),
|
||||
fail: (e) => {
|
||||
logger.warn(LOG, 'switchTab 个人资料失败, err=', e && e.errMsg)
|
||||
// 跳转失败时清除标记,避免下次进入「我的」页意外弹窗
|
||||
wx.removeStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT)
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -187,9 +187,15 @@ Page({
|
||||
cancelText: '稍后再说',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// switchTab 不支持 query 传参,用 storage 标记让「我的」页 onShow 自动弹出编辑弹窗
|
||||
wx.setStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT, 1)
|
||||
wx.switchTab({
|
||||
url: '/pages/profile/profile',
|
||||
fail: (e) => logger.warn(LOG, 'switchTab 个人资料失败, err=', e && e.errMsg),
|
||||
fail: (e) => {
|
||||
logger.warn(LOG, 'switchTab 个人资料失败, err=', e && e.errMsg)
|
||||
// 跳转失败时清除标记,避免下次进入「我的」页意外弹窗
|
||||
wx.removeStorageSync(STORAGE_KEYS.OPEN_PROFILE_EDIT)
|
||||
},
|
||||
})
|
||||
} else {
|
||||
this.goAfterLogin()
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<view class="menu-row hairline" bindtap="onTapNotification">
|
||||
<view class="icon icon-bell menu-icon"></view>
|
||||
<text class="menu-label">通知</text>
|
||||
<view wx:if="{{unread > 0}}" class="menu-badge">{{unread > 99 ? '99+' : unread}}</view>
|
||||
<view class="icon icon-chevron-right menu-arrow"></view>
|
||||
</view>
|
||||
<view class="menu-row hairline" bindtap="onTapCollect">
|
||||
|
||||
@@ -120,6 +120,21 @@
|
||||
color: #8E8E93;
|
||||
}
|
||||
|
||||
.menu-badge {
|
||||
min-width: 32rpx;
|
||||
height: 32rpx;
|
||||
padding: 0 10rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #FF3B30;
|
||||
color: #fff;
|
||||
font-size: 20rpx;
|
||||
line-height: 32rpx;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
flex-shrink: 0;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
|
||||
.menu-arrow {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
|
||||
@@ -14,6 +14,7 @@ export const STORAGE_KEYS = {
|
||||
USER_INFO: 'zt_closet_user_info',
|
||||
UNREAD: 'zt_closet_unread',
|
||||
OPEN_COLLECT: 'zt_open_collect',
|
||||
OPEN_PROFILE_EDIT: 'zt_open_profile_edit',
|
||||
}
|
||||
|
||||
// 衣物图片处理状态
|
||||
|
||||
@@ -17,6 +17,12 @@ export function syncTabBarUnread(force = true): void {
|
||||
if (tabBar && typeof tabBar.syncUnread === 'function') tabBar.syncUnread(force)
|
||||
}
|
||||
|
||||
// 用已知数量直接更新红点:不发请求,供页面拉到最新未读数后同步 tabBar
|
||||
export function setTabBarUnread(count: number): void {
|
||||
const tabBar = getTabBarInstance()
|
||||
if (tabBar && typeof tabBar.setUnread === 'function') tabBar.setUnread(count)
|
||||
}
|
||||
|
||||
// 更新选中态:走 tabBar 的 setSelected(内部保证首帧安全),
|
||||
// 老版本实例没有该方法时降级为 setData
|
||||
export function setTabBarSelected(index: number): void {
|
||||
|
||||
Reference in New Issue
Block a user