fix: 权益页每次进入向服务端复查最新状态,避免缓存导致权益变化不可见

用户权益包/中奖状态会变化,原逻辑仅在无认证缓存时才查询后端,
导致本地缓存过期时用户始终看到旧的「未中奖」。改为进入权益页一律
凭手机号复查服务端资格并覆盖缓存,认证回调场景仍交由 checkAuthResult 处理。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jacobxu666
2026-08-28 10:24:58 +08:00
co-authored by Claude Fable 5
parent 291be28219
commit cda36ddc1e
+19 -12
View File
@@ -212,18 +212,24 @@
this.lat = loc.lat this.lat = loc.lat
} }
this.checkAuthResult() this.checkAuthResult()
// xuchao: 本地无认证缓存时自动查询后端恢复已认证状态 // xuchao: 权益状态会变化,缓存只作首屏展示,进入页面一律向服务端复查最新状态
this.autoRecoverStatus() this.refreshStatus()
if (this.status === 'info') { if (this.status === 'info') {
this.loadRightsList() this.loadRightsList()
} }
}, },
methods: { methods: {
// xuchao: 已登录但本地无认证缓存时,仅传手机号查询资格以恢复状态(不带证件号,避免触发被动认证) // xuchao: 缓存的权益状态可能过期(中奖/权益包会变化),每次进页面仅凭手机号向服务端
autoRecoverStatus() { // 复查最新状态并覆盖缓存(不带证件号,避免触发被动认证)
if (this.status !== 'auth') return refreshStatus() {
// xuchao: 人脸认证回调场景由 checkAuthResult 负责查询,跳过避免重复请求
try {
if (new URL(window.location.href).searchParams.get('response')) return
} catch (e) {
return
}
// xuchao: 用户主动发起过认证流程时,取消后应停留在认证页,不自动恢复 // xuchao: 用户主动发起过认证流程时,取消后应停留在认证页,不自动恢复
if (uni.getStorageSync('authFlowStarted')) return if (this.status === 'auth' && uni.getStorageSync('authFlowStarted')) return
const phone = uni.getStorageSync('phone') const phone = uni.getStorageSync('phone')
if (!phone) return if (!phone) return
this.$u.api.getEligibility({ this.$u.api.getEligibility({
@@ -234,14 +240,15 @@
uni.setStorageSync('hasWin', res.data.hasWin) uni.setStorageSync('hasWin', res.data.hasWin)
uni.setStorageSync('cardNumber', res.data.cardNumber) uni.setStorageSync('cardNumber', res.data.cardNumber)
uni.setStorageSync('expiresTime', res.data.expiresTime) uni.setStorageSync('expiresTime', res.data.expiresTime)
// xuchao: 自动恢复成功,清除流程标记 // xuchao: 服务端已认证则清除取消标记,后续按真实状态展示
uni.removeStorageSync('authFlowStarted') if (res.data.isAuth) uni.removeStorageSync('authFlowStarted')
if (res.data.isAuth) { const newStatus = res.data.isAuth ? (res.data.hasWin ? 'info' : 'noWin') : 'auth'
this.status = res.data.hasWin ? 'info' : 'noWin' const prevStatus = this.status
if (this.status === 'info') { this.status = newStatus
// xuchao: 状态刷新为权益页时补拉权益列表,避免与首屏加载重复
if (newStatus === 'info' && prevStatus !== 'info') {
this.loadRightsList() this.loadRightsList()
} }
}
}) })
}, },
// xuchao: 认证取消/未通过:清理旧认证缓存并标记流程已发起,取消后应停留认证页 // xuchao: 认证取消/未通过:清理旧认证缓存并标记流程已发起,取消后应停留认证页