From 059f2a762ac88bb7ec20454a455b4ed2d43877b3 Mon Sep 17 00:00:00 2001
From: charles <981744753@qq.com>
Date: 星期四, 18 七月 2024 21:56:50 +0800
Subject: [PATCH] feat:实现srm与aps共用token
---
.env.development | 8 ++++
src/common/untils/request.js | 6 +-
vue.config.js | 9 ++--
.env.preview | 12 ++++++
src/components/layout/components/appHeader/index.vue | 11 +++--
.env | 18 +++++++++
src/.env.development | 2 +
src/common/untils/index.js | 49 ++++++++++++++++++++++++
8 files changed, 104 insertions(+), 11 deletions(-)
diff --git a/.env b/.env
new file mode 100644
index 0000000..bd7fd8a
--- /dev/null
+++ b/.env
@@ -0,0 +1,18 @@
+# 鎵�鏈夌幆澧冮粯璁�
+
+# 椤甸潰 title 鍓嶇紑
+VUE_APP_TITLE=Basic
+NODE_ENV=development
+VUE_APP_BATH_PATH='http://192.168.20.119:9084'
+# 缃戠粶璇锋眰鍏敤鍦板潃
+VUE_APP_API=/api/
+
+# 浠撳簱鍦板潃
+VUE_APP_REPO=""
+
+# 鍥介檯鍖栭厤缃�
+VUE_APP_I18N_LOCALE=zh-chs
+VUE_APP_I18N_FALLBACK_LOCALE=en
+
+# element 棰滆壊
+VUE_APP_ELEMENT_COLOR=#2A78FB
diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..174ce30
--- /dev/null
+++ b/.env.development
@@ -0,0 +1,8 @@
+# 寮�鍙戠幆澧�
+# 鎸囧畾鏋勫缓妯″紡
+NODE_ENV=development
+
+# 椤甸潰 title 鍓嶇紑
+VUE_APP_TITLE=Basic
+VUE_APP_BATH_PATH='http://192.168.20.119:9084'
+
diff --git a/.env.preview b/.env.preview
new file mode 100644
index 0000000..6d2aea2
--- /dev/null
+++ b/.env.preview
@@ -0,0 +1,12 @@
+# 鏋勫缓棰勮椤甸潰
+
+# 鎸囧畾鏋勫缓妯″紡
+NODE_ENV=production
+
+# 鏍囪褰撳墠鏋勫缓鏂瑰紡
+VUE_APP_BUILD_MODE=PREVIEW
+VUE_APP_BATH_PATH='http://www.fai365.com:9084
+VUE_APP_SCOURCE_LINK=TRUE
+
+# 閮ㄧ讲璺緞
+VUE_APP_PUBLIC_PATH=/
diff --git a/src/.env.development b/src/.env.development
index 174ce30..e2d8944 100644
--- a/src/.env.development
+++ b/src/.env.development
@@ -5,4 +5,6 @@
# 椤甸潰 title 鍓嶇紑
VUE_APP_TITLE=Basic
VUE_APP_BATH_PATH='http://192.168.20.119:9084'
+# 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 ed39ab8..db1b3ec 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浼樺厛
const DEV_TOKEN = ''
@@ -23,7 +23,7 @@
responseType: "json",
withCredentials: true // 鏄惁鍏佽甯ookie杩欎簺
})
-const getApsPage = () => {
+/*const getApsPage = () => {
// 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
const loginPathMap = {
prod:`//${window.location.hostname}:9080`,
@@ -31,7 +31,7 @@
dev: `//192.168.8.117:8080`
}
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 e2e8b75..0095e5f 100644
--- a/src/components/layout/components/appHeader/index.vue
+++ b/src/components/layout/components/appHeader/index.vue
@@ -22,6 +22,7 @@
<script>
import Cookies from "js-cookie"
import UpdatePassWord from "./components/updatePassWord"
+import {getApsPage} from '@/common/untils/index.js'
export default {
name: "SalesLead",
props: {
@@ -65,7 +66,7 @@
return type
},
- getApsPage() {
+ /* getApsPage() {
// 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
const loginPathMap = {
prod: `//${window.location.hostname}:9080`,
@@ -74,9 +75,8 @@
dev: `//192.168.8.117:8080`
}
return loginPathMap[this.environmentType()]
- },
+ },*/
handleCommand(command) {
- console.log(command)
if (command === "logout") {
// this.$router.push({ path: "/login" })
document.cookie = "cookieName=; path=/;"
@@ -88,11 +88,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({
diff --git a/vue.config.js b/vue.config.js
index db22398..decc78e 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -4,7 +4,8 @@
function resolve(dir) {
return path.join(__dirname, dir)
}
-
+const ipNum=144;
+const serverPath=`http://192.168.0.${ipNum}:8001`;
// 璁剧疆涓嶅弬涓庢瀯寤虹殑搴�
const externals = {}
module.exports = {
@@ -14,7 +15,7 @@
devServer: {
proxy: {
"/api/menu":{
- target:"http://192.168.20.119:8001",
+ target:serverPath,
ws: true,
changeOrigin: true
},
@@ -23,12 +24,12 @@
// target: "http://192.168.20.118:8889", // http://192.168.20.119:8002 http://fai365.com:30150/
// target: "http://192.168.20.120:8004",
// target: "http://192.168.20.119:8004", // http://192.168.20.119:8004 http://fai365.com:30150/
- target: "http://192.168.20.119:8004", // http://192.168.20.119:8004 http://fai365.com:30150/
+ target: `http://192.168.0.${ipNum}:8004`, // http://192.168.20.119:8004 http://fai365.com:30150/
ws: true,
changeOrigin: true
},
"/api":{
- target:"http://192.168.20.119:8001",
+ target:serverPath,
ws: true,
changeOrigin: true
},
--
Gitblit v1.8.0