feat: env config

This commit is contained in:
zzs 2025-03-05 10:25:49 +08:00
parent 44ea0e635d
commit 5350cc068a
4 changed files with 8 additions and 2 deletions

View File

@ -21,4 +21,4 @@ VITE_GLOB_API_URL = /dev-api
# 接口地址前缀,有些系统所有接口地址都有前缀,可以在这里统一加,方便切换
VITE_GLOB_API_URL_PREFIX =
VITE_HOST_NAME = DESKTOP-F0GAFI5

View File

@ -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
}

View File

@ -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,
}
}

View File

@ -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<CreateAxiosOptions>) {
const { VITE_HOST_NAME } = getAppEnvConfig()
return new VAxios(
// 深度合并
deepMerge(
@ -281,7 +283,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 基础接口地址
// 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 },
// 数据处理方式