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

12
.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 VITE_ROUTE_MODE = web
# 权限路由模式: static dynamic
VITE_AUTH_ROUTE_MODE=dynamic # 路由加载模式 static dynamic
VITE_ROUTE_LOAD_MODE = dynamic
# 设置登陆后跳转地址 # 设置登陆后跳转地址
VITE_HOME_PATH = /dashboard/workbench VITE_HOME_PATH = /dashboard/workbench
@ -18,3 +21,6 @@ VITE_COPYRIGHT_INFO= Copyright © 2024 chansee97
# 自动刷新token # 自动刷新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 zhCN from '../../locales/zh_CN.json'
import { local } from '@/utils' import { local } from '@/utils'
const { VITE_DEFAULT_LANG } = import.meta.env
export const i18n = createI18n({ export const i18n = createI18n({
legacy: false, legacy: false,
locale: local.get('lang') || 'enUS', // 默认显示语言 locale: local.get('lang') || VITE_DEFAULT_LANG, // 默认显示语言
fallbackLocale: 'enUS', fallbackLocale: VITE_DEFAULT_LANG,
messages: { messages: {
zhCN, zhCN,
enUS, 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 TransitionAnimation = '' | 'fade-slide' | 'fade-bottom' | 'fade-scale' | 'zoom-fade' | 'zoom-out'
export type LayoutMode = 'leftMenu' | 'topMenu' | 'mixMenu' export type LayoutMode = 'leftMenu' | 'topMenu' | 'mixMenu'
const { VITE_DEFAULT_LANG, VITE_COPYRIGHT_INFO } = import.meta.env
const docEle = ref(document.documentElement) const docEle = ref(document.documentElement)
const { isFullscreen, toggle } = useFullscreen(docEle) const { isFullscreen, toggle } = useFullscreen(docEle)
@ -18,8 +20,8 @@ const { system, store } = useColorMode({
export const useAppStore = defineStore('app-store', { export const useAppStore = defineStore('app-store', {
state: () => { state: () => {
return { return {
footerText: import.meta.env.VITE_COPYRIGHT_INFO, footerText: VITE_COPYRIGHT_INFO,
lang: 'enUS' as App.lang, lang: VITE_DEFAULT_LANG,
theme: themeConfig as GlobalThemeOverrides, theme: themeConfig as GlobalThemeOverrides,
primaryColor: themeConfig.common.primaryColor, primaryColor: themeConfig.common.primaryColor,
collapsed: false, collapsed: false,

View File

@ -38,7 +38,7 @@ export const useRouteStore = defineStore('route-store', {
}, },
async initRouteInfo() { 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') const userInfo = local.get('userInfo')
if (!userInfo || !userInfo.id) { if (!userInfo || !userInfo.id) {

View File

@ -21,17 +21,18 @@ interface ImportMetaEnv {
| 'brotliCompress' | 'brotliCompress'
| 'deflate' | 'deflate'
| 'deflateRaw' | 'deflateRaw'
/** hash路由模式 */ /** 路由模式 */
readonly VITE_ROUTE_MODE?: 'hash' | 'web' 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_HOME_PATH: string
/** 版权信息 */ /** 版权信息 */
readonly VITE_COPYRIGHT_INFO: string readonly VITE_COPYRIGHT_INFO: string
/** 是否自动刷新token */ /** 是否自动刷新token */
readonly VITE_AUTO_REFRESH_TOKEN: 'Y' | 'N' readonly VITE_AUTO_REFRESH_TOKEN: 'Y' | 'N'
/** 默认语言 */
readonly VITE_DEFAULT_LANG: App.lang
/** 后端服务的环境类型 */ /** 后端服务的环境类型 */
readonly MODE: ServiceEnvType readonly MODE: ServiceEnvType
} }