From 1ef6016d9ddc20893d8c8b3c9be519671c866fb2 Mon Sep 17 00:00:00 2001 From: xingyu Date: Tue, 20 Dec 2022 16:05:16 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=B7=AF=E7=94=B1=E5=AD=90=E9=9B=86?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin-vue3/.env | 3 +++ yudao-ui-admin-vue3/src/utils/routerHelper.ts | 7 ++++++- yudao-ui-admin-vue3/types/env.d.ts | 3 ++- yudao-ui-admin-vue3/vite.config.ts | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/yudao-ui-admin-vue3/.env b/yudao-ui-admin-vue3/.env index e5996ca53..e5dbc8ecf 100644 --- a/yudao-ui-admin-vue3/.env +++ b/yudao-ui-admin-vue3/.env @@ -12,3 +12,6 @@ VITE_APP_TENANT_ENABLE=true # 验证码的开关 VITE_APP_CAPTCHA_ENABLE=true + +# 路由在只有一个子集的时候是否显示父级 +VITE_ROUTE_ALWAYSSHOW_ENABLE=true diff --git a/yudao-ui-admin-vue3/src/utils/routerHelper.ts b/yudao-ui-admin-vue3/src/utils/routerHelper.ts index 02a738da8..d3a2b2283 100644 --- a/yudao-ui-admin-vue3/src/utils/routerHelper.ts +++ b/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 = { diff --git a/yudao-ui-admin-vue3/types/env.d.ts b/yudao-ui-admin-vue3/types/env.d.ts index b8cff557a..33e1f40b8 100644 --- a/yudao-ui-admin-vue3/types/env.d.ts +++ b/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 diff --git a/yudao-ui-admin-vue3/vite.config.ts b/yudao-ui-admin-vue3/vite.config.ts index 6531be705..e5572436a 100644 --- a/yudao-ui-admin-vue3/vite.config.ts +++ b/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']: {