refactor: env var

This commit is contained in:
chansee97 2024-08-09 00:49:55 +08:00
parent a9c7708119
commit d69bd796a4
5 changed files with 26 additions and 15 deletions

20
.env
View File

@ -1,11 +1,14 @@
# 项目根目录
VITE_BASE_URL=/
VITE_BASE_URL = /
# 项目名称
VITE_APP_NAME=Nova - Admin
# 路由模式
VITE_APP_NAME = Nova - Admin
# 路由模式 web hash
VITE_ROUTE_MODE = web
# 权限路由模式: static dynamic
VITE_AUTH_ROUTE_MODE=dynamic
# 路由加载模式 static dynamic
VITE_ROUTE_LOAD_MODE = dynamic
# 设置登陆后跳转地址
VITE_HOME_PATH = /dashboard/workbench
@ -14,7 +17,10 @@ VITE_HOME_PATH = /dashboard/workbench
VITE_STORAGE_PREFIX=
# 版权信息
VITE_COPYRIGHT_INFO= Copyright © 2024 chansee97
VITE_COPYRIGHT_INFO = Copyright © 2024 chansee97
# 自动刷新token
VITE_AUTO_REFRESH_TOKEN=Y
VITE_AUTO_REFRESH_TOKEN = Y
# 默认多语言
VITE_DEFAULT_LANG = enUS

View File

@ -4,10 +4,12 @@ import enUS from '../../locales/en_US.json'
import zhCN from '../../locales/zh_CN.json'
import { local } from '@/utils'
const { VITE_DEFAULT_LANG } = import.meta.env
export const i18n = createI18n({
legacy: false,
locale: local.get('lang') || 'enUS', // 默认显示语言
fallbackLocale: 'enUS',
locale: local.get('lang') || VITE_DEFAULT_LANG, // 默认显示语言
fallbackLocale: VITE_DEFAULT_LANG,
messages: {
zhCN,
enUS,

View File

@ -7,6 +7,8 @@ import { local, setLocale } from '@/utils'
export type TransitionAnimation = '' | 'fade-slide' | 'fade-bottom' | 'fade-scale' | 'zoom-fade' | 'zoom-out'
export type LayoutMode = 'leftMenu' | 'topMenu' | 'mixMenu'
const { VITE_DEFAULT_LANG, VITE_COPYRIGHT_INFO } = import.meta.env
const docEle = ref(document.documentElement)
const { isFullscreen, toggle } = useFullscreen(docEle)
@ -18,8 +20,8 @@ const { system, store } = useColorMode({
export const useAppStore = defineStore('app-store', {
state: () => {
return {
footerText: import.meta.env.VITE_COPYRIGHT_INFO,
lang: 'enUS' as App.lang,
footerText: VITE_COPYRIGHT_INFO,
lang: VITE_DEFAULT_LANG,
theme: themeConfig as GlobalThemeOverrides,
primaryColor: themeConfig.common.primaryColor,
collapsed: false,

View File

@ -38,7 +38,7 @@ export const useRouteStore = defineStore('route-store', {
},
async initRouteInfo() {
if (import.meta.env.VITE_AUTH_ROUTE_MODE === 'dynamic') {
if (import.meta.env.VITE_ROUTE_LOAD_MODE === 'dynamic') {
const userInfo = local.get('userInfo')
if (!userInfo || !userInfo.id) {

View File

@ -21,17 +21,18 @@ interface ImportMetaEnv {
| 'brotliCompress'
| 'deflate'
| 'deflateRaw'
/** hash路由模式 */
/** 路由模式 */
readonly VITE_ROUTE_MODE?: 'hash' | 'web'
/** 路由加载模式 */
readonly VITE_AUTH_ROUTE_MODE: 'static' | 'dynamic'
readonly VITE_ROUTE_LOAD_MODE: 'static' | 'dynamic'
/** 首次加载页面 */
readonly VITE_HOME_PATH: string
/** 版权信息 */
readonly VITE_COPYRIGHT_INFO: string
/** 是否自动刷新token */
readonly VITE_AUTO_REFRESH_TOKEN: 'Y' | 'N'
/** 默认语言 */
readonly VITE_DEFAULT_LANG: App.lang
/** 后端服务的环境类型 */
readonly MODE: ServiceEnvType
}