From 15ae4a0daffaa7fdec2566a2fc96409b90822a09 Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期二, 12 十一月 2024 13:13:18 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master-2.0' into master-2.0 --- plugins/http.js | 91 +++++++++++++++++++++++++++++++++------------ 1 files changed, 66 insertions(+), 25 deletions(-) diff --git a/plugins/http.js b/plugins/http.js index 47b71d6..59919fb 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,8 @@ dataType: options.dataType ? options.dataType : 'json', data: options.data || null, header, - success: (res) => { + timeout: 30000, + success: async (res) => { if (!options.ignore) { message.hideLoading() } @@ -71,18 +72,31 @@ code: 0, msg: '' }) - } else if (res.data.code === '3000' || res.data && res.data.code && + } else if (res.data.code === '3000' || res.data.code === '30000' || 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), @@ -93,13 +107,13 @@ message.showToast('系统异常') } else if (res.data.code === '401' || res.data && res.data.code && res.data.code.startsWith('401')) { - message.showToast('登录信息失效') - storage.removeItem('token') - reject({ - data: null, - code: 401, - msg: 'Unauthorized' - }) + console.log('resp', res) + // storage.removeItem('token') + // await store.dispatch('logout') + store.commit('updateLogin', false) + + await message.showToast('登录信息失效') + // #ifdef PUB_CUSTOMER uni.reLaunch({ url: '/pages/user/supplier-user' @@ -108,6 +122,12 @@ // #ifndef PUB_CUSTOMER uni.reLaunch({ url: '/pages/login/supplier-login' + }) + // #endif + reject({ + data: null, + code: 401, + msg: 'Unauthorized' }) } else { @@ -132,28 +152,41 @@ // store.dispatch('/clearUserInfo') // commit('updat') // store.commit('updateLogin', false) - storage.removeItem('token') + console.log('401', res) + // storage.removeItem('token') + // await store.dispatch('logout') + store.commit('updateLogin', false) + await message.showToast('登录信息失效') + + + // #ifdef PUB_CUSTOMER + uni.reLaunch({ + url: '/pages/user/supplier-user' + }) + // #endif + // #ifndef PUB_CUSTOMER + uni.reLaunch({ + url: '/pages/login/supplier-login' + }) + // #endif reject({ data: null, code: 401, msg: 'Unauthorized' }) - // #ifdef H5 - uni.reLaunch({ - url: '/views/pc/login.vue' - }) - // #endif - // #ifndef H5 - uni.reLaunch({ - url: '/' - }) - // #endif } else if (res.statusCode === 403) { message.showToast('请求被拒绝') reject({ data: null, code: 403, + msg: 'Forbidden' + }) + } else if (res.statusCode === 429) { + message.showToast('系统操作太频繁,请稍后再试!') + reject({ + data: null, + code: 429, msg: 'Forbidden' }) } else if (res.statusCode === 404) { @@ -164,11 +197,18 @@ 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('服务更新升级中,请稍等一分钟左右') + reject({ + data: null, + code: 502, + msg: '服务更新升级中,请稍等一分钟左右' }) } else { message.showToast('其他错误') @@ -183,6 +223,7 @@ if (!options.ignore) { message.hideLoading() } + message.showToast('网络异常') reject({ data: null, code: 9999, -- Gitblit v1.9.3