From 1a0e437bd073d428e276a804c6846e409d92a99e Mon Sep 17 00:00:00 2001
From: charles <981744753@qq.com>
Date: 星期四, 18 七月 2024 23:45:56 +0800
Subject: [PATCH] fix:与aps共享token

---
 src/common/untils/request.js                         |    6 +-
 src/components/layout/components/appHeader/index.vue |   12 ++++--
 src/common/untils/index.js                           |   86 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/src/common/untils/index.js b/src/common/untils/index.js
new file mode 100644
index 0000000..f2a8020
--- /dev/null
+++ b/src/common/untils/index.js
@@ -0,0 +1,86 @@
+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}`+'/#';
+        }
+    }
+};
+/**
+ *  @param dataList 鍘熷垪琛ㄦ暟鎹�
+ *  @param childFieldName 瀛愮骇灞炴�у悕绉�
+ *  @param pIdFieldName 鍏宠仈涓婄骇鑺傜偣灞炴�у悕绉�
+ *  @param idFieldName 鑺傜偣灞炴�у悕绉�
+ *  @param rootValue 鏍硅妭鐐圭殑鍊�(涓�鑸槸灏忎簬绛変簬0鏁�)
+ * */
+export const getTreeData=(dataList,childFieldName='children',pIdFieldName='parentId',idFieldName = 'id',rootValue=0)=>{
+    const rootArr=[];
+    //1.鍏堣幏鍙栨牴鑺傜偣鍒楄〃
+    dataList.forEach(item=>{
+       if(item[pIdFieldName]===rootValue){//鏄牴鑺傜偣
+           //1.1 閫掑綊鑾峰彇鏍硅妭鐐圭殑鎵�鏈変笅绾ц妭鐐�
+           const children= getChildrenNode(item[idFieldName],dataList);
+           if(Array.isArray(children)&&children.length>0){
+               item[childFieldName]=children;
+           }
+           rootArr.push(item)
+       }
+    });
+    //2.閫掑綊鑾峰彇鏍硅妭鐐圭殑鎵�鏈変笅绾ц妭鐐�
+    function getChildrenNode(parentId,dataList) {
+        //1.鏍规嵁鏍硅妭鐐硅幏鍙� 瀛愯妭鐐瑰垪琛�
+        const childrenArr=dataList.filter(item=>parentId===item[pIdFieldName]);
+        //2.瀛╁瓙鏈夊彲鑳借繕鏈夊瀛� 閬嶅巻瀛╁瓙杩涜閲嶆柊閫掑綊
+        childrenArr.forEach(item=>{
+            const children=getChildrenNode(item[idFieldName],dataList);
+            if(children.length>0){
+                item[childFieldName]=children;
+            }
+        });
+        return childrenArr;
+    }
+    return rootArr;
+};
+
+
diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 7bfc4d3..dcb6d1f 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(
diff --git a/src/components/layout/components/appHeader/index.vue b/src/components/layout/components/appHeader/index.vue
index 389d527..fbdbf5a 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,14 @@
           .then(() => {
             Cookies.remove("token")
             // window.location.href = 'http://localhost:8080/login'; //鏈湴鐨勬櫤鎱у伐鍘�-鐧诲綍椤�
-            window.location.href = "http:" + this.getApsPage() + "/login"
+            //window.location.href = "http:" + this.getApsPage() + "/login"
             this.$message({
               type: "success",
               message: "娉ㄩ攢鎴愬姛!"
-            })
+            });
+              setTimeout(()=>{
+                  window.open(`//${getApsPage()}/login`);
+              },500);
           })
           .catch(() => {
             this.$message({

--
Gitblit v1.8.0