|
|
@@ -16,11 +16,13 @@ const service = axios.create({
|
|
|
});
|
|
|
// request拦截器
|
|
|
service.interceptors.request.use(config => {
|
|
|
+ let hasLoginMark = false;
|
|
|
const guidInfo = JSON.parse(window.localStorage.getItem('guidInfo'));
|
|
|
const token = window.localStorage.getItem('AIToken');
|
|
|
if (guidInfo && guidInfo.guid) {
|
|
|
let loginMark = guidInfo.guid;
|
|
|
config.headers['loginmark'] = loginMark;
|
|
|
+ hasLoginMark = true;
|
|
|
}
|
|
|
if (token) {
|
|
|
config.headers['token'] = token;
|
|
|
@@ -31,27 +33,46 @@ service.interceptors.request.use(config => {
|
|
|
delete config.headers['Content-Type'];
|
|
|
}
|
|
|
}
|
|
|
+ // 核心逻辑:检查loginmark是否存在,不存在则拦截请求并跳转
|
|
|
+ if (!hasLoginMark) {
|
|
|
+ // Promise.reject(new Error('缺少loginmark,请求被拦截'));
|
|
|
+ sessionStorage.setItem("errorMsgTit", "无权限使用");
|
|
|
+ if (router.currentRoute.fullPath !== '/error') {
|
|
|
+ router.replace(`/error`);
|
|
|
+ }
|
|
|
+ // 返回reject阻止请求继续发送
|
|
|
+ return Promise.reject();
|
|
|
+ }
|
|
|
return config
|
|
|
}, error => {
|
|
|
Promise.reject(error)
|
|
|
})
|
|
|
|
|
|
// 响应拦截器
|
|
|
-service.interceptors.response.use(async(res) => {
|
|
|
+service.interceptors.response.use(async (res) => {
|
|
|
const code = res.data.StatusCode || 200;
|
|
|
- const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
+ const msg = errorCode[code] || res.data.msg || res.data.Info || errorCode['default']
|
|
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
return res.data
|
|
|
}
|
|
|
if (code === 401) {
|
|
|
console.log(msg)
|
|
|
+ } else if (code === 400) {
|
|
|
+ let errInfo = msg;
|
|
|
+ if (msg === "loginMark不能为空") {
|
|
|
+ errInfo = "无权限登录"
|
|
|
+ }
|
|
|
+ sessionStorage.setItem("errorMsgTit", errInfo);
|
|
|
+ if (router.currentRoute.fullPath !== '/error') {
|
|
|
+ router.replace(`/error`);
|
|
|
+ }
|
|
|
} else if (code === 500) {
|
|
|
Toast(msg);
|
|
|
return Promise.reject(new Error(msg))
|
|
|
} else if (code === 420) {
|
|
|
// 双重判断:内存锁 + 本地缓存锁
|
|
|
const isLock = authLock.isAuthorizing || window.localStorage.getItem('isWechatAuthorizing') === 'true';
|
|
|
-
|
|
|
+
|
|
|
if (isLock) {
|
|
|
return Promise.reject(new Error('正在授权,请勿重复操作'));
|
|
|
}
|
|
|
@@ -75,7 +96,7 @@ service.interceptors.response.use(async(res) => {
|
|
|
authLock.unlock();
|
|
|
console.error('授权跳转失败:', err);
|
|
|
}
|
|
|
- } else if(code === 430){
|
|
|
+ } else if (code === 430) {
|
|
|
// 没有读取到userid
|
|
|
sessionStorage.setItem("errorMsgTit", msg);
|
|
|
router.replace(`/error`);
|