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 { request, uploadFile, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth' import * as auth from '../../utils/auth'
import { UserInfo, QuotaItem } from '../../types/models' 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 { formatDate } from '../../utils/format'
import { setTabBarSelected, setTabBarUnread, setTabBarHidden } from '../../utils/tabbar' import { setTabBarSelected, setTabBarUnread, setTabBarHidden } from '../../utils/tabbar'
import { navScroll } from '../../utils/nav' import { navScroll } from '../../utils/nav'
@@ -30,6 +30,8 @@ function getZodiac(birthDay: number): string {
Page({ Page({
data: { data: {
userInfo: {} as UserInfo, userInfo: {} as UserInfo,
// 会员标签(vip_type 2/3/4 → 月度/年度/体验会员;非会员为空不展示)
vipLabel: '',
uploadRemain: 0, uploadRemain: 0,
zodiac: '', zodiac: '',
unread: 0, unread: 0,
@@ -116,7 +118,11 @@ Page({
const cached = wx.getStorageSync(STORAGE_KEYS.USER_INFO) const cached = wx.getStorageSync(STORAGE_KEYS.USER_INFO)
if (cached && Object.keys(cached).length) { if (cached && Object.keys(cached).length) {
logger.debug(LOG, '用户信息未就绪,使用本地缓存预填编辑表单') 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() this.onEdit()
@@ -130,9 +136,14 @@ Page({
fetchUser() { fetchUser() {
request<UserInfo>({ url: '/user/info', showError: false }) request<UserInfo>({ url: '/user/info', showError: false })
.then((user) => { .then((user) => {
logger.debug(LOG, '用户信息加载成功') logger.debug(LOG, '用户信息加载成功, vipType=', user.vip_type)
wx.setStorageSync(STORAGE_KEYS.USER_INFO, user) 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)) .catch((e: any) => logger.warn(LOG, '用户信息加载失败, code=', e && e.code))
}, },
@@ -140,9 +151,22 @@ Page({
fetchQuota() { fetchQuota() {
request<{ quotas: QuotaItem[] }>({ url: '/quota/info', showError: false, silentAuth: true }) request<{ quotas: QuotaItem[] }>({ url: '/quota/info', showError: false, silentAuth: true })
.then((res) => { .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 }) 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)) .catch((e: any) => logger.warn(LOG, '额度加载失败(静默降级), code=', e && e.code))
}, },
+1 -1
View File
@@ -18,7 +18,7 @@
<view class="pf-sub"> <view class="pf-sub">
<text wx:if="{{userInfo.sex === 1}}" class="pill">男</text> <text wx:if="{{userInfo.sex === 1}}" class="pill">男</text>
<text wx:elif="{{userInfo.sex === 2}}" 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:if="{{zodiac}}" class="pill pill--line">{{zodiac}}</text>
<text wx:else class="pill pill--line" bindtap="onEdit">设置生日</text> <text wx:else class="pill pill--line" bindtap="onEdit">设置生日</text>
</view> </view>
+4 -2
View File
@@ -117,10 +117,12 @@ export interface QuotaFlowItem {
quota_flow_uuid: string quota_flow_uuid: string
quota_type: number quota_type: number
change_target: number change_target: number
change_type: number // 1 购买 2 活动 3 上传消耗 4 删除回退 5 人工 6 退款回收 // 1 购买获赠 2 活动赠送 3 消耗 4 删除回退 5 人工调整 6 退款回收 7 到期失效(固定有效期凭证过期)
change_num: number // 正增负减 change_type: number
change_num: number // 正增负减(到期失效为负)
new_value: number new_value: number
reason: string reason: string
// 购买/退款类为真实订单号;赠送/消耗/回退/到期类由后端填充流水 UUID 或凭证 ref_id(幂等用),不代表订单
order_no: string order_no: string
created_at: number created_at: number
} }
+15
View File
@@ -45,6 +45,21 @@ export enum QuotaType {
CLOSET_SHARE = 4, // 衣柜分享 CLOSET_SHARE = 4, // 衣柜分享
} }
// 会员类型(与后端 UserInfo.vip_type 对齐)
export enum VipType {
NONE = 1, // 非会员
MONTHLY = 2, // 月度会员
YEARLY = 3, // 年度会员
TRIAL = 4, // 体验会员(新用户注册赠送,固定有效期,不随续费延长)
}
// 会员标签映射:非会员不在资料区展示标签,故意不提供 NONE 的文案
export const VIP_TYPE_NAMES: Record<number, string> = {
[VipType.MONTHLY]: '月度会员',
[VipType.YEARLY]: '年度会员',
[VipType.TRIAL]: '体验会员',
}
// 通知类型 // 通知类型
export enum MsgType { export enum MsgType {
LIKE = 1, // 点赞通知 LIKE = 1, // 点赞通知