From a95803867c6ef201a55e703ed1482cb21e8c0d75 Mon Sep 17 00:00:00 2001 From: chansee97 Date: Mon, 1 Apr 2024 10:34:11 +0800 Subject: [PATCH] fix: async static routes --- .env | 2 +- src/router/routes.static.ts | 395 +++++++++++++++++++++++++++++------- src/typings/route.d.ts | 4 +- 3 files changed, 327 insertions(+), 74 deletions(-) diff --git a/.env b/.env index 77ad0d3..b48df03 100644 --- a/.env +++ b/.env @@ -5,7 +5,7 @@ VITE_APP_NAME=Nova - Admin # 路由模式 VITE_ROUTE_MODE = web # 权限路由模式: static | dynamic -VITE_AUTH_ROUTE_MODE=dynamic +VITE_AUTH_ROUTE_MODE=static # 设置登陆后跳转地址 VITE_HOME_PATH = /dashboard/workbench diff --git a/src/router/routes.static.ts b/src/router/routes.static.ts index 7542d98..3854085 100644 --- a/src/router/routes.static.ts +++ b/src/router/routes.static.ts @@ -1,140 +1,393 @@ export const staticRoutes: AppRoute.RowRoute[] = [ { - 'id': 1, - 'pid': 0, 'name': 'dashboard', 'path': '/dashboard', - 'componentPath': null, - 'redirect': '/dashboard/workbench', - 'meta.title': '分析页', + 'meta.title': '仪表盘', 'meta.requiresAuth': true, 'meta.icon': 'icon-park-outline:analysis', + 'componentPath': null, + 'id': 1, + 'pid': null, }, { - 'id': 2, - 'pid': 1, 'name': 'dashboard_workbench', 'path': '/dashboard/workbench', - 'componentPath': '/dashboard/workbench/index.vue', 'meta.title': '工作台', 'meta.requiresAuth': true, 'meta.icon': 'icon-park-outline:alarm', + 'meta.pinTab': true, + 'componentPath': '/dashboard/workbench/index.vue', + 'id': 2, + 'pid': 1, }, { - 'id': 3, - 'pid': 1, 'name': 'dashboard_monitor', 'path': '/dashboard/monitor', - 'componentPath': '/dashboard/monitor/index.vue', 'meta.title': '监控页', 'meta.requiresAuth': true, 'meta.icon': 'icon-park-outline:anchor', + 'componentPath': '/dashboard/monitor/index.vue', + 'id': 3, + 'pid': 1, }, { - 'id': 4, - 'pid': 0, 'name': 'test', 'path': '/test', + 'meta.title': '多级菜单演示', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:list', 'componentPath': null, - 'redirect': '/test/test1', - 'meta.title': '测试专题', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:ambulance', + 'id': 4, + 'pid': null, }, { - 'id': 5, - 'pid': 4, - 'name': 'test1', - 'path': '/test/test1', - 'componentPath': '/test/test1/index.vue', - 'meta.title': '测试专题1', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:alarm', - }, - { - 'id': 6, - 'pid': 4, 'name': 'test2', 'path': '/test/test2', - 'componentPath': '/test/test2/index.vue', - 'meta.title': '测试专题2', + 'meta.title': '多级菜单子页', 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:pic', + 'meta.icon': 'icon-park-outline:list', + 'componentPath': '/test/test2/index.vue', + 'id': 6, + 'pid': 4, }, { - 'id': 7, - 'pid': 6, 'name': 'test2_detail', 'path': '/test/test2/detail', - 'componentPath': '/test/test2/detail/index.vue', - 'meta.title': '测试专题2的详情页', + 'meta.title': '多级菜单的详情页', 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:tool', + 'meta.icon': 'icon-park-outline:list', 'meta.hide': true, 'meta.activeMenu': '/test/test2', + 'componentPath': '/test/test2/detail/index.vue', + 'id': 7, + 'pid': 4, }, { - 'id': 8, - 'pid': 4, 'name': 'test3', 'path': '/test/test3', - 'componentPath': null, - 'meta.title': '测试专题3', + 'meta.title': '多级菜单', 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:tool', + 'meta.icon': 'icon-park-outline:list', + 'componentPath': null, + 'id': 8, + 'pid': 4, }, { - 'id': 9, - 'pid': 8, 'name': 'test4', 'path': '/test/test3/test4', + 'meta.title': '多级菜单3-1', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:list', 'componentPath': '/test/test3/test4/index.vue', - 'meta.title': '测试专题4', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:tool', + 'id': 9, + 'pid': 8, }, { - 'id': 10, - 'pid': 0, - 'name': 'permission', - 'path': '/permission', + 'name': 'list', + 'path': '/list', + 'meta.title': '列表页', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:list-two', 'componentPath': null, - 'meta.title': '权限示例', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:people-safe', + 'id': 10, + 'pid': null, }, { + 'name': 'list_commonList', + 'path': '/list/commonList', + 'meta.title': '常用列表', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:list-view', + 'componentPath': '/list/commonList/index.vue', 'id': 11, 'pid': 10, - 'name': 'permission_permission', - 'path': '/permission/permission', - 'componentPath': '/permission/permission/index.vue', - 'meta.title': '权限示例', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:right-user', }, { + 'name': 'list_cardList', + 'path': '/list/cardList', + 'meta.title': '卡片列表', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:view-grid-list', + 'componentPath': '/list/cardList/index.vue', 'id': 12, 'pid': 10, - 'name': 'permission_justSuper', - 'path': '/permission/justSuper', - 'componentPath': '/permission/justSuper/index.vue', - 'meta.title': '超管super可见', - 'meta.requiresAuth': true, - 'meta.icon': 'icon-park-outline:wrong-user', - 'meta.roles': [ - 'super', - ], }, { + 'name': 'plugin', + 'path': '/plugin', + 'meta.title': '功能示例', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:application-one', + 'componentPath': null, 'id': 13, - 'pid': 0, + 'pid': null, + }, + { + 'name': 'fetch', + 'path': '/plugin/fetch', + 'meta.title': '接口功能测试', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:international', + 'componentPath': '/plugin/fetch/index.vue', + 'id': 5, + 'pid': 13, + }, + { + 'name': 'plugin_echarts', + 'path': '/plugin/echarts', + 'meta.title': 'ECharts', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:chart-proportion', + 'componentPath': '/plugin/echarts/index.vue', + 'id': 15, + 'pid': 13, + }, + { 'name': 'PluginMap', 'path': '/plugin/map', - 'componentPath': '/plugin/map/index.vue', 'meta.title': '地图', 'meta.requiresAuth': true, 'meta.icon': 'carbon:map', 'meta.keepAlive': true, + 'componentPath': '/plugin/map/index.vue', + 'id': 17, + 'pid': 13, + }, + { + 'name': 'plugin_editor', + 'path': '/plugin/editor', + 'meta.title': '编辑器', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:editor', + 'componentPath': null, + 'id': 18, + 'pid': 13, + }, + { + 'name': 'plugin_md', + 'path': '/plugin/editor/md', + 'meta.title': 'MarkDown', + 'meta.requiresAuth': true, + 'meta.icon': 'ri:markdown-line', + 'componentPath': '/plugin/editor/md/index.vue', + 'id': 19, + 'pid': 18, + }, + { + 'name': 'plugin_rich', + 'path': '/plugin/editor/rich', + 'meta.title': '富文本', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:edit-one', + 'componentPath': '/plugin/editor/rich/index.vue', + 'id': 20, + 'pid': 18, + }, + { + 'name': 'plugin_clipboard', + 'path': '/plugin/clipboard', + 'meta.title': '剪贴板', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:clipboard', + 'componentPath': '/plugin/clipboard/index.vue', + 'id': 21, + 'pid': 13, + }, + { + 'name': 'plugin_icons', + 'path': '/plugin/icons', + 'meta.title': '图标', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:winking-face-with-open-eyes', + 'componentPath': '/plugin/icons/index.vue', + 'id': 22, + 'pid': 13, + }, + { + 'name': 'plugin_QRCode', + 'path': '/plugin/QRCode', + 'meta.title': '二维码', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:two-dimensional-code', + 'componentPath': '/plugin/QRCode/index.vue', + 'id': 23, + 'pid': 13, + }, + { + 'name': 'docments', + 'path': '/docments', + 'meta.title': '外链文档', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:file-doc', + 'componentPath': null, + 'id': 24, + 'pid': null, + }, + { + 'name': 'docments_vue', + 'path': '/docments/vue', + 'meta.title': 'vue', + 'meta.requiresAuth': true, + 'meta.icon': 'logos:vue', + 'componentPath': '/docments/vue/index.vue', + 'id': 25, + 'pid': 24, + }, + { + 'name': 'docments_vite', + 'path': '/docments/vite', + 'meta.title': 'vite', + 'meta.requiresAuth': true, + 'meta.icon': 'logos:vitejs', + 'componentPath': '/docments/vite/index.vue', + 'id': 26, + 'pid': 24, + }, + { + 'name': 'docments_vueuse', + 'path': '/docments/vueuse', + 'meta.title': 'VueUse(外链)', + 'meta.requiresAuth': true, + 'meta.icon': 'logos:vueuse', + 'meta.herf': 'https://vueuse.org/guide/', + 'componentPath': '/docments/vueuse/index.vue', + 'id': 27, + 'pid': 24, + }, + { + 'name': 'permission', + 'path': '/permission', + 'meta.title': '权限示例', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:people-safe', + 'componentPath': null, + 'id': 28, + 'pid': null, + }, + { + 'name': 'permission_permission', + 'path': '/permission/permission', + 'meta.title': '权限示例', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:right-user', + 'componentPath': '/permission/permission/index.vue', + 'id': 29, + 'pid': 28, + }, + { + 'name': 'permission_justSuper', + 'path': '/permission/justSuper', + 'meta.title': '超管super可见', + 'meta.requiresAuth': true, + 'meta.roles': [ + 'super', + ], + 'meta.icon': 'icon-park-outline:wrong-user', + 'componentPath': '/permission/justSuper/index.vue', + 'id': 30, + 'pid': 28, + }, + { + 'name': 'error', + 'path': '/error', + 'meta.title': '异常页', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:error-computer', + 'componentPath': null, + 'id': 31, + 'pid': null, + }, + { + 'name': 'demo403', + 'path': '/error/403', + 'meta.title': '403页', + 'meta.requiresAuth': true, + 'meta.icon': 'carbon:error', + 'meta.order': 3, + 'componentPath': '/error/403/index.vue', + 'id': 32, + 'pid': 31, + }, + { + 'name': 'demo404', + 'path': '/error/404', + 'meta.title': '404页', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:error', + 'meta.order': 2, + 'componentPath': '/error/404/index.vue', + 'id': 33, + 'pid': 31, + }, + { + 'name': 'demo500', + 'path': '/error/500', + 'meta.title': '500页', + 'meta.requiresAuth': true, + 'meta.icon': 'carbon:data-error', + 'meta.order': 1, + 'componentPath': '/error/500/index.vue', + 'id': 34, + 'pid': 31, + }, + { + 'name': 'setting', + 'path': '/setting', + 'meta.title': '系统设置', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:setting', + 'componentPath': null, + 'id': 35, + 'pid': null, + }, + { + 'name': 'setting_account', + 'path': '/setting/account', + 'meta.title': '用户设置', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:every-user', + 'componentPath': '/setting/account/index.vue', + 'id': 36, + 'pid': 35, + }, + { + 'name': 'setting_dictionary', + 'path': '/setting/dictionary', + 'meta.title': '字典设置', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:book-one', + 'componentPath': '/setting/dictionary/index.vue', + 'id': 37, + 'pid': 35, + }, + { + 'name': 'setting_menu', + 'path': '/setting/menu', + 'meta.title': '菜单设置', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:application-menu', + 'componentPath': '/setting/menu/index.vue', + 'id': 38, + 'pid': 35, + }, + { + 'name': 'userCenter', + 'path': '/userCenter', + 'meta.title': '个人中心', + 'meta.requiresAuth': true, + 'meta.icon': 'carbon:user-avatar-filled-alt', + 'componentPath': '/userCenter/index.vue', + 'id': 39, + 'pid': null, + }, + { + 'name': 'about', + 'path': '/about', + 'meta.title': '关于', + 'meta.requiresAuth': true, + 'meta.icon': 'icon-park-outline:info', + 'componentPath': '/about/index.vue', + 'id': 40, + 'pid': null, }, ] diff --git a/src/typings/route.d.ts b/src/typings/route.d.ts index 508cc63..396135a 100644 --- a/src/typings/route.d.ts +++ b/src/typings/route.d.ts @@ -36,8 +36,8 @@ declare namespace AppRoute { componentPath?: string | null // 路由id id: numnber - // 父级路由id,顶级页面为0 - pid: number + // 父级路由id,顶级页面为null + pid: number | null } type RowRoute = {