From 12a89593d13fa38810c7af54c7ea8cb72ae65a10 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期二, 14 一月 2025 14:56:45 +0800 Subject: [PATCH] 使用 url 参数传 session --- src/utils/request.ts | 33 +++++++++++++++++---------------- 1 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 9d864a4..6c8eace 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -8,6 +8,7 @@ import { debounce, decodeFormData } from './util'; import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; import { Local, LoginInfo, Session } from '/@/utils/storage'; +import { isSharePage } from '../stores/chatRoom'; // import JSONbig from 'json-bigint'; //#region ====================== 鍚庣 res.err_code ====================== @@ -34,7 +35,7 @@ } return !!accessSession; }; - +export const SESSION_KEY = 'hswatersession'; export const handleNoAuth = debounce(() => { emitNoAuth(); }); @@ -46,9 +47,9 @@ const accessSession = Local.get(accessSessionKey); if (accessSession) { // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� - config.headers['hswatersession'] = accessSession; + config.headers[SESSION_KEY] = accessSession; } - if (!NO_AUTH_API_LIST.includes(config.url)) { + if (!NO_AUTH_API_LIST.includes(config.url) && !isSharePage.value) { if (!accessSession && config.url !== LOGIN_URL && config.url !== TEL_LOGIN_URL) { handleNoAuth(config.url); throw '鏉冮檺楠岃瘉澶辫触'; @@ -88,7 +89,7 @@ if (!serveData.json_ok) { switch (serveData?.err_code) { case ErrorCode.Auth: - if (res.config.url !== LOGIN_URL && res.config.url !== TEL_LOGIN_URL) { + if (res.config.url !== LOGIN_URL && res.config.url !== TEL_LOGIN_URL && !isSharePage.value) { handleNoAuth(); throw '鏉冮檺楠岃瘉澶辫触'; } @@ -131,14 +132,15 @@ const createAxiosInstance = (option: Partial<CreateAxiosDefaults<any>> = {}) => { return axios.create({ baseURL: MAIN_URL, - timeout: 120000, - headers: { 'Content-Type': 'application/json;charset=utf-8 ' }, + timeout: 1200000, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, ...option, }); }; const service = createAxiosInstance(); - export const mainRequest = service; //#region ====================== 娴佸搷搴旀暟鎹� ====================== @@ -147,7 +149,6 @@ responseType: 'stream', }); const decoder = new TextDecoder(); -const encoder = new TextEncoder(); const readStream = async (stream: ReadableStream, cb: (value) => void): Promise<any> => { const reader = stream.getReader(); let lastValue = ''; @@ -161,12 +162,11 @@ // const txt = decoder.decode(Uint8Array.from([...lastValue, ...value])); const txt = decoder.decode(value); const txtArr = txt.split('\n'); - txtArr[0] =lastValue+ txtArr[0] + txtArr[0] = lastValue + txtArr[0]; txtArr.forEach((value, index, array) => { // 涓�鑸笉浼氬嚭鐜拌繛缁崲琛岋紝鍙彲鑳芥渶鍚庝竴涓槸鎹㈣ if (index === array.length - 1) { - lastValue =value; - + lastValue = value; } else { const decodeValue = decodeURIComponent(value); fullValue += decodeValue; @@ -212,7 +212,7 @@ * @description 鍩熷悕鍓嶇紑 * 闃叉绫讳技浜� http://sqi.beng35.com/airp 鍜� http://sqi.beng35.com/test 鍏敤鍚屼竴涓� token 鎴� userInfo */ -export const getDomainPrefix = (win: Window) => { +export const getDomainPrefix = (win: Window = window) => { const subDomainName = win.location.pathname .split('/') .filter((item) => !!item) @@ -221,15 +221,17 @@ return domainPrefix; }; +export const domainPrefix = getDomainPrefix(window); + // token 閿畾涔� export const sessionName = 'access-session'; export const userName = 'userName'; export const getSessionKey = (win: Window) => { - return getDomainPrefix(win) + sessionName; + return sessionName; }; export const getUserNameKey = (win: Window) => { - return getDomainPrefix(win) + userName; + return userName; }; export const accessSessionKey = getSessionKey(window); @@ -238,8 +240,7 @@ export const refreshAccessTokenKey = `x-${accessSessionKey}`; // userInfo閿畾涔� -export const userInfoKey = getDomainPrefix(window) + 'userInfo'; - +export const userInfoKey ='userInfo'; // 鑾峰彇 token export const getSession = () => { return Local.get(accessSessionKey); -- Gitblit v1.9.3