From 5350cc068ab0e98df2948776440380ff249db869 Mon Sep 17 00:00:00 2001 From: zzs Date: Wed, 5 Mar 2025 10:25:49 +0800 Subject: [PATCH] feat: env config --- .env.development | 2 +- src/types/config.d.ts | 2 ++ src/utils/env.ts | 2 ++ src/utils/http/axios/index.ts | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.env.development b/.env.development index cb5bc57..ccd092f 100644 --- a/.env.development +++ b/.env.development @@ -21,4 +21,4 @@ VITE_GLOB_API_URL = /dev-api # 接口地址前缀,有些系统所有接口地址都有前缀,可以在这里统一加,方便切换 VITE_GLOB_API_URL_PREFIX = - +VITE_HOST_NAME = DESKTOP-F0GAFI5 diff --git a/src/types/config.d.ts b/src/types/config.d.ts index 592f08a..ab98534 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -180,4 +180,6 @@ export interface GlobEnvConfig { VITE_GLOB_APP_TENANT_ENABLE: string // 验证码开关 VITE_GLOB_APP_CAPTCHA_ENABLE: string + // 本机hostname,用于spring gateway转发 + VITE_HOST_NAME: string } diff --git a/src/utils/env.ts b/src/utils/env.ts index 45e1db9..c485842 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -25,6 +25,7 @@ export function getAppEnvConfig() { VITE_GLOB_UPLOAD_URL, VITE_GLOB_APP_TENANT_ENABLE, VITE_GLOB_APP_CAPTCHA_ENABLE, + VITE_HOST_NAME, } = ENV if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) { @@ -42,6 +43,7 @@ export function getAppEnvConfig() { VITE_GLOB_UPLOAD_URL, VITE_GLOB_APP_TENANT_ENABLE, VITE_GLOB_APP_CAPTCHA_ENABLE, + VITE_HOST_NAME, } } diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index d832a81..06f393a 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -19,6 +19,7 @@ import { useErrorLogStoreWithOut } from '@/store/modules/errorLog' import { useI18n } from '@/hooks/web/useI18n' import { useUserStoreWithOut } from '@/store/modules/user' import { AxiosRetry } from '@/utils/http/axios/axiosRetry' +import { getAppEnvConfig, isDevMode } from '@/utils/env' const globSetting = useGlobSetting() const urlPrefix = globSetting.urlPrefix @@ -269,6 +270,7 @@ const transform: AxiosTransform = { } function createAxios(opt?: Partial) { + const { VITE_HOST_NAME } = getAppEnvConfig() return new VAxios( // 深度合并 deepMerge( @@ -281,7 +283,7 @@ function createAxios(opt?: Partial) { // 基础接口地址 // baseURL: globSetting.apiUrl, - headers: { 'Content-Type': ContentTypeEnum.JSON }, + headers: { 'Content-Type': ContentTypeEnum.JSON, 'tag': isDevMode() ? VITE_HOST_NAME : undefined }, // 如果是form-data格式 // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, // 数据处理方式