From 1a8ac8e42a0ee286f1f67de3fbf8fa5f422d7dd4 Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期三, 11 九月 2024 18:02:25 +0800 Subject: [PATCH] update登录过期的 --- plugins/http.js | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 37 insertions(+), 19 deletions(-) diff --git a/plugins/http.js b/plugins/http.js index d608efb..f393090 100644 --- a/plugins/http.js +++ b/plugins/http.js @@ -1,7 +1,7 @@ import environments from '@/environments' import message from './message' import storage from './storage' -// import store from '../store' +import store from '../store' import utils from './util.js' // import Vue from 'vue' // import { @@ -52,7 +52,7 @@ dataType: options.dataType ? options.dataType : 'json', data: options.data || null, header, - success: (res) => { + success: async (res) => { if (!options.ignore) { message.hideLoading() } @@ -73,16 +73,29 @@ }) } else if (res.data.code === '3000' || res.data && res.data.code && res.data.code.startsWith('3000')) { + let validmsg = '' if (Array.isArray(res.data.data)) { if (res.data.data.length > 0 && res.data.data[0] .msg) { - message.showToast(res.data.data[0].msg) + validmsg = res.data.data[0].msg + // message.showToast(res.data.data[0].msg) } } else if (res.data && res.data.msg) { - message.showToast(res.data.msg) + validmsg = res.data.msg + // message.showToast(res.data.msg) } else if (res.data.data && typeof res.data.data === 'string') { + validmsg = res.data.msg message.showToast(res.data.data) } + if (validmsg) { + //兼容安卓手机提醒过快问题 + setTimeout(() => { + message.showToast(validmsg) + }, 200) + } + + + reject({ data: null, code: parseInt(res.data.code), @@ -94,13 +107,10 @@ } else if (res.data.code === '401' || res.data && res.data.code && res.data.code.startsWith('401')) { console.log('resp', res) + // storage.removeItem('token') + await store.dispatch('logout') message.showToast('登录信息失效') - storage.removeItem('token') - reject({ - data: null, - code: 401, - msg: 'Unauthorized' - }) + // #ifdef PUB_CUSTOMER uni.reLaunch({ url: '/pages/user/supplier-user' @@ -111,6 +121,11 @@ url: '/pages/login/supplier-login' }) // #endif + reject({ + data: null, + code: 401, + msg: 'Unauthorized' + }) } else { if (res.data.data && typeof res.data.data === 'string') { @@ -135,13 +150,11 @@ // commit('updat') // store.commit('updateLogin', false) console.log('401', res) - message.showToast('登录信息失效') storage.removeItem('token') - reject({ - data: null, - code: 401, - msg: 'Unauthorized' - }) + await store.dispatch('logout') + message.showToast('登录信息失效') + + // #ifdef PUB_CUSTOMER uni.reLaunch({ url: '/pages/user/supplier-user' @@ -152,6 +165,11 @@ url: '/pages/login/supplier-login' }) // #endif + reject({ + data: null, + code: 401, + msg: 'Unauthorized' + }) } else if (res.statusCode === 403) { message.showToast('请求被拒绝') @@ -175,11 +193,11 @@ msg: 'Not Found' }) } else if (res.statusCode === 500) { - message.showToast('服务器内部错误') + message.showToast('服务更新升级中,请稍等一分钟左右') reject({ data: null, code: 500, - msg: 'Internal Server Error' + msg: '服务更新升级中,请稍等一分钟左右' }) } else if (res.statusCode === 502) { message.showToast('服务更新升级中,请稍等一分钟左右') @@ -188,7 +206,7 @@ code: 502, msg: '服务更新升级中,请稍等一分钟左右' }) - }else { + } else { message.showToast('其他错误') reject({ data: null, -- Gitblit v1.9.3