调整 token错误更新

This commit is contained in:
浅念
2026-05-08 13:28:09 +08:00
parent bdd6bd1066
commit 845dff1ef7
5 changed files with 30 additions and 20 deletions
+12 -2
View File
@@ -5,15 +5,25 @@
import { import {
version version
} from './package.json' } from './package.json'
import {
silentLogin
} from '@/utils/auth.js'
// #ifdef APP // #ifdef APP
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
// #endif // #endif
export default { export default {
onLaunch: function() { onLaunch: function() {
// 线上示例使用
// console.log('%c uni-app官方团队诚邀优秀前 端工程师加盟,一起打造更卓越的uni-app & uniCloud,欢迎投递简历到 hr2013@dcloud.io', 'color: red');
console.log('App Launch'); console.log('App Launch');
const token = uni.getStorageSync('token')
if (token) {
this.globalData.tokenRefreshPromise = silentLogin().then(result => {
if (!result.success) {
uni.removeStorageSync('token')
}
return result
})
}
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
+1 -1
View File
@@ -31,7 +31,7 @@ async function handle401Error(originalOptions) {
// 清空队列 // 清空队列
retryQueue.length = 0; retryQueue.length = 0;
} else { } else {
// 登录失败,拒绝所有队列中的请求 // 登录失败,拒绝所有队列中的请求并跳转登录页
retryQueue.forEach(({ reject }) => { retryQueue.forEach(({ reject }) => {
reject({ data: { message: '登录失败,请重新登录' } }); reject({ data: { message: '登录失败,请重新登录' } });
}); });
+14 -14
View File
@@ -88,21 +88,21 @@ export default {
homemapurl:'' homemapurl:''
}; };
}, },
onLoad(options) { async onLoad(options) {
// 数据加载逻辑 const token = uni.getStorageSync('token')
if (!uni.getStorageSync('token')) { if (!token) {
this.mini_login().then(() => { await this.mini_login()
this.bannerListfn() } else {
this.configListfn() const refreshPromise = getApp().globalData.tokenRefreshPromise
this.barragelist() if (refreshPromise) {
this.$refs.paging && this.$refs.paging.reload() const result = await refreshPromise
}) if (!result.success) return
}else{ }
this.bannerListfn()
this.configListfn()
this.barragelist()
this.$refs.paging && this.$refs.paging.reload()
} }
this.bannerListfn()
this.configListfn()
this.barragelist()
this.$refs.paging && this.$refs.paging.reload()
}, },
onShow() { onShow() {
this.getFuzzy().then(res => { this.getFuzzy().then(res => {
+2 -2
View File
@@ -81,7 +81,7 @@
icon: 'none' icon: 'none'
}); });
} else if (res.data.code == 0) { } else if (res.data.code == 200) {
//返回数据接收成功 //返回数据接收成功
this.mini_login(); this.mini_login();
} }
@@ -111,7 +111,7 @@
}).then(res => { }).then(res => {
console.log(res.data); console.log(res.data);
uni.hideLoading() uni.hideLoading()
if (res.data.code == 0) { if (res.data.code == 200) {
//存取session //存取session
uni.setStorageSync('openid', res.data.data.openid); uni.setStorageSync('openid', res.data.data.openid);
uni.setStorageSync('token', res.data.data.token); uni.setStorageSync('token', res.data.data.token);
+1 -1
View File
@@ -23,7 +23,7 @@ export function silentLogin() {
'Fdesk-System-Code': 'wechat' 'Fdesk-System-Code': 'wechat'
}, },
success: (res) => { success: (res) => {
if (res.data.code == 0) { if (res.data.code == 200) {
const { token, openid } = res.data.data; const { token, openid } = res.data.data;
// 更新本地存储 // 更新本地存储
uni.setStorageSync('token', token); uni.setStorageSync('token', token);