From 396b48fd04497c2936538313f43ad79822b849aa Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Wed, 23 Feb 2022 14:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=A6=81=E7=94=A8=E5=90=8E?= =?UTF-8?q?=E8=B8=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 1 + src/plugins/requests/index.js | 31 ++++++++++++++++++++++++++++++- src/setting.js | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 940f258..9ecec0c 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -51,6 +51,7 @@ export default { isClient: `/users/users/user/isClient`, deleteProfile: `/users/users/userInfo/deleteProfile`, checkEmailOrPhone: `/occupationlab/architecture/checkEmailOrPhone`, + accountIsDisabled: `/users/users/user/accountIsDisabled`, userTemplate: `http://39.108.250.202/template/%E6%95%B0%E6%8D%AE%E5%B9%B3%E5%8F%B0%E7%94%A8%E6%88%B7%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx`, // 角色管理 diff --git a/src/plugins/requests/index.js b/src/plugins/requests/index.js index efee4bb..4445823 100644 --- a/src/plugins/requests/index.js +++ b/src/plugins/requests/index.js @@ -3,14 +3,38 @@ import util from '@/libs/util' import router from '@/router/index' import Setting from '@/setting' import store from '@/store' +import api from '@/api' +const baseURL = Setting.apiBaseURL const service = axios.create({ - baseURL: Setting.apiBaseURL, + baseURL, timeout: 10000000 }) // post请求头 service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8' +let check = true +let checkTimer = null +// 检测账号是否被禁用,如果禁用则提示并退出登录 +function checkDisabled () { + const token = util.local.get(Setting.tokenKey) + if (!token) return false + check = false + axios.get(baseURL + api.accountIsDisabled + '?token=' + token, { + token: util.local.get(Setting.tokenKey), + headers: { + token + } + }).then(res => { + console.log(11, res.data) + if (res.data) { + util.errorMsg('当前账号无权限,请重新登录!') + setTimeout(() => { + store.dispatch('user/logout') + }, 1500) + } + }).catch(res => {}) +} // 请求拦截器 service.interceptors.request.use(config => { let token = util.local.get(Setting.tokenKey) @@ -20,6 +44,11 @@ service.interceptors.request.use(config => { if(routeSchoolId) routeSchoolId = atob(decodeURI(routeSchoolId)) // 如果store里没有schoolId,则取url里的schoolId,从用户跳转到后台的时候因为加载顺序的问题会出现这个情况,所以要做这个处理 if(storeSchoolId || routeSchoolId) config.headers.schoolId = storeSchoolId ? storeSchoolId : routeSchoolId + clearTimeout(checkTimer) + check && checkDisabled() + checkTimer = setTimeout(() => { + check = true + }, 2000) return config },err => { util.errorMsg({ diff --git a/src/setting.js b/src/setting.js index c007756..250ecfd 100644 --- a/src/setting.js +++ b/src/setting.js @@ -25,7 +25,7 @@ const Setting = { * 正式:http://www.dataforward.cn:9000 * */ // apiBaseURL: env === 'development' ? 'http://192.168.31.151:9000' : 'http://39.108.250.202:9000', - apiBaseURL: env === 'development' ? 'http://192.168.31.151:9000' : `${location.origin}:9000`, + apiBaseURL: env === 'development' ? 'http://39.108.250.202:9000' : `${location.origin}:9000`, // 接口请求返回错误时,弹窗的持续时间,单位:秒 modalDuration: 3, // 接口请求返回错误时,弹窗的类型,可选值为 Message 或 Notice