From dbab45ef6e56c32ca3b2d286ec5cb7ed0c86bfea Mon Sep 17 00:00:00 2001 From: charles <981744753@qq.com> Date: 星期四, 18 七月 2024 21:57:21 +0800 Subject: [PATCH] feat:实现crm与aps共用token --- src/common/untils/request.js | 32 +++++++++++++++++++++++++------- 1 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/common/untils/request.js b/src/common/untils/request.js index 9cb4874..66335ef 100644 --- a/src/common/untils/request.js +++ b/src/common/untils/request.js @@ -1,6 +1,6 @@ import axios from "axios" import { Message } from "element-ui" - +import {getApsPage} from './index.js'; // import router from '@/router' // 寮�鍙戠幆澧冧笅灏嗚嚜宸辩殑token澶嶅埗鍒拌繖閲�, 涔熷彲浠ュ湪娴忚鍣ㄤ腑鎵嬪姩娣诲姞token鍒癱ookie涓�,cookie涓殑token浼樺厛 @@ -27,17 +27,17 @@ withCredentials: true // 鏄惁鍏佽甯ookie杩欎簺 }) -const getApsPage = () => { +/*const getApsPage = () => { // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛 const loginPathMap = { prod:`//${window.location.hostname}:9080`, test:`//192.168.20.119:9080`, // 鎯宠烦鍒版湰鍦板惎鍔ㄧ殑鐧诲綍椤电殑璇濋渶瑕佹妸dev鏀规垚浣犳湰鍦伴」鐩矾寰� - dev: `//192.168.20.124:8081` + dev: `//192.168.8.108:8080` } return loginPathMap[environmentType()] -} +}*/ /* //POST浼犲弬搴忓垪鍖�(娣诲姞璇锋眰鎷︽埅鍣�) */ Axios.interceptors.request.use( @@ -64,18 +64,35 @@ (res) => { /* //瀵瑰搷搴旀暟鎹仛浜涗簨 */ if (res.data.code === 200) { - return res.data ? res.data : {} + if(res.config.IsHeader){ + return res; + }else{ + return res.data ? res.data : {} + } } else if (res.data.code === 700001 || res.data.code === 700005) { console.log("瀹㈡埛鍚嶇О閲嶅") return res } else if([2012,2013,2014,2015].includes(res.data.code)){ if (isDev){ - alert("JWT澶辨晥") + // alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..") + window.location = getApsPage()+'/login' }else { // JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉 window.location = getApsPage()+'/login' } return Promise.reject(res.data) + }else if([2036].includes(res.data.code)){ + if (isDev){ + window.location = getApsPage()+'/commonWeb?resetPwd=true' + }else { + // JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉 + 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 { Message({ message: res.data.msg, @@ -88,7 +105,8 @@ (error) => { if (error.response.status === 401){ if (isDev){ - alert("JWT澶辨晥") + alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..") + window.location = getApsPage()+'/login' }else { // JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉 window.location = getApsPage()+'/login' -- Gitblit v1.8.0