请求优化

This commit is contained in:
jia 2023-12-07 09:34:55 +08:00
parent 6a63cdf094
commit 45547b52b7
3 changed files with 128 additions and 120 deletions

View File

@ -17,6 +17,7 @@ function baseRequest(url, method, data, {
header = config.HEADER; header = config.HEADER;
if (store.state.userInfo) { if (store.state.userInfo) {
header.TOKEN = store.state.userInfo.token header.TOKEN = store.state.userInfo.token
} }
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
@ -43,9 +44,13 @@ function baseRequest(url, method, data, {
reslove(res.data); reslove(res.data);
else if (res.data.code == -1) { else if (res.data.code == -1) {
if (onReLogin) { if (res.data.msg == "登录超时,请重新登录") {
// store.commit('LOGOUT'); // store.commit('LOGOUT');
uni.reLaunch({
url:'/pages/Login/login'
})
} }
} else if (res.data.code == 0) { } else if (res.data.code == 0) {
if (res.data.msg != '用户信息不存在') { if (res.data.msg != '用户信息不存在') {

View File

@ -37,15 +37,18 @@ function baseRequest(url, method, data, {
if (noVerify) if (noVerify)
reslove(res.data); reslove(res.data);
else if (res.data.code == -1) { else if (res.data.code == -1) {
// if (onReLogin) {
// // store.commit('LOGOUT');
// return reject();
// } if (res.data.msg == "登录超时,请重新登录") {
// store.commit('LOGOUT');
uni.showToast({ uni.showToast({
title: res.data.msg , title: res.data.msg ,
icon: 'none', icon: 'none',
}) })
uni.reLaunch({
url:'/pages/Login/login'
})
}
} else if (res.data.code == 0) { } else if (res.data.code == 0) {
if (res.data.msg != '用户信息不存在') { if (res.data.msg != '用户信息不存在') {
uni.showToast({ uni.showToast({