dee8c762 by renchao@pashanhoo.com

style:token设置

1 parent 1a2d8aba
1 /* 1 /*
2 * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 2 * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
3 * @Autor: renchao 3 * @Autor: renchao
4 * @LastEditTime: 2023-05-31 15:30:02 4 * @LastEditTime: 2023-06-01 09:20:24
5 */ 5 */
6 import axios from 'axios' 6 import axios from 'axios'
7 import { Message } from 'element-ui' 7 import { Message } from 'element-ui'
...@@ -10,9 +10,9 @@ import { endLoadingSubCount } from './requestLoading' ...@@ -10,9 +10,9 @@ import { endLoadingSubCount } from './requestLoading'
10 // create an axios instance 10 // create an axios instance
11 const service = axios.create({ 11 const service = axios.create({
12 baseURL: 12 baseURL:
13 process.env.NODE_ENV == "development" 13 process.env.NODE_ENV == "development"
14 ? process.env.VUE_APP_BASE_API 14 ? process.env.VUE_APP_BASE_API
15 : window.baseUrl + "/", 15 : window.baseUrl + "/",
16 withCredentials: true, //是否允许跨域 16 withCredentials: true, //是否允许跨域
17 headers: { 17 headers: {
18 'Content-Type': 'application/json; charset=utf-8' 18 'Content-Type': 'application/json; charset=utf-8'
...@@ -38,7 +38,7 @@ service.interceptors.request.use( ...@@ -38,7 +38,7 @@ service.interceptors.request.use(
38 return Promise.reject(error); 38 return Promise.reject(error);
39 } 39 }
40 ) 40 )
41 41 window.__isNeedLogin = true
42 // response interceptor 42 // response interceptor
43 service.interceptors.response.use( 43 service.interceptors.response.use(
44 response => { 44 response => {
...@@ -60,7 +60,7 @@ service.interceptors.response.use( ...@@ -60,7 +60,7 @@ service.interceptors.response.use(
60 //todo: 需要解决 一个页面多个请求,刷新后此处会触发多次 60 //todo: 需要解决 一个页面多个请求,刷新后此处会触发多次
61 if (window.__isNeedLogin) { 61 if (window.__isNeedLogin) {
62 window.__isNeedLogin = false 62 window.__isNeedLogin = false
63 this.$message.error('token失效,请重新登录'); 63 Message.error('token失效,请重新登录');
64 let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname; 64 let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
65 localStorage.removeItem('token') 65 localStorage.removeItem('token')
66 if (window._config.casEnable) { 66 if (window._config.casEnable) {
......