From 5cbc5b48d547b91c6f7dbd66cf5977584d120120 Mon Sep 17 00:00:00 2001
From: lzhe <lzhe@example.com>
Date: 星期四, 25 四月 2024 09:14:39 +0800
Subject: [PATCH] 1
---
src/utils/request.js | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/utils/request.js b/src/utils/request.js
index 239f85b..262d2f1 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -1,5 +1,5 @@
import axios from 'axios';
-import { ElNotification, ElMessageBox } from 'element-plus';
+import { ElNotification, ElMessageBox, ElMessage } from 'element-plus';
import sysConfig from "@/config";
import tool from '@/utils/tool';
import router from '@/router';
@@ -12,12 +12,13 @@
axios.interceptors.request.use(
(config) => {
let token = tool.cookie.get("TOKEN");
+ config.headers['Authorization'] = 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
if(token){
config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
}
if(!sysConfig.REQUEST_CACHE && config.method == 'get'){
config.params = config.params || {};
- config.params['_'] = new Date().getTime();
+ // config.params['_'] = new Date().getTime();
}
Object.assign(config.headers, sysConfig.HEADERS)
return config;
@@ -129,7 +130,14 @@
}).then((response) => {
resolve(response.data);
}).catch((error) => {
- reject(error);
+ if(error.status == 400) {
+ ElMessage({
+ message: error.data.msg,
+ type: 'warning',
+ })
+ }else {
+ reject(error);
+ }
})
})
},
@@ -144,7 +152,7 @@
axios({
method: 'post',
url: url,
- headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8','Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'},
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
data: qsStringify(data),
...config
}).then((response) => {
@@ -209,7 +217,14 @@
}).then((response) => {
resolve(response.data);
}).catch((error) => {
- reject(error);
+ if(error.status == 400) {
+ ElMessage({
+ message: error.data.msg,
+ type: 'warning',
+ })
+ }else {
+ reject(error);
+ }
})
})
},
--
Gitblit v1.9.3