diff --git a/api/oaUser.js b/api/oaUser.js index f298d6c..5cf351c 100644 --- a/api/oaUser.js +++ b/api/oaUser.js @@ -3,7 +3,7 @@ import oahttp from "@/utils/oahttp.js"; /** * 登录 */ -export const loginAccount = (data) => oahttp.post('/login/account', data, { noAuth: true }) +export const loginAccount = (data, onReLogin = false) => oahttp.post('/login/account', data, { noAuth: true, onReLogin: onReLogin }) /** * cesi diff --git a/store/modules/app.js b/store/modules/app.js index 7e493c1..2580b75 100644 --- a/store/modules/app.js +++ b/store/modules/app.js @@ -59,16 +59,22 @@ const actions = { RE_LOGIN({ state, commit }, data) { return new Promise((resolve, reject) => { let fromData = encrypt.decode('ACT'); - loginAccount({ ...fromData }).then((res) => { - commit('SET_TOKEN', res.data); - oaHttp[data.method](data.url, data.data, data.opt).then((e) => { - resolve(e); + console.log(fromData); + if(fromData) { + loginAccount({ ...fromData }, true).then((res) => { + commit('SET_TOKEN', res.data); + oaHttp[data.method](data.url, data.data, data.opt).then((e) => { + resolve(e); + }).catch((err) => { + reject(err) + }) }).catch((err) => { reject(err) }) - }).catch((err) => { - reject(err) - }) + }else { + commit('LOGOUT') + reject(); + } }) }, MobileLogin({ state, commit }, force) { diff --git a/utils/oahttp.js b/utils/oahttp.js index 97e0b7e..063cdb7 100644 --- a/utils/oahttp.js +++ b/utils/oahttp.js @@ -19,7 +19,8 @@ function toLogin() { function baseRequestTwo(url, method, data, { noAuth = false, - noVerify = false + noVerify = false, + onReLogin = false }) { let Url = HTTP_REQUEST_URL_THREE, header = HEADER; @@ -59,6 +60,10 @@ function baseRequestTwo(url, method, data, { if (noVerify) reslove(res.data); else if (res.data.code == -1) { + if(onReLogin) { + store.commit('LOGOUT'); + return reject(); + } // 如果登录超时,自动重新登录并且继续发送请求 store.dispatch("RE_LOGIN", { url: url,