123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import axios from 'axios'
- import { menuStatusStore, userInfoStore } from '@/stores'
- import { ElMessage } from 'element-plus';
- import router from '@/router';
- const userInfo = userInfoStore()
- const menuStatus = menuStatusStore()
- const base_url = 'http://43.143.198.30:8089/'
- axios.defaults.baseURL = base_url
- axios.defaults.timeout = 30000
- axios.defaults.headers.common['Content-Type'] = 'application/JSON;charset=UTF-8'
- axios.defaults.withCredentials = true;
- const whiteList = []
- axios.interceptors.request.use(
- config => {
-
-
- config.headers.Authorization = userInfo.token
- ? `Bearer ${userInfo.token}`
- : "";
- return config
- },
- error => {
-
- return Promise.reject(error)
- }
- )
- axios.interceptors.response.use(
- response => {
-
- if (response.data.code === 401) {
-
-
-
-
-
-
- if (userInfo.token) {
- ElMessage({
- message: response.data.msg,
- type: 'warning'
- })
- router.push({ name: 'login' })
- menuStatus.saveActiveIndex('6')
- }
-
- userInfo.clearUserInfo()
-
-
-
-
- }
- return response
- }, error => {
- Promise.reject(error)
- }
- )
- export const http = <T>(option: any) => {
- return new Promise((resolve, reject) => {
- axios({
- ...option,
- }).then(res => {
-
- resolve(res.data)
- }).catch(error => {
- reject(error)
- });
- })
- }
|