From 6b1037893e5ef166995fa366b4dbfb23251a6b82 Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Tue, 15 Sep 2026 12:42:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=AA=E6=8E=A5=E5=8F=97=E9=9D=9E?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=87=AD=E8=AF=81=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E8=84=8F=20accessToken=20=E6=89=93=E6=8C=82=E9=89=B4?= =?UTF-8?q?=E6=9D=83=EF=BC=9B=E4=BF=AE=E6=AD=A3=E8=AE=A4=E8=AF=81=E9=A1=B5?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 7 +++++-- pages/index/login.vue | 7 ++++--- pages/rights/rights.vue | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 3796c5b..f0dd8c8 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -93,8 +93,11 @@ this.finishTokenLogin() if (res.errcode === 0 && res.data && res.data.mobile) { uni.setStorageSync('phone', res.data.mobile) - // xuchao: 后端已为云闪付入口签发会员会话,存下 accessToken,后续接口才认得这个用户 - if (res.data.accessToken) uni.setStorageSync('token', res.data.accessToken) + // xuchao: 后端已为云闪付入口签发会员会话,存下 accessToken,后续接口才认得这个用户。 + // 只认"非空字符串":后端字段缺失/为 null 时会被序列化成 {},直接存进缓存 + // 就会变成 Bearer [object Object],把所有鉴权接口全打挂 + const issued = typeof res.data.accessToken === 'string' ? res.data.accessToken : '' + if (issued) uni.setStorageSync('token', issued) this.$u.api.getEligibility({ phone: res.data.mobile, identityNo: res.data.idNo || '', name: res.data.name || '' }).then(eRes => { if (eRes.errcode === 0) { uni.setStorageSync('isAuth', eRes.data.isAuth) diff --git a/pages/index/login.vue b/pages/index/login.vue index 526c796..7c8cacf 100644 --- a/pages/index/login.vue +++ b/pages/index/login.vue @@ -125,10 +125,11 @@ export default { // xuchao: password 为后端要求的固定旁路口令,集中取自 config.loginFixedPassword this.$u.api.checkerLogin({ password: config.loginFixedPassword, mobile: this.phone, verifyCode: this.code }).then(res => { if (this.isBizOk(res)) { - // xuchao: 后端当前只回 userId/userName,并未下发 accessToken(字段名也是 accessToken)。 - // 取到才存、取不到存空串,避免把 undefined 写进 storage 变成 "Bearer undefined" + // xuchao: 只认"非空字符串"凭证。后端若把 null 序列化成 {}(实测 tokenDecode 就是这个形状), + // 用 || 兜底会把对象存进缓存,之后每个请求都变成 Bearer [object Object] const payload = (res.data && res.data.data) || {} - uni.setStorageSync('token', payload.accessToken || payload.token || '') + const issued = [payload.accessToken, payload.token].find(v => typeof v === 'string' && v.length > 0) + uni.setStorageSync('token', issued || '') uni.setStorageSync('phone', this.phone) this.$u.api.getEligibility({ phone: this.phone, identityNo: '', name: '' }).then(eRes => { if (eRes.errcode === 0) { diff --git a/pages/rights/rights.vue b/pages/rights/rights.vue index c9921e2..4e960fa 100644 --- a/pages/rights/rights.vue +++ b/pages/rights/rights.vue @@ -46,7 +46,7 @@ 1. 请输入真实的身份信息用来进行活动权益资格认证 2. 认证通过后系统会显示出您的所获得的权益信息 - 3. 手机号码为您登录的手机,无法修改。若号码对,请更换登录手机。 + 3. 手机号码为您登录的手机号,无法修改。若号码不对,请更换手机号重新登录。