From 78137be892b6810b54ba70f27c28a69a7179e603 Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期一, 15 七月 2024 15:59:35 +0800
Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/WI/Web.V1.0

---
 src/utils/request.ts |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/utils/request.ts b/src/utils/request.ts
index e99f4d2..d0c51f8 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -4,7 +4,7 @@
 import emitter from './mitt';
 import { debounce } from './util';
 import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants';
-import { Local, Session } from '/@/utils/storage';
+import { Local, LoginInfo, Session } from '/@/utils/storage';
 // import JSONbig from 'json-bigint';
 
 //#region ====================== 鍚庣 res.err_code ======================
@@ -25,12 +25,14 @@
 		(config) => {
 			// 鑾峰彇鏈湴鐨� token
 			const accessSession = Local.get(accessSessionKey);
+
 			if (accessSession) {
 				// 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓�
 				config.headers['hswatersession'] = accessSession;
 			} else {
 				if (config.url !== loginUrl) {
 					handleNoAuth(config.url);
+
 					throw '鏉冮檺楠岃瘉澶辫触';
 				}
 			}
@@ -89,7 +91,6 @@
 					clearAccessTokens();
 				}
 			}
-
 			// 瀵瑰搷搴旈敊璇仛鐐逛粈涔�
 			if (error.message.indexOf('timeout') != -1) {
 				ElMessage.error('缃戠粶瓒呮椂');
@@ -138,19 +139,33 @@
  * @description 鍩熷悕鍓嶇紑
  * 闃叉绫讳技浜� http://sqi.beng35.com/airp 鍜� http://sqi.beng35.com/test 鍏敤鍚屼竴涓� token 鎴� userInfo
  */
-const subDomainName = window.location.pathname
-	.split('/')
-	.filter((item) => !!item)
-	.join('-');
-const domainPrefix = subDomainName ? `${subDomainName}-` : '';
+export const getDomainPrefix = (win: Window) => {
+	const subDomainName = win.location.pathname
+		.split('/')
+		.filter((item) => !!item)
+		.join('-');
+	const domainPrefix = subDomainName ? `${subDomainName}-` : '';
+	return domainPrefix;
+};
+
 // token 閿畾涔�
-export const accessSessionKey = domainPrefix + 'access-session';
-export const userNameKey = domainPrefix + 'userName';
+export const sessionName = 'access-session';
+export const userName = 'userName';
+
+export const getSessionKey = (win: Window) => {
+	return getDomainPrefix(win) + sessionName;
+};
+export const getUserNameKey = (win: Window) => {
+	return getDomainPrefix(win) + userName;
+};
+
+export const accessSessionKey = getSessionKey(window);
+export const userNameKey = getUserNameKey(window);
 
 export const refreshAccessTokenKey = `x-${accessSessionKey}`;
 
 // userInfo閿畾涔�
-export const userInfoKey = domainPrefix + 'userInfo';
+export const userInfoKey = getDomainPrefix(window) + 'userInfo';
 
 // 鑾峰彇 token
 export const getSession = () => {
@@ -159,7 +174,8 @@
 
 // 娓呴櫎 token
 export const clearAccessTokens = async () => {
-	Local.remove(accessSessionKey);
+	// Local.remove(accessSessionKey);
+	LoginInfo.remove();
 	// 娓呴櫎鐢ㄦ埛淇℃伅锛堟瘡娆″埛鏂伴兘闇�瑕佸埄鐢ㄧ敤鎴蜂俊鎭幓璇锋眰瀵瑰簲鏉冮檺鑿滃崟锛�
 	Local.remove(userInfoKey);
 	// 娓呴櫎鍏朵粬

--
Gitblit v1.9.3