mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
系统管理
This commit is contained in:
@@ -1,53 +1,42 @@
|
||||
import axios from 'axios'
|
||||
// import openNotification from "../utils/notification";
|
||||
// let { config } = window;
|
||||
// let { baseUrl } = config;
|
||||
import openNotification from '../utils/notification'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const service = axios.create({
|
||||
// baseURL: baseUrl,
|
||||
baseURL: '/api',
|
||||
timeout: 120000
|
||||
})
|
||||
|
||||
service.interceptors.request.use((config) => {
|
||||
const webConfig = config
|
||||
// if (!['/login'].includes(config.url)) {
|
||||
// if (localStorage.getItem('token')) {
|
||||
// webConfig.headers = {
|
||||
// token: localStorage.getItem('token')
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return webConfig
|
||||
})
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
// 排除以下接口的错误提示
|
||||
const { url } = response.config
|
||||
const urls = ['/light/', '/serve/delete', '/user/checkRandom']
|
||||
const urlFlag = urls.map((item) => {
|
||||
return url.includes(item)
|
||||
})
|
||||
|
||||
const res = response.data
|
||||
|
||||
if (res.code !== 200) {
|
||||
if (res.code == 401 || res.tip == '校验token过期') {
|
||||
if (res.errCode !== 0) {
|
||||
if ((res.ERR_TOKEN = 2 || res.errmsg == '校验token过期')) {
|
||||
setTimeout(() => {
|
||||
window.$wujie?.props.jump({ path: '/login' })
|
||||
// router.push({ path: '/login' })
|
||||
}, 1000)
|
||||
} else if (urlFlag.every((item) => item === false)) {
|
||||
} else {
|
||||
console.log(res.errmsg, 'res.errmsg')
|
||||
message.error(res.errmsg)
|
||||
// openNotification({
|
||||
// status: "error",
|
||||
// desc: res.tip,
|
||||
// });
|
||||
// status: 'error',
|
||||
// desc: res.tip
|
||||
// })
|
||||
}
|
||||
} else {
|
||||
console.log(res.errmsg, 'res.errmsg')
|
||||
|
||||
message.error(res.errmsg)
|
||||
}
|
||||
return res
|
||||
},
|
||||
(error) => {
|
||||
// console.log(error, 'error 此处添加监控超时处理')
|
||||
if (
|
||||
error.name === 'AxiosError' &&
|
||||
error.message === 'timeout of 120000ms exceeded' &&
|
||||
|
||||
Reference in New Issue
Block a user