Browse Source

perf: 路由子集显示可配置

xingyu 2 years ago
parent
commit
1ef6016d9d

+ 3 - 0
yudao-ui-admin-vue3/.env

@@ -12,3 +12,6 @@ VITE_APP_TENANT_ENABLE=true
 
 # 验证码的开关
 VITE_APP_CAPTCHA_ENABLE=true
+
+# 路由在只有一个子集的时候是否显示父级
+VITE_ROUTE_ALWAYSSHOW_ENABLE=true

+ 6 - 1
yudao-ui-admin-vue3/src/utils/routerHelper.ts

@@ -57,7 +57,12 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
       icon: route.icon,
       hidden: !route.visible,
       noCache: !route.keepAlive,
-      alwaysShow: route.children && route.children.length == 1 ? true : false
+      alwaysShow:
+        route.children &&
+        route.children.length === 1 &&
+        import.meta.env.VITE_ROUTE_ALWAYSSHOW_ENABLE === 'true'
+          ? true
+          : false
     }
     // 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
     let data: AppRouteRecordRaw = {

+ 2 - 1
yudao-ui-admin-vue3/types/env.d.ts

@@ -10,7 +10,8 @@ declare module '*.vue' {
 interface ImportMetaEnv {
   readonly VITE_APP_TITLE: string
   readonly VITE_PORT: number
-  readonly VITE_OPEN: boolean
+  readonly VITE_OPEN: string
+  readonly VITE_ROUTE_ALWAYSSHOW_ENABLE: string
   readonly VITE_APP_CAPTCHA_ENABLE: string
   readonly VITE_APP_TENANT_ENABLE: string
   readonly VITE_BASE_URL: string

+ 1 - 1
yudao-ui-admin-vue3/vite.config.ts

@@ -30,7 +30,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
       // 端口号
       port: env.VITE_PORT,
       host: "0.0.0.0",
-      open: env.VITE_OPEN,
+      open: env.VITE_OPEN === 'true',
       // 本地跨域代理
       proxy: {
         ['/admin-api']: {