From 13401515904922581dd06fa6e9bb5e59b36daa9b Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期一, 25 三月 2024 18:43:31 +0800
Subject: [PATCH] 调整登录页面端口号修改
---
src/common/untils/request.js | 76 ++++++++++++++++++++++----------------
1 files changed, 44 insertions(+), 32 deletions(-)
diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 1c10074..9097a5d 100644
--- a/src/common/untils/request.js
+++ b/src/common/untils/request.js
@@ -3,21 +3,21 @@
// import router from '@/router'
// 寮�鍙戠幆澧冧笅灏嗚嚜宸辩殑token澶嶅埗鍒拌繖閲�, 涔熷彲浠ュ湪娴忚鍣ㄤ腑鎵嬪姩娣诲姞token鍒癱ookie涓�,cookie涓殑token浼樺厛
-const DEV_TOKEN = ''
-function environmentType(){
+const DEV_TOKEN = ""
+function environmentType() {
let type
- if (location.href.includes('192.168.20.119')) {
- type = 'test'
- } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
- type = 'dev'
+ if (location.href.includes("192.168.20.119")) {
+ type = "test"
+ } else if (location.href.includes("192.168") || location.href.includes("localhost")) {
+ type = "dev"
} else {
- type = 'prod'
+ type = "prod"
}
return type
}
-const isDev = environmentType() === 'dev'
+const isDev = environmentType() === "dev"
const Axios = axios.create({
responseType: "json",
@@ -26,9 +26,9 @@
const getApsPage = () => {
// 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
const loginPathMap = {
- prod:`//${window.location.hostname}:9080`,
- test:`//192.168.20.119:9080`,
- dev: `//192.168.8.107:8080`
+ prod: `//${window.location.hostname}:9088`,
+ test: `//192.168.20.119:9088`,
+ dev: `//localhost:8081`
}
return loginPathMap[environmentType()]
}
@@ -41,15 +41,13 @@
// // if (token != undefined) {
// // config.headers.Authorization = "Bearer " + token;
// // }
- let token = document.cookie.replace(
- /(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/,
- "$1",
- );
- if (isDev){
+ let token = localStorage.getItem("token")
+ // let token = document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")
+ if (isDev) {
token = token || DEV_TOKEN
}
if (token) {
- config.headers.Authorization = "Bearer " + token;
+ config.headers.Authorization = "Bearer " + token
}
return config
},
@@ -64,13 +62,13 @@
/* //瀵瑰搷搴旀暟鎹仛浜涗簨 */
if (res.data.code === 200) {
return res.data ? res.data : {}
- } else if([2012,2013,2014,2015].includes(res.data.code)){
- if (isDev){
+ } else if ([2012, 2013, 2014, 2015].includes(res.data.code)) {
+ if (isDev) {
alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
- window.location = getApsPage()+'/login'
- }else {
+ window.location = getApsPage() + "/login"
+ } else {
// JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
- window.location = getApsPage()+'/login'
+ window.location = getApsPage() + "/login"
}
// Message({
// message: res.data.msg,
@@ -78,28 +76,42 @@
// duration: 5 * 1000
// })
return Promise.reject(res.data)
- }else if([2036].includes(res.data.code)){
- if (isDev){
- window.location = getApsPage()+'/commonWeb?resetPwd=true'
- }else {
+ } else if ([2036].includes(res.data.code)) {
+ if (isDev) {
+ window.location = getApsPage() + "/commonWeb?resetPwd=true"
+ } else {
// JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
- window.location = getApsPage()+'/commonWeb?resetPwd=true'
+ window.location = getApsPage() + "/commonWeb?resetPwd=true"
}
return Promise.reject(res.data)
// if(window.location.pathname && window.location.pathname !== '/login'){
// window.location = window.location.origin+'/login'
// }
+ } else if ([3003].includes(res.data.code)) {
+ // 姝ょ姸鎬佷笅涓嶅脊鍑篹rror message
+ console.log("3003")
+ return Promise.resolve(res.data)
+ } else {
+ if (!res.config.loadingFlag) {
+ Message({
+ // message: res.data.msg==res.data.data?res.data.data:res.data.msg+','+res.data.data,
+ message: res.data.msg,
+ type: "error",
+ duration: 5 * 1000
+ })
+ }
+ return res.data ? res.data : {}
}
},
(error) => {
- if(error.response.status === 401){
- if (isDev){
+ if (error.response.status === 401) {
+ if (isDev) {
alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
- window.location = getApsPage()+'/login'
- }else {
+ window.location = getApsPage() + "/login"
+ } else {
// JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
- window.location = getApsPage()+'/login'
+ window.location = getApsPage() + "/login"
}
}
let { message } = error
--
Gitblit v1.8.0