| | |
| | | import axios from 'axios' |
| | | import { MessageBox, Message } from 'element-ui' |
| | | import { Message, Notification } from 'element-ui' |
| | | import store from '@/store' |
| | | import { getCookie, getToken, removeCookie, setCookie } from '@/utils/auth' |
| | | import { handleDatetime } from '@/utils/global' |
| | | // create an axios instance |
| | | import { removeCookie } from '@/utils/auth' |
| | | |
| | | const service = axios.create({ |
| | | baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url |
| | | withCredentials: true, // send cookies when cross-domain requests |
| | | timeout: 10000 // request timeout |
| | | }) |
| | | // axios.defaults.withCredentials = true |
| | | |
| | | // request interceptor |
| | | service.interceptors.request.use( |
| | | config => { |
| | | // do something before request is sent |
| | | |
| | | // if (getCookie('admin')) { |
| | | // let each request carry token |
| | | // ['X-Token'] is a custom headers key |
| | | // please modify it according to the actual situation |
| | | // config.headers['X-Token'] = getToken() |
| | | // config.headers['Authorization'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // config.headers['Cookie'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // document.cookie = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId') |
| | | // document.cookie = 'admin' |
| | | // } |
| | | config.headers['Token'] = localStorage.getItem('token') |
| | | return config |
| | | }, |
| | |
| | | |
| | | // if the custom code is not 20000, it is judged as an error. |
| | | if (res.code === '300' || res.code === '303') { |
| | | Message({ |
| | | message: res.Message || 'Error', |
| | | type: 'error', |
| | | duration: 5 * 1000 |
| | | }) |
| | | if (res.code === '300') { |
| | | Message({ |
| | | message: res.Message || 'Error', |
| | | type: 'error', |
| | | duration: 5 * 1000 |
| | | }) |
| | | } |
| | | if (res.code === '303') { |
| | | removeCookie('ruleCode') |
| | | removeCookie('username') |
| | | removeCookie('admin') |
| | | removeCookie('navTabId') |
| | | removeCookie('usertype') |
| | | removeCookie('userid') |
| | | removeCookie('rediskey') |
| | | removeCookie('code') |
| | | removeCookie('guid') |
| | | |
| | | removeCookie('stu_torgcode') |
| | | removeCookie('stu_torgname') |
| | | removeCookie('description') |
| | | |
| | | // if (getCookie('cloud')) { |
| | | // removeCookie('cloud') |
| | | // setTimeout(() => { |
| | | // sessionStorage.removeItem('tabViews') |
| | | // window.location.href = 'http://182.61.13.206/choose' |
| | | // }, 1000 * 2) |
| | | // } else { |
| | | setTimeout(() => { |
| | | localStorage.removeItem('token') |
| | | sessionStorage.removeItem('tabViews') |
| | | window.location.reload() |
| | | }, 1000 * 2) |
| | | // } |
| | | // Notification({ |
| | | // message: res.Message || 'Error', |
| | | // type: 'error', |
| | | // duration: 5 * 1000 |
| | | // }) |
| | | removeCookie('usercode') |
| | | localStorage.removeItem('token') |
| | | sessionStorage.removeItem('tabViews') |
| | | // setTimeout(() => { |
| | | // window.location.reload() |
| | | // }, 1000) |
| | | } |
| | | // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; |
| | | // if (res.code === 50008 || res.code === 50012 || res.code === 50014) { |
| | |
| | | // } |
| | | store.state.app.buttonIsDisabled = false // 将按钮变回可点击 |
| | | return Promise.reject(new Error(res.message || 'Error')) |
| | | } |
| | | // else if (res.code === '303') { |
| | | // console.log(res.code, 888) |
| | | // Message({ |
| | | // message: res.Message || 'Error', |
| | | // type: 'error', |
| | | // duration: 5 * 1000 |
| | | // }) |
| | | // removeCookie('ruleCode') |
| | | // removeCookie('username') |
| | | // removeCookie('admin') |
| | | // removeCookie('navTabId') |
| | | // removeCookie('usertype') |
| | | // removeCookie('userid') |
| | | // removeCookie('code') |
| | | // this.$router.push({ path: this.redirect || '/' }) |
| | | // } |
| | | else { |
| | | } else { |
| | | return res |
| | | } |
| | | }, |