hookehuyr

登陆状态返回402时处理逻辑

/*
* @Date: 2022-05-18 22:56:08
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-07-27 07:44:07
* @LastEditTime: 2024-08-12 11:52:47
* @FilePath: /data-table/src/api/fn.js
* @Description: 文件描述
*/
......@@ -21,7 +21,7 @@ export const fn = (api) => {
return res.data || true;
} else {
// tslint:disable-next-line: no-console
// if (!res.data.show) return false;
if (!res.data.show) return false;
showFailToast({
message: res.data.msg,
duration: 5000,
......
......@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-12-01 16:33:51
* @LastEditTime: 2024-08-12 12:37:11
* @FilePath: /data-table/src/utils/axios.js
* @Description:
*/
......@@ -11,6 +11,7 @@ import router from '@/router';
import qs from 'Qs'
import { strExist } from '@/utils/tools'
// import { parseQueryString } from '@/utils/tools'
import { showToast } from 'vant';
axios.defaults.params = {
f: 'custom_form',
......@@ -43,6 +44,18 @@ axios.interceptors.request.use(
*/
axios.interceptors.response.use(
response => {
if (response.data.code === 402) { // 未授权状态
// 特殊标识-带此标识报错不显示
response.data.show = false;
//
showToast({
message: '登录失效!将跳转到登录页面',
duration: 1500,
onClose: () => {
window.location.href = location.origin + '/admin/';
}
})
}
return response;
},
error => {
......