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

---
 .env.development                                     |    2 +
 src/common/untils/request.js                         |    8 ++--
 vue.config.js                                        |    6 +-
 src/components/layout/components/appHeader/index.vue |   11 +++--
 src/common/untils/index.js                           |   49 ++++++++++++++++++++++++
 5 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/.env.development b/.env.development
index 9073ccc..78d34fe 100644
--- a/.env.development
+++ b/.env.development
@@ -5,4 +5,6 @@
 # 椤甸潰 title 鍓嶇紑
 VUE_APP_TITLE=Basic
 VUE_APP_BATH_PATH='http://192.168.20.119:9083'
+# aps鏈湴绔彛鍙�
+VUE_APP_APS_PORT=9080
 
diff --git a/src/common/untils/index.js b/src/common/untils/index.js
new file mode 100644
index 0000000..971eac9
--- /dev/null
+++ b/src/common/untils/index.js
@@ -0,0 +1,49 @@
+import router from '@/router';
+export const getPortFromUrl=(url) =>{
+    try {
+        const portPattern = /:\d+/;
+        const urlObj = new URL(url);
+        const portMatch = portPattern.exec(urlObj.host)[0].slice(1); // 鍘绘帀鍐掑彿
+        return parseInt(portMatch, 10); // 杞崲涓烘暣鏁�
+    } catch (error) {
+        console.error(error.message);
+        return null;
+    }
+};
+export const doHostName=(hostname)=>{
+    /* if(hostname.includes('localhost')){
+         return hostname;
+     }*/
+    return hostname.substring(hostname.indexOf(".")+1);
+};
+export const getApsPage = () => {
+    // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
+    /* const loginPathMap = {
+       prod:`//${window.location.hostname}:9080`,
+       test:`//192.168.20.119:9080`,
+       // 鎯宠烦鍒版湰鍦板惎鍔ㄧ殑鐧诲綍椤电殑璇濋渶瑕佹妸dev鏀规垚浣犳湰鍦伴」鐩矾寰�
+       dev: `//192.168.8.112:8080`
+     };*/
+    //return loginPathMap[environmentType()]
+    let port=getPortFromUrl(window.location.href);//鑾峰緱绔彛鍙�
+    let hostname=window.location.hostname;// 涓�绾у煙鍚�
+    if(hostname.includes('fai365.com')||hostname.includes('smartai.com')||hostname.includes('navicat.com')) {// 浠h〃瀛樺湪鍩熷悕
+        hostname='aps.'+doHostName(hostname);
+    }
+    if(hostname.includes('localhost')){
+        port=process.env.VUE_APP_APS_PORT;//绔彛鍙蜂笌 .env.development 涓� VUE_APP_APS_PORT 璺熸湰鍦癮ps椤圭洰鐨勭鍙e彿淇濇寔涓�鑷�
+    }
+    if(router.mode==='history'){
+        if(port){
+            return `${hostname}:${port}`;
+        }else{
+            return `${hostname}`;
+        }
+    }else{
+        if(port){
+            return `${hostname}:${port}`+'/#';
+        }else{
+            return `${hostname}`+'/#';
+        }
+    }
+};
\ No newline at end of file
diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 7bfc4d3..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,7 +27,7 @@
   withCredentials: true // 鏄惁鍏佽甯ookie杩欎簺
 })
 
-const getApsPage = () => {
+/*const getApsPage = () => {
     // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
     const loginPathMap = {
         prod:`//${window.location.hostname}:9080`,
@@ -37,7 +37,7 @@
     }
 
     return loginPathMap[environmentType()]
-}
+}*/
 
 /* //POST浼犲弬搴忓垪鍖�(娣诲姞璇锋眰鎷︽埅鍣�) */
 Axios.interceptors.request.use(
@@ -74,7 +74,7 @@
       return res
     } else if([2012,2013,2014,2015].includes(res.data.code)){
       if (isDev){
-        alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
+       // alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
         window.location = getApsPage()+'/login'
       }else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
diff --git a/src/components/layout/components/appHeader/index.vue b/src/components/layout/components/appHeader/index.vue
index 389d527..d16d43e 100644
--- a/src/components/layout/components/appHeader/index.vue
+++ b/src/components/layout/components/appHeader/index.vue
@@ -21,6 +21,7 @@
 <script>
 import Cookies from "js-cookie"
 import UpdatePassWord from "./components/updatePassWord"
+import {getApsPage} from '@/common/untils/index.js'
 export default {
   name: "SalesLeads",
   props: {
@@ -67,7 +68,7 @@
 
       return type
     },
-    getApsPage() {
+    /*getApsPage() {
       // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
       const loginPathMap = {
         prod: `//${window.location.hostname}:9080`,
@@ -76,7 +77,7 @@
         dev: `//192.168.8.113:8080`
       }
       return loginPathMap[this.environmentType()]
-    },
+    },*/
     handleCommand(command) {
       if (command === "logout") {
         // this.$router.push({ path: "/login" })
@@ -89,11 +90,13 @@
           .then(() => {
             Cookies.remove("token")
             // window.location.href = 'http://localhost:8080/login'; //鏈湴鐨勬櫤鎱у伐鍘�-鐧诲綍椤�
-            window.location.href = "http:" + this.getApsPage() + "/login"
             this.$message({
               type: "success",
               message: "娉ㄩ攢鎴愬姛!"
-            })
+            });
+              setTimeout(()=>{
+                  window.open(`//${getApsPage()}/login`);
+              },500);
           })
           .catch(() => {
             this.$message({
diff --git a/vue.config.js b/vue.config.js
index d13a119..3c48f24 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -4,7 +4,7 @@
 function resolve(dir) {
   return path.join(__dirname, dir)
 }
-
+const ipNum=144;
 // 璁剧疆涓嶅弬涓庢瀯寤虹殑搴�
 const externals = {}
 module.exports = {
@@ -14,14 +14,14 @@
   devServer: {
     proxy: {
       "/api/menu":{
-        target: "http://192.168.20.119:8001", // http://192.168.20.119:8002 http://fai365.com:30150/
+        target: `http://192.168.0.${ipNum}:8001`, // http://192.168.20.119:8002 http://fai365.com:30150/
         // 寤洪亾鏈湴鐜
         // target: "http://192.168.20.118:8002",
         ws: true,
         changeOrigin: true
       },
       "/api": {
-        target: "http://192.168.20.119:8002", // http://192.168.20.119:8002 http://fai365.com:30150/
+        target: `http://192.168.0.${ipNum}:8002`, // http://192.168.20.119:8002 http://fai365.com:30150/
         // 寤洪亾鏈湴鐜
         // target: "http://192.168.20.118:8002",
         ws: true,

--
Gitblit v1.8.0