import { createWebHistory, createRouter } from 'vue-router' /* Layout */ import Layout from '@/layout' /** * Note: 路由配置项 * * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401,login等页面,或者如一些编辑页面/edit/1 * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面 * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面 * // 若你想不管路由下面的 children 声明的个数都显示你的根路由 * // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由 * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击 * name:'router-name' // 设定路由的名字,一定要填写不然使用时会出现各种问题 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数 * roles: ['admin', 'common'] // 访问路由的角色权限 * permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限 * meta : { noCache: true // 如果设置为true,则不会被 缓存(默认 false) title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字 icon: 'svg-name' // 设置该路由的图标,对应路径src/assets/icons/svg breadcrumb: false // 如果设置为false,则不会在breadcrumb面包屑中显示 activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。 } */ // 公共路由 export const constantRoutes = [ { path: '/redirect', component: Layout, hidden: true, children: [ { path: '/redirect/:path(.*)', component: () => import('@/views/redirect/index.vue') } ] }, { path: '/login', component: () => import('@/views/login'), hidden: true }, { path: '/register', component: () => import('@/views/register'), hidden: true }, { path: "/:pathMatch(.*)*", component: () => import('@/views/error/404'), hidden: true }, { path: '/401', component: () => import('@/views/error/401'), hidden: true }, { path: '', component: Layout, redirect: '/index', children: [ { path: '/index', component: () => import('@/views/index'), name: 'Index', meta: { title: '首页', icon: 'dashboard', affix: true } } ] }, { path: '/lock', component: () => import('@/views/lock'), hidden: true, meta: { title: '锁定屏幕' } }, { path: '/user', component: Layout, hidden: true, redirect: 'noredirect', children: [ { path: 'profile/:activeTab?', component: () => import('@/views/system/user/profile/index'), name: 'Profile', meta: { title: '个人中心', icon: 'user' } } ] } ] // 动态路由,基于用户权限动态去加载 export const dynamicRoutes = [ { path: '/system/user-auth', component: Layout, hidden: true, permissions: ['system:user:edit'], children: [ { path: 'role/:userId(\\d+)', component: () => import('@/views/system/user/authRole'), name: 'AuthRole', meta: { title: '分配角色', activeMenu: '/system/user' } } ] }, { path: '/system/role-auth', component: Layout, hidden: true, permissions: ['system:role:edit'], children: [ { path: 'user/:roleId(\\d+)', component: () => import('@/views/system/role/authUser'), name: 'AuthUser', meta: { title: '分配用户', activeMenu: '/system/role' } } ] }, { path: '/system/dict-data', component: Layout, hidden: true, permissions: ['system:dict:list'], children: [ { path: 'index/:dictId(\\d+)', component: () => import('@/views/system/dict/data'), name: 'Data', meta: { title: '字典数据', activeMenu: '/system/dict' } } ] }, { path: '/monitor/job-log', component: Layout, hidden: true, permissions: ['monitor:job:list'], children: [ { path: 'index/:jobId(\\d+)', component: () => import('@/views/monitor/job/log'), name: 'JobLog', meta: { title: '调度日志', activeMenu: '/monitor/job' } } ] }, { path: '/tool/gen-edit', component: Layout, hidden: true, permissions: ['tool:gen:edit'], children: [ { path: 'index/:tableId(\\d+)', component: () => import('@/views/tool/gen/editTable'), name: 'GenEdit', meta: { title: '修改生成配置', activeMenu: '/tool/gen' } } ] }, { // 会员详情:不落菜单表,靠这条隐藏路由注入; // activeMenu 指向列表页,进详情后侧边栏仍高亮「用户列表」 path: '/member/user-detail', component: Layout, hidden: true, permissions: ['member:user:list'], children: [ { path: 'index/:userId(\\d+)', component: () => import('@/views/member/user/detail'), name: 'MemberUserDetail', meta: { title: '用户详情', activeMenu: '/member/user' } } ] }, { // 认证申请审核详情:同「会员详情」,不落菜单表,activeMenu 指回主体认证审核 path: '/member/certification-detail', component: Layout, hidden: true, permissions: ['member:certification:list'], children: [ { path: 'index/:id(\\d+)', component: () => import('@/views/member/certification/detail'), name: 'MemberCertificationDetail', meta: { title: '认证审核详情', activeMenu: '/member/certification' } } ] }, { // 注销申请审核详情:同「认证审核详情」,不落菜单表,activeMenu 指回注销申请审核 path: '/member/cancel-detail', component: Layout, hidden: true, permissions: ['member:cancel:list'], children: [ { path: 'index/:id(\\d+)', component: () => import('@/views/member/cancel/detail'), name: 'MemberCancelDetail', meta: { title: '注销审核详情', activeMenu: '/member/cancel' } } ] }, { // 升级审核详情:同「注销审核详情」,不落菜单表,activeMenu 指回升级审核。 // 权限用 grade:audit:list(与菜单 2217 一致):能进审核队列的人就该能看单子, // 详情里的通过/驳回按钮另受 grade:audit:audit 保护。 path: '/grade/audit-detail', component: Layout, hidden: true, permissions: ['grade:audit:list'], children: [ { path: 'index/:id(\\d+)', component: () => import('@/views/grade/audit/detail'), name: 'GradeAuditDetail', meta: { title: '升级审核详情', activeMenu: '/grade/audit' } } ] }, { // 城市公司档案的新增/查看共用一个组件(查看页即可直接改并提交): // 不落菜单表,靠这条隐藏路由注入;activeMenu 指向列表页。 // 两个 child 的 route name 都与组件的 name(MemberCompanyForm)不同, // 故 keep-alive 匹配不上、每次进入都重新挂载——这正是新增页需要的(不能残留上一次的输入)。 path: '/member/company-form', component: Layout, hidden: true, permissions: ['member:company:list'], children: [ { path: 'add', component: () => import('@/views/member/company/form'), name: 'MemberCompanyAdd', meta: { title: '城市公司档案-新增', activeMenu: '/member/company' } }, { path: 'edit/:id(\\d+)', component: () => import('@/views/member/company/form'), name: 'MemberCompanyEdit', meta: { title: '城市公司档案-详情', activeMenu: '/member/company' } } ] }, { // 服务商的新增/查看共用一个组件。原型里详情页本身就可编辑(原话「详情可编辑信息」), // 故不像公司档案那样做「查看只读 ↔ 修改」双态,两个入口进来都是可编辑表单。 // 不落菜单表,靠这条隐藏路由注入;activeMenu 指向列表页。 // 两个 child 的 route name 都与组件的 name(MemberProviderForm)不同, // 故 keep-alive 匹配不上、每次进入都重新挂载——这正是新增页需要的(不能残留上一次的输入)。 path: '/member/provider-form', component: Layout, hidden: true, permissions: ['member:provider:list'], children: [ { path: 'add', component: () => import('@/views/member/provider/form'), name: 'MemberProviderAdd', meta: { title: '服务商-新增', activeMenu: '/member/provider' } }, { path: 'edit/:id(\\d+)', component: () => import('@/views/member/provider/form'), name: 'MemberProviderEdit', meta: { title: '服务商-详情', activeMenu: '/member/provider' } } ] }, { // 协议配置的「新发布」与「查看(再发一版)」共用一个组件。 // 追加式版本模型下「发布新版本」是插一条新行而不是改这一行,故没有「查看只读 ↔ 修改」双态: // 两个入口进来都是「填版本号 + 内容 → 发布」。 // 不落菜单表,靠这条隐藏路由注入;activeMenu 指向列表页。 // 两个 child 的 route name 都与组件的 name(SystemAgreementForm)不同, // 故 keep-alive 匹配不上、每次进入都重新挂载——这正是新增页需要的(不能残留上一次的输入)。 path: '/system/agreement-form', component: Layout, hidden: true, permissions: ['system:agreement:list'], children: [ { path: 'add', component: () => import('@/views/system/agreement/form'), name: 'SystemAgreementAdd', meta: { title: '协议配置-新发布', activeMenu: '/system/agreement' } }, { path: 'edit/:id(\\d+)', component: () => import('@/views/system/agreement/form'), name: 'SystemAgreementEdit', meta: { title: '协议配置-详情', activeMenu: '/system/agreement' } } ] }, { // 角色的「新增 / 编辑 / 详情」共用一个组件(views/system/role/form.vue), // 模式由 route name 区分,故这里必须给三个互不相同的 name。 // 它们也都不同于组件 name(SystemRoleForm),keep-alive 匹配不上、每次进入都重新挂载 // ——新增页尤其需要(不能残留上一次填的名称与勾选)。 // 不落菜单表,靠这条隐藏路由注入;activeMenu 指向列表页。 path: '/system/role-form', component: Layout, hidden: true, permissions: ['system:role:list'], children: [ { path: 'add', component: () => import('@/views/system/role/form'), name: 'SystemRoleAdd', meta: { title: '新增角色', activeMenu: '/system/role' } }, { path: 'edit/:roleId(\\d+)', component: () => import('@/views/system/role/form'), name: 'SystemRoleEdit', meta: { title: '编辑角色', activeMenu: '/system/role' } }, { path: 'detail/:roleId(\\d+)', component: () => import('@/views/system/role/form'), name: 'SystemRoleDetail', meta: { title: '角色详情', activeMenu: '/system/role' } } ] } ] const router = createRouter({ history: createWebHistory(), routes: constantRoutes, scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition } return { top: 0 } }, }) export default router