import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' import { AppRouteRecordRaw } from './types' import useStore from '@/store' export const Layout = () => import('@/layout/index.vue') // 参数说明: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html // 静态路由 type RouteMeta = { // 标题 title?: string // 图标 icon?: string // 是否固定 affix?: true // 是否在菜单列表进行隐藏 hidden?: boolean // // 类型 // type: string; } export const constantRoutes: Array = [ { path: '/redirect', component: Layout, meta: { hidden: true }, children: [ { path: '/redirect/:path(.*)', component: () => import('@/views/redirect/index.vue') } ] }, { path: '/login', component: () => import('@/views/login/index.vue'), meta: { hidden: true } }, { path: '/404', component: () => import('@/views/error-page/404.vue'), meta: { hidden: true } }, { path: '/401', component: () => import('@/views/error-page/401.vue'), meta: { hidden: true } }, // 首页 { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', component: () => import('@/views/dashboard/index.vue'), name: 'dashboard', meta: { title: 'dashboard', icon: 'homepage', affix: true } } ] }, // 组件示例 { path: '/components', component: Layout, redirect: '/index', children: [ { path: 'index', component: () => import('@/views/components/index.vue'), name: 'comps', meta: { title: 'comps', icon: 'excel' } } ] }, // 表单示例 { path: '/form', component: Layout, // meta: { title: 'Form', icon: 'guide' }, redirect: '/default', children: [ { path: 'default', component: () => import('@/views/form/default.vue'), name: 'FormDefault', meta: { title: 'form', icon: 'guide' } } ] }, // 列表示例 { path: '/table', component: Layout, redirect: '/default', meta: { title: 'table', icon: 'table' }, children: [ { path: 'default', component: () => import('@/views/table/default.vue'), name: 'TableDefault', meta: { title: 'table' /*, icon: 'table'*/ } }, { path: 'multipleHeader', component: () => import('@/views/table/multipleHeader.vue'), name: 'multipleHeader', meta: { title: 'multipleHeader' } }, { path: 'treeTable', component: () => import('@/views/table/treeTable.vue'), name: 'treeTable', meta: { title: 'treeTable' } }, { path: 'mergeCells', component: () => import('@/views/table/mergeCells.vue'), name: 'mergeCells', meta: { title: 'mergeCells' } }, { path: 'footerSummary', component: () => import('@/views/table/footerSummary.vue'), name: 'footerSummary', meta: { title: 'footerSummary' } }, { path: 'expandTable', component: () => import('@/views/table/expandTable.vue'), name: 'expandTable', meta: { title: 'expandTable' } }, { path: 'resizeParentHeightTable', component: () => import('@/views/table/resizeParentHeightTable.vue'), name: 'resizeParentHeightTable', meta: { title: 'resizeParentHeightTable' } } ] }, // 仅用于研发测试 START /*{ path: '/test', component: Layout, // meta: {hidden: true, title: 'test', icon: 'system'}, meta: { title: 'test', icon: 'system' }, redirect: '/test/testSetup', children: [ { path: 'testSetup', component: () => import('@/views/test/testSetup.vue'), name: 'testSetup', meta: { title: 'testSetup' } }, { path: 'componentCommunication', component: () => import('@/views/test/componentCommunication/index.vue'), name: 'componentCommunication', meta: { title: '组件通信方式' } } ] },*/ { path: '/setting', component: Layout, meta: { title: '设置', icon: 'guide' }, redirect: '/setting/user', children: [ { path: 'user', component: () => import('@/views/setting/user/index.vue'), name: 'user', meta: { title: '用户管理', icon: '' } }, { path: 'post', component: () => import('@/views/setting/post/index.vue'), name: 'post', meta: { title: '岗位管理', icon: '' } }, { path: 'role', component: () => import('@/views/setting/role/index.vue'), name: 'role', meta: { title: '角色管理', icon: '' } }, { path: 'app', component: () => import('@/views/setting/app/index.vue'), name: 'app', meta: { title: '应用管理', icon: '' } }, { path: 'department', component: () => import('@/views/setting/department/index.vue'), name: 'department', meta: { title: '部门管理', icon: '' } }, { path: 'region', component: () => import('@/views/setting/region/index.vue'), name: 'region', meta: { title: '行政区域', icon: '' } }, { path: 'configure', component: () => import('@/views/setting/configure/index.vue'), name: 'configure', meta: { title: '扩展配置', icon: '' } }, { path: 'dict', component: () => import('@/views/setting/dict/index.vue'), name: 'dict', meta: { title: '字典管理', icon: '' } }, { path: 'menu', component: () => import('@/views/setting/menu/index.vue'), name: 'menu', meta: { title: '菜单管理', icon: '' } } ] } // 仅用于研发测试 END // 外部链接 /*{ path: '/external-link', component: Layout, children: [ { path: 'https://github.com/LanceJiang/vue3_element_admin', meta: { title: '外部链接', icon: 'link' } } ] }*/ ] export const noFoundRouters = [ { // redirect: '/404', path: '/:pathMatch(.*)', component: () => import('@/views/error-page/404.vue'), meta: { hidden: true } } ] /** * local_permissionsRoutes: 本地存储带权限路由 每次有新的路由配置 请做好标注!!! * 本地 dev 调试 默认使用本地路由数据 * (若想要调试 接口数据 请在 env.development.local 修改 VITE_APP_USE_LOCAL_ROUTES 不为 1即可) */ export const local_permissionsRoutes: Array = [ { // demo演示 path: '/demo', component: 'Layout', redirect: '/demo/adminManage', meta: { title: 'demo', icon: 'peoples' }, children: [ { path: 'pageConfig', // component: () => import('@/views/demo/pageConfig/index'), component: 'demo/pageConfig/index', name: 'pageConfig', meta: { title: 'demo_pageConfig' } }, { // 管理员管理 path: 'adminManage', name: 'adminManage', component: 'demo/adminManage/index', meta: { title: 'demo_adminManage' } } ] }, // todo 请添加相关新路由描述 // 流程管理 权限 { path: '/flow', // component: Layout, component: '', meta: { title: '流程管理', icon: 'guide' }, redirect: '/flow/group', children: [ { path: 'group1', // component: () => import('@/views/flow/group/index1.vue'), component: 'flow/group/index1', name: 'flow_group1', meta: { title: '流程组', icon: '' } }, { path: 'group', // component: () => import('@/views/flow/group/index.vue'), component: 'flow/group/index', name: 'flow_group', meta: { title: '流程组 - ui调整', icon: '' } }, { path: 'form', // component: () => import('@/views/flow/form/index.vue'), component: 'flow/form/index', name: 'flow_form', meta: { title: '流程表单', icon: '' } }, { path: 'create', // component: () => import('@/views/flow/create/index.vue'), component: 'flow/create/index', name: 'flow_create', meta: { title: '创建流程', icon: '' } }, { path: 'task', // component: () => import('@/views/flow/task/index.vue'), component: 'flow/task/index', name: 'flow_task', meta: { title: '流程任务', icon: '' } }, { path: 'instance', // component: () => import('@/views/flow/instance/index.vue'), component: 'flow/instance/index', name: 'flow_instance', meta: { title: '流程实例', icon: '' } }, { path: 'modal', // component: () => import('@/views/flow/modal/index.vue'), component: 'flow/modal/index', name: 'flow_modal', meta: { title: '流程模型', icon: '' } } ] } ] // 创建路由 const router = createRouter({ history: createWebHashHistory(), routes: constantRoutes.concat(noFoundRouters) as RouteRecordRaw[], // 刷新时,滚动条位置还原 scrollBehavior: () => ({ left: 0, top: 0 }) }) // 重置路由 export function resetRouter() { const { permission } = useStore() permission.routes.forEach(route => { const name = route.name if (name && router.hasRoute(name)) { router.removeRoute(name) } }) } export default router