mirror of
				https://github.com/soybeanjs/soybean-admin.git
				synced 2025-11-01 06:13:44 +08:00 
			
		
		
		
	feat(projects): 新增静态路由
This commit is contained in:
		| @@ -15,9 +15,9 @@ export async function createDynamicRouteGuard( | ||||
|   const route = useRouteStore(); | ||||
|   const isLogin = Boolean(getToken()); | ||||
|  | ||||
|   // 初始化动态路由 | ||||
|   if (!route.isAddedDynamicRoute) { | ||||
|     // 未登录情况下直接回到登录页,登录成功后再加载动态路由 | ||||
|   // 初始化权限路由 | ||||
|   if (!route.isInitedAuthRoute) { | ||||
|     // 未登录情况下直接回到登录页,登录成功后再加载权限路由 | ||||
|     if (!isLogin) { | ||||
|       if (to.name === routeName('login')) { | ||||
|         next(); | ||||
| @@ -28,16 +28,16 @@ export async function createDynamicRouteGuard( | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     await route.initDynamicRoute(router); | ||||
|     await route.initAuthRoute(router); | ||||
|  | ||||
|     if (to.name === routeName('not-found-page')) { | ||||
|       // 动态路由没有加载导致被not-found-page路由捕获,等待动态路由加载好了,回到之前的路由 | ||||
|       // 动态路由没有加载导致被not-found-page路由捕获,等待权限路由加载好了,回到之前的路由 | ||||
|       next({ path: to.fullPath, replace: true, query: to.query }); | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // 动态路由已经加载,仍然未找到,重定向到not-found | ||||
|   // 权限路由已经加载,仍然未找到,重定向到not-found | ||||
|   if (to.name === routeName('not-found-page')) { | ||||
|     next({ name: routeName('not-found'), replace: true }); | ||||
|     return false; | ||||
|   | ||||
| @@ -21,3 +21,4 @@ export async function setupRouter(app: App) { | ||||
| } | ||||
|  | ||||
| export * from './routes'; | ||||
| export * from './modules'; | ||||
|   | ||||
							
								
								
									
										15
									
								
								src/router/modules/about.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/router/modules/about.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| const about: AuthRoute.Route = { | ||||
|   name: 'about', | ||||
|   path: '/about', | ||||
|   component: 'self', | ||||
|   meta: { | ||||
|     title: '关于', | ||||
|     requiresAuth: true, | ||||
|     singleLayout: 'basic', | ||||
|     permissions: ['super', 'admin', 'test'], | ||||
|     icon: 'fluent:book-information-24-regular', | ||||
|     order: 7, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default about; | ||||
							
								
								
									
										44
									
								
								src/router/modules/component.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/router/modules/component.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| const component: AuthRoute.Route = { | ||||
|   name: 'component', | ||||
|   path: '/component', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'component_button', | ||||
|       path: '/component/button', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '按钮', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-radio-button-checked', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'component_card', | ||||
|       path: '/component/card', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '卡片', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:card-outline', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'component_table', | ||||
|       path: '/component/table', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '表格', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:table-large', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '组件示例', | ||||
|     icon: 'fluent:app-store-24-regular', | ||||
|     order: 3, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default component; | ||||
							
								
								
									
										35
									
								
								src/router/modules/dashboard.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/router/modules/dashboard.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| const dashboard: AuthRoute.Route = { | ||||
|   name: 'dashboard', | ||||
|   path: '/dashboard', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'dashboard_analysis', | ||||
|       path: '/dashboard/analysis', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '分析页', | ||||
|         requiresAuth: true, | ||||
|         icon: 'icon-park-outline:analysis', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'dashboard_workbench', | ||||
|       path: '/dashboard/workbench', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '工作台', | ||||
|         requiresAuth: true, | ||||
|         permissions: ['super', 'admin'], | ||||
|         icon: 'icon-park-outline:workbench', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '仪表盘', | ||||
|     icon: 'carbon:dashboard', | ||||
|     order: 1, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default dashboard; | ||||
							
								
								
									
										54
									
								
								src/router/modules/document.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/router/modules/document.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| const document: AuthRoute.Route = { | ||||
|   name: 'document', | ||||
|   path: '/document', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'document_vue', | ||||
|       path: '/document/vue', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: 'vue文档', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:vuejs', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'document_vue-new', | ||||
|       path: '/document/vue-new', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: 'vue文档(新版)', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:vuejs', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'document_vite', | ||||
|       path: '/document/vite', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: 'vite文档', | ||||
|         requiresAuth: true, | ||||
|         icon: 'simple-icons:vite', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'document_project', | ||||
|       path: '/document/project', | ||||
|       meta: { | ||||
|         title: '项目文档(外链)', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:file-link-outline', | ||||
|         href: 'https://docs.soybean.pro/', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '文档', | ||||
|     icon: 'carbon:document', | ||||
|     order: 2, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default document; | ||||
							
								
								
									
										44
									
								
								src/router/modules/exception.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/router/modules/exception.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| const exception: AuthRoute.Route = { | ||||
|   name: 'exception', | ||||
|   path: '/exception', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'exception_403', | ||||
|       path: '/exception/403', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '异常页403', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-block', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'exception_404', | ||||
|       path: '/exception/404', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '异常页404', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-web-asset-off', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'exception_500', | ||||
|       path: '/exception/500', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '异常页500', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-wifi-off', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '异常页', | ||||
|     icon: 'ant-design:exception-outlined', | ||||
|     order: 5, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default exception; | ||||
							
								
								
									
										5
									
								
								src/router/modules/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/router/modules/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| import { handleModuleRoutes } from '@/utils'; | ||||
|  | ||||
| const modules = import.meta.globEager('./**/*.ts') as AuthRoute.RouteModule; | ||||
|  | ||||
| export const routes = handleModuleRoutes(modules); | ||||
							
								
								
									
										56
									
								
								src/router/modules/multi-menu.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/router/modules/multi-menu.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| const multiMenu: AuthRoute.Route = { | ||||
|   name: 'multi-menu', | ||||
|   path: '/multi-menu', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'multi-menu_first', | ||||
|       path: '/multi-menu/first', | ||||
|       component: 'multi', | ||||
|       children: [ | ||||
|         { | ||||
|           name: 'multi-menu_first_second', | ||||
|           path: '/multi-menu/first/second', | ||||
|           component: 'self', | ||||
|           meta: { | ||||
|             title: '二级菜单', | ||||
|             requiresAuth: true, | ||||
|             icon: 'ic:outline-menu', | ||||
|           }, | ||||
|         }, | ||||
|         { | ||||
|           name: 'multi-menu_first_second-new', | ||||
|           path: '/multi-menu/first/second-new', | ||||
|           component: 'multi', | ||||
|           children: [ | ||||
|             { | ||||
|               name: 'multi-menu_first_second-new_third', | ||||
|               path: '/multi-menu/first/second-new/third', | ||||
|               component: 'self', | ||||
|               meta: { | ||||
|                 title: '三级菜单', | ||||
|                 requiresAuth: true, | ||||
|                 icon: 'ic:outline-menu', | ||||
|               }, | ||||
|             }, | ||||
|           ], | ||||
|           meta: { | ||||
|             title: '二级菜单(有子菜单)', | ||||
|             icon: 'ic:outline-menu', | ||||
|           }, | ||||
|         }, | ||||
|       ], | ||||
|       meta: { | ||||
|         title: '一级菜单', | ||||
|         icon: 'ic:outline-menu', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '多级菜单', | ||||
|     icon: 'carbon:menu', | ||||
|     order: 6, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default multiMenu; | ||||
							
								
								
									
										105
									
								
								src/router/modules/plugin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								src/router/modules/plugin.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| const plugin: AuthRoute.Route = { | ||||
|   name: 'plugin', | ||||
|   path: '/plugin', | ||||
|   component: 'basic', | ||||
|   children: [ | ||||
|     { | ||||
|       name: 'plugin_map', | ||||
|       path: '/plugin/map', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '地图', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:map', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_video', | ||||
|       path: '/plugin/video', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '视频', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:video', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_editor', | ||||
|       path: '/plugin/editor', | ||||
|       component: 'multi', | ||||
|       children: [ | ||||
|         { | ||||
|           name: 'plugin_editor_quill', | ||||
|           path: '/plugin/editor/quill', | ||||
|           component: 'self', | ||||
|           meta: { | ||||
|             title: '富文本编辑器', | ||||
|             requiresAuth: true, | ||||
|             icon: 'mdi:file-document-edit-outline', | ||||
|           }, | ||||
|         }, | ||||
|         { | ||||
|           name: 'plugin_editor_markdown', | ||||
|           path: '/plugin/editor/markdown', | ||||
|           component: 'self', | ||||
|           meta: { | ||||
|             title: 'markdown编辑器', | ||||
|             requiresAuth: true, | ||||
|             icon: 'ri:markdown-line', | ||||
|           }, | ||||
|         }, | ||||
|       ], | ||||
|       meta: { | ||||
|         title: '编辑器', | ||||
|         icon: 'icon-park-outline:editor', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_swiper', | ||||
|       path: '/plugin/swiper', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: 'Swiper插件', | ||||
|         requiresAuth: true, | ||||
|         icon: 'simple-icons:swiper', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_copy', | ||||
|       path: '/plugin/copy', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '剪贴板', | ||||
|         requiresAuth: true, | ||||
|         icon: 'mdi:clipboard-outline', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_icon', | ||||
|       path: '/plugin/icon', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '图标', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-insert-emoticon', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       name: 'plugin_print', | ||||
|       path: '/plugin/print', | ||||
|       component: 'self', | ||||
|       meta: { | ||||
|         title: '打印', | ||||
|         requiresAuth: true, | ||||
|         icon: 'ic:baseline-local-printshop', | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   meta: { | ||||
|     title: '插件示例', | ||||
|     icon: 'clarity:plugin-line', | ||||
|     order: 4, | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export default plugin; | ||||
		Reference in New Issue
	
	Block a user