bugfix:前端接口与后端不一致

This commit is contained in:
2026-09-16 00:27:34 +08:00
parent 592fa9be64
commit a9f2659c42
4 changed files with 50 additions and 9 deletions
+30 -6
View File
@@ -1,7 +1,7 @@
import { request, uploadFile, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { UserInfo, QuotaItem } from '../../types/models'
import { QuotaType, STORAGE_KEYS } from '../../utils/config'
import { QuotaType, QUOTA_NAMES, VIP_TYPE_NAMES, STORAGE_KEYS } from '../../utils/config'
import { formatDate } from '../../utils/format'
import { setTabBarSelected, setTabBarUnread, setTabBarHidden } from '../../utils/tabbar'
import { navScroll } from '../../utils/nav'
@@ -30,6 +30,8 @@ function getZodiac(birthDay: number): string {
Page({
data: {
userInfo: {} as UserInfo,
// 会员标签(vip_type 2/3/4 → 月度/年度/体验会员;非会员为空不展示)
vipLabel: '',
uploadRemain: 0,
zodiac: '',
unread: 0,
@@ -116,7 +118,11 @@ Page({
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.setData({
userInfo: cached,
zodiac: getZodiac(cached.birth_day),
vipLabel: VIP_TYPE_NAMES[cached.vip_type] || '',
})
}
}
this.onEdit()
@@ -130,9 +136,14 @@ Page({
fetchUser() {
request<UserInfo>({ url: '/user/info', showError: false })
.then((user) => {
logger.debug(LOG, '用户信息加载成功')
logger.debug(LOG, '用户信息加载成功, vipType=', user.vip_type)
wx.setStorageSync(STORAGE_KEYS.USER_INFO, user)
this.setData({ userInfo: user, zodiac: getZodiac(user.birth_day) })
// 会员标签按 vip_type 判定:2 月度 / 3 年度 / 4 体验(新用户默认赠送),非会员不展示
this.setData({
userInfo: user,
zodiac: getZodiac(user.birth_day),
vipLabel: VIP_TYPE_NAMES[user.vip_type] || '',
})
})
.catch((e: any) => logger.warn(LOG, '用户信息加载失败, code=', e && e.code))
},
@@ -140,9 +151,22 @@ Page({
fetchQuota() {
request<{ quotas: QuotaItem[] }>({ url: '/quota/info', showError: false, silentAuth: true })
.then((res) => {
const upload = res.quotas.find((q) => q.quota_type === QuotaType.UPLOAD)
const quotas = res && Array.isArray(res.quotas) ? res.quotas : []
const upload = quotas.find((q) => q.quota_type === QuotaType.UPLOAD)
if (upload) this.setData({ uploadRemain: upload.remain })
logger.debug(LOG, '额度加载成功, 上传剩余=', upload ? upload.remain : 0)
// 四栏额度条按固定顺序取数,缺失类型补 0,保证栏位不塌陷
const order = [QuotaType.UPLOAD, QuotaType.AI, QuotaType.OUTFIT_SHARE, QuotaType.CLOSET_SHARE]
const quotaStats = order.map((type) => {
const hit = quotas.find((q) => q.quota_type === type)
return {
key: type,
label: QUOTA_NAMES[type] || '额度',
remain: hit ? hit.remain : 0,
total: hit ? hit.total : 0,
}
})
this.setData({ quotaStats })
logger.debug(LOG, '额度加载成功, 上传剩余=', upload ? upload.remain : 0, '栏位=', quotaStats.length)
})
.catch((e: any) => logger.warn(LOG, '额度加载失败(静默降级), code=', e && e.code))
},
+1 -1
View File
@@ -18,7 +18,7 @@
<view class="pf-sub">
<text wx:if="{{userInfo.sex === 1}}" class="pill">男</text>
<text wx:elif="{{userInfo.sex === 2}}" class="pill">女</text>
<text wx:if="{{userInfo.vip_type !== 1}}" class="pill pill--ink">月度会员</text>
<text wx:if="{{vipLabel}}" class="pill pill--ink">{{vipLabel}}</text>
<text wx:if="{{zodiac}}" class="pill pill--line">{{zodiac}}</text>
<text wx:else class="pill pill--line" bindtap="onEdit">设置生日</text>
</view>