|
|
|
@ -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({ |
|
|
|
|