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