From 39e0e69eff5231ce30e2c027b9209202af80b16b Mon Sep 17 00:00:00 2001 From: QJia <532612154@qq.com> Date: Fri, 15 Nov 2024 14:01:35 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=90=8E=E7=AB=AF=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=97=B6=EF=BC=8C=E6=9C=AC=E5=9C=B0=E9=9D=99?= =?UTF-8?q?=E6=80=81=E8=B7=AF=E7=94=B1=E5=92=8C=E5=90=8E=E7=AB=AF=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/router/access.ts | 8 ++- apps/web-antd/src/router/routes/static.ts | 73 ++++++++++++++++++++++ apps/web-ele/src/router/access.ts | 8 ++- apps/web-ele/src/router/routes/static.ts | 73 ++++++++++++++++++++++ apps/web-naive/src/router/access.ts | 8 ++- apps/web-naive/src/router/routes/static.ts | 73 ++++++++++++++++++++++ 6 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 apps/web-antd/src/router/routes/static.ts create mode 100644 apps/web-ele/src/router/routes/static.ts create mode 100644 apps/web-naive/src/router/routes/static.ts diff --git a/apps/web-antd/src/router/access.ts b/apps/web-antd/src/router/access.ts index 3a48be2378c..e7722086ff2 100644 --- a/apps/web-antd/src/router/access.ts +++ b/apps/web-antd/src/router/access.ts @@ -5,6 +5,7 @@ import type { import { generateAccessible } from '@vben/access'; import { preferences } from '@vben/preferences'; +import { cloneDeep } from '@vben/utils'; import { message } from 'ant-design-vue'; @@ -12,6 +13,8 @@ import { getAllMenusApi } from '#/api'; import { BasicLayout, IFrameView } from '#/layouts'; import { $t } from '#/locales'; +import { staticMenuList } from './routes/static'; + const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue'); async function generateAccess(options: GenerateMenuAndRoutesOptions) { @@ -29,7 +32,10 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) { content: `${$t('common.loadingMenu')}...`, duration: 1.5, }); - return await getAllMenusApi(); + + const dynamicMenus = await getAllMenusApi(); + // 本地菜单和动态菜单合并 + return [...cloneDeep(staticMenuList), ...dynamicMenus]; }, // 可以指定没有权限跳转403页面 forbiddenComponent, diff --git a/apps/web-antd/src/router/routes/static.ts b/apps/web-antd/src/router/routes/static.ts new file mode 100644 index 00000000000..501faad7a8f --- /dev/null +++ b/apps/web-antd/src/router/routes/static.ts @@ -0,0 +1,73 @@ +import type { RouteRecordStringComponent } from '@vben/types'; + +import { $t } from '@vben/locales'; + +/** + * 该文件放非后台返回的前端静态路由 + */ + +/** + * demo + */ +const demoRoute: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + hideChildrenInMenu: true, + icon: 'lucide:copyright', + order: 9999, + title: $t('demos.vben.about'), + }, + name: 'About', + path: '/about', + children: [ + { + component: '/_core/about/index', + meta: { + title: $t('demos.vben.about'), + }, + name: 'VbenAbout', + path: '/vben-admin/about', + }, + ], + }, +]; + +/** + * 这里放本地路由 + */ +export const staticMenuList: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + icon: 'lucide:layout-dashboard', + order: -1, + title: 'page.dashboard.title', + }, + name: 'Dashboard', + path: '/', + redirect: '/analytics', + children: [ + { + name: 'Analytics', + path: '/analytics', + component: '/dashboard/analytics/index', + meta: { + affixTab: true, + icon: 'lucide:area-chart', + title: 'page.dashboard.analytics', + }, + }, + { + name: 'Workspace', + path: '/workspace', + component: '/dashboard/workspace/index', + meta: { + icon: 'carbon:workspace', + title: 'page.dashboard.workspace', + }, + }, + ], + }, + ...demoRoute, +]; diff --git a/apps/web-ele/src/router/access.ts b/apps/web-ele/src/router/access.ts index 2d07c892b23..9f547c75b9f 100644 --- a/apps/web-ele/src/router/access.ts +++ b/apps/web-ele/src/router/access.ts @@ -5,6 +5,7 @@ import type { import { generateAccessible } from '@vben/access'; import { preferences } from '@vben/preferences'; +import { cloneDeep } from '@vben/utils'; import { ElMessage } from 'element-plus'; @@ -12,6 +13,8 @@ import { getAllMenusApi } from '#/api'; import { BasicLayout, IFrameView } from '#/layouts'; import { $t } from '#/locales'; +import { staticMenuList } from './routes/static'; + const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue'); async function generateAccess(options: GenerateMenuAndRoutesOptions) { @@ -29,7 +32,10 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) { duration: 1500, message: `${$t('common.loadingMenu')}...`, }); - return await getAllMenusApi(); + + const dynamicMenus = await getAllMenusApi(); + // 本地菜单和动态菜单合并 + return [...cloneDeep(staticMenuList), ...dynamicMenus]; }, // 可以指定没有权限跳转403页面 forbiddenComponent, diff --git a/apps/web-ele/src/router/routes/static.ts b/apps/web-ele/src/router/routes/static.ts new file mode 100644 index 00000000000..501faad7a8f --- /dev/null +++ b/apps/web-ele/src/router/routes/static.ts @@ -0,0 +1,73 @@ +import type { RouteRecordStringComponent } from '@vben/types'; + +import { $t } from '@vben/locales'; + +/** + * 该文件放非后台返回的前端静态路由 + */ + +/** + * demo + */ +const demoRoute: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + hideChildrenInMenu: true, + icon: 'lucide:copyright', + order: 9999, + title: $t('demos.vben.about'), + }, + name: 'About', + path: '/about', + children: [ + { + component: '/_core/about/index', + meta: { + title: $t('demos.vben.about'), + }, + name: 'VbenAbout', + path: '/vben-admin/about', + }, + ], + }, +]; + +/** + * 这里放本地路由 + */ +export const staticMenuList: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + icon: 'lucide:layout-dashboard', + order: -1, + title: 'page.dashboard.title', + }, + name: 'Dashboard', + path: '/', + redirect: '/analytics', + children: [ + { + name: 'Analytics', + path: '/analytics', + component: '/dashboard/analytics/index', + meta: { + affixTab: true, + icon: 'lucide:area-chart', + title: 'page.dashboard.analytics', + }, + }, + { + name: 'Workspace', + path: '/workspace', + component: '/dashboard/workspace/index', + meta: { + icon: 'carbon:workspace', + title: 'page.dashboard.workspace', + }, + }, + ], + }, + ...demoRoute, +]; diff --git a/apps/web-naive/src/router/access.ts b/apps/web-naive/src/router/access.ts index 7a80bac0979..2e5bda13023 100644 --- a/apps/web-naive/src/router/access.ts +++ b/apps/web-naive/src/router/access.ts @@ -5,12 +5,15 @@ import type { import { generateAccessible } from '@vben/access'; import { preferences } from '@vben/preferences'; +import { cloneDeep } from '@vben/utils'; import { message } from '#/adapter/naive'; import { getAllMenusApi } from '#/api'; import { BasicLayout, IFrameView } from '#/layouts'; import { $t } from '#/locales'; +import { staticMenuList } from './routes/static'; + const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue'); async function generateAccess(options: GenerateMenuAndRoutesOptions) { @@ -27,7 +30,10 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) { message.loading(`${$t('common.loadingMenu')}...`, { duration: 1.5, }); - return await getAllMenusApi(); + + const dynamicMenus = await getAllMenusApi(); + // 本地菜单和动态菜单合并 + return [...cloneDeep(staticMenuList), ...dynamicMenus]; }, // 可以指定没有权限跳转403页面 forbiddenComponent, diff --git a/apps/web-naive/src/router/routes/static.ts b/apps/web-naive/src/router/routes/static.ts new file mode 100644 index 00000000000..501faad7a8f --- /dev/null +++ b/apps/web-naive/src/router/routes/static.ts @@ -0,0 +1,73 @@ +import type { RouteRecordStringComponent } from '@vben/types'; + +import { $t } from '@vben/locales'; + +/** + * 该文件放非后台返回的前端静态路由 + */ + +/** + * demo + */ +const demoRoute: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + hideChildrenInMenu: true, + icon: 'lucide:copyright', + order: 9999, + title: $t('demos.vben.about'), + }, + name: 'About', + path: '/about', + children: [ + { + component: '/_core/about/index', + meta: { + title: $t('demos.vben.about'), + }, + name: 'VbenAbout', + path: '/vben-admin/about', + }, + ], + }, +]; + +/** + * 这里放本地路由 + */ +export const staticMenuList: RouteRecordStringComponent[] = [ + { + component: 'BasicLayout', + meta: { + icon: 'lucide:layout-dashboard', + order: -1, + title: 'page.dashboard.title', + }, + name: 'Dashboard', + path: '/', + redirect: '/analytics', + children: [ + { + name: 'Analytics', + path: '/analytics', + component: '/dashboard/analytics/index', + meta: { + affixTab: true, + icon: 'lucide:area-chart', + title: 'page.dashboard.analytics', + }, + }, + { + name: 'Workspace', + path: '/workspace', + component: '/dashboard/workspace/index', + meta: { + icon: 'carbon:workspace', + title: 'page.dashboard.workspace', + }, + }, + ], + }, + ...demoRoute, +];