fix: 退出登录与云闪付入口统一清理账号缓存,避免串号与脏数据

1. 新增 common/account.js,集中维护账号级本地缓存 key(token/phone/isAuth/hasWin/cardNumber/expiresTime/rightsCount/totalValueFen/authFlowStarted/authName/authIdNo),定位 lng/lat 属设备信息不清

2. 我的页退出登录原来只清 token/phone,权益缓存残留会被下一个账号当成自己的数据展示(权益页首屏读这些 key 兜底,且无手机号时 refreshStatus 不会刷新)

3. 首页云闪付入口是免密换人,进入前先清上一个账号的会话与权益缓存,否则请求仍带旧 accessToken,后端会话优先会把上一个账号的数据返回给新用户
This commit is contained in:
jacobxu666
2026-09-15 10:17:27 +08:00
parent f69bd630a4
commit a53b228f0b
3 changed files with 24 additions and 2 deletions
+15
View File
@@ -0,0 +1,15 @@
// xuchao: 账号级本地缓存集中管理。权益页首屏会读这些缓存做兜底展示,
// 换账号/退出时漏清就会把上一个账号的中奖状态、卡号、到期时间当成当前账号的数据展示。
const ACCOUNT_KEYS = ['token', 'phone', 'isAuth', 'hasWin', 'cardNumber', 'expiresTime',
'rightsCount', 'totalValueFen', 'authFlowStarted', 'authName', 'authIdNo']
export default {
// 清空当前账号的本地会话与权益缓存(定位 lng/lat 属于设备信息,不在此列)
clearAccountCache() {
ACCOUNT_KEYS.forEach(key => uni.removeStorageSync(key))
},
// 账号标识(手机号)
setAccountPhone(phone) {
uni.setStorageSync('phone', phone)
}
}
+5
View File
@@ -34,6 +34,8 @@
</template> </template>
<script> <script>
import account from '@/common/account.js'
export default { export default {
data() { data() {
return { return {
@@ -70,6 +72,9 @@
handleTokenLogin(token) { handleTokenLogin(token) {
this.$u.api.tokenDecode({ token }).then(res => { this.$u.api.tokenDecode({ token }).then(res => {
if (res.errcode === 0 && res.data && res.data.mobile) { if (res.errcode === 0 && res.data && res.data.mobile) {
// xuchao: 云闪付入口是“免密换人”,先丢弃本机上一个账号的会话与权益缓存,
// 否则请求仍带旧 accessToken,后端“会话优先”会把上一个账号的数据返回给这位用户
account.clearAccountCache()
uni.setStorageSync('phone', res.data.mobile) uni.setStorageSync('phone', res.data.mobile)
this.$u.api.getEligibility({ phone: res.data.mobile, identityNo: res.data.idNo || '', name: res.data.name || '' }).then(eRes => { this.$u.api.getEligibility({ phone: res.data.mobile, identityNo: res.data.idNo || '', name: res.data.name || '' }).then(eRes => {
if (eRes.errcode === 0) { if (eRes.errcode === 0) {
+4 -2
View File
@@ -43,6 +43,7 @@
<script> <script>
import config from '@/common/config.js' import config from '@/common/config.js'
import account from '@/common/account.js'
export default { export default {
data() { data() {
@@ -71,8 +72,9 @@ export default {
content: '确定要退出登录吗?', content: '确定要退出登录吗?',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
uni.removeStorageSync('token') // xuchao: 原来只清 token/phone,权益缓存(isAuth/hasWin/cardNumber/expiresTime/
uni.removeStorageSync('phone') // rightsCount 等)残留会被下一个账号当成自己的数据展示
account.clearAccountCache()
this.isLogin = false this.isLogin = false
this.phone = '' this.phone = ''
uni.showToast({ title: '已退出登录', icon: 'success' }) uni.showToast({ title: '已退出登录', icon: 'success' })