|
@@ -1,6 +1,8 @@
|
|
|
import axios from 'axios'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
-import { getSessionVar,deleteSessionVar } from "@/utils/session";
|
|
|
+import { getSessionVar, deleteSessionVar } from "@/utils/session";
|
|
|
+
|
|
|
+const NETWORK_ERROR = '网络错误,请稍后重试!'
|
|
|
// 创建 axios 实例
|
|
|
const http = axios.create({
|
|
|
baseURL: '', // 设置基本 URL
|
|
@@ -14,9 +16,9 @@ http.interceptors.request.use(
|
|
|
// console.log('请求被拦截:', config);
|
|
|
// 例如:添加 token 到请求头
|
|
|
// config.headers['Authorization'] = 'Bearer your_token_here';
|
|
|
- if (getSessionVar('session_id') != null && getSessionVar('username') != null){
|
|
|
- config.headers.Authorization = 'Beaver ' + getSessionVar('username') + ' ' + getSessionVar('session_id');
|
|
|
- }
|
|
|
+ if (getSessionVar('session_id') != null && getSessionVar('username') != null) {
|
|
|
+ config.headers.Authorization = 'Beaver ' + getSessionVar('username') + ' ' + getSessionVar('session_id');
|
|
|
+ }
|
|
|
return config; // 必须返回 config,否则请求不会被发送
|
|
|
},
|
|
|
(error) => {
|
|
@@ -54,8 +56,9 @@ http.interceptors.response.use(
|
|
|
// 请求已发出,服务器响应了状态码,但状态码超出了 2xx 的范围
|
|
|
|
|
|
ElMessage({
|
|
|
- message: "服务器响应错误:" + error.response.status,
|
|
|
- type: "warning"
|
|
|
+ message: NETWORK_ERROR,
|
|
|
+ type: "warning",
|
|
|
+ plain: true,
|
|
|
})
|
|
|
|
|
|
} else if (error.request) {
|