From 495d1510f9a9ebf1f488569f6ca24a6be56bc9f3 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 12 九月 2024 13:59:23 +0800 Subject: [PATCH] Revert "对接接口" --- src/utils/request.ts | 36 ++++++++++++------------------------ 1 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 7443dcc..d608c7f 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,8 +1,8 @@ import type { AxiosInstance, AxiosRequestConfig } from 'axios'; import axios from 'axios'; import { ElMessage } from 'element-plus'; -import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; import { Local, Session } from '/@/utils/storage'; +import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; // import JSONbig from 'json-bigint'; //#region ====================== 鍚庣 res.Code ====================== @@ -30,7 +30,7 @@ // // 瓒呮椂锛堟殏涓嶄娇鐢級 // TimeOut = -5 //#endregion -const initRequestInterceptor = (request: AxiosInstance,isAuth=false) => { +const initRequestInterceptor = (request: AxiosInstance) => { // 娣诲姞璇锋眰鎷︽埅鍣� request.interceptors.request.use( (config) => { @@ -42,13 +42,8 @@ // 鑾峰彇鏈湴鐨� token const accessToken = Local.get(accessTokenKey); if (accessToken) { - // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓�� - if(isAuth){ - config.headers!['Authorization'] = `Bearer ${accessToken}`; - - }else{ - config.headers['Referrer-Policy'] = undefined; - } + // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� + config.headers!['Authorization'] = `Bearer ${accessToken}`; // 鍒ゆ柇 accessToken 鏄惁杩囨湡 const jwt: any = decryptJWT(accessToken); @@ -122,12 +117,6 @@ Local.set(accessTokenKey, accessToken); Local.set(refreshAccessTokenKey, refreshAccessToken); } - - if (!serve.json_ok && !isAuth) { - // ElMessage.warning(serve.json_msg) - throw new Error('鍝嶅簲閿欒'); - } - // 鍝嶅簲鎷︽埅鍙婅嚜瀹氫箟澶勭悊 if (serve.data === 401) { clearAccessTokens(); @@ -169,17 +158,16 @@ baseURL: MAIN_URL, timeout: 50000, headers: { 'Content-Type': 'application/json;charset=utf-8 ' }, - + // transformResponse: [ + // function (data) { + // const JSONbigToString = JSONbig({ storeAsString: true }); + // // 灏哃ong绫诲瀷鏁版嵁杞崲涓哄瓧绗︿覆 + // return JSONbigToString.parse(data); + // }, + // ], }); -const authService = axios.create({ - // baseURL: MAIN_URL, - timeout: 50000, - headers: { 'Content-Type': 'application/json;charset=utf-8 ' }, - -}); initRequestInterceptor(service); -initRequestInterceptor(authService,true) export function secondaryRequest(config: AxiosRequestConfig<any>) { return service({ @@ -192,7 +180,7 @@ * 鐢ㄤ簬璁块棶鐧诲綍鎺ュ彛 */ export function authRequest(config: AxiosRequestConfig<any>) { - return authService({ + return service({ ...config, baseURL: AUTH_URL, }); -- Gitblit v1.9.3