|
@@ -4,39 +4,42 @@ 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;
|
|
|
-}
|
|
|
+const HOME_URL = '/dashboard'
|
|
|
// 是否展示示例相关菜单
|
|
|
const showDemoRoutes = !!import.meta.env.DEV
|
|
|
-export const constantRoutes: Array<AppRouteRecordRaw> = [
|
|
|
+// 参数说明: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
|
|
|
+// 静态路由
|
|
|
+export const sysStaticRouter: Array<AppRouteRecordRaw> = [
|
|
|
{
|
|
|
- path: '/redirect',
|
|
|
+ path: '/login',
|
|
|
+ component: () => import('@/views/login/index.vue'),
|
|
|
+ meta: { hidden: true }
|
|
|
+ },
|
|
|
+ // 主入口
|
|
|
+ {
|
|
|
+ path: '/',
|
|
|
+ name: 'mainLayout',
|
|
|
component: Layout,
|
|
|
- meta: { hidden: true },
|
|
|
+ redirect: HOME_URL,
|
|
|
+ // redirect: '/dashboard',
|
|
|
children: [
|
|
|
+ // 重定向
|
|
|
{
|
|
|
path: '/redirect/:path(.*)',
|
|
|
+ meta: { hidden: true },
|
|
|
component: () => import('@/views/redirect/index.vue')
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: 'dashboard',
|
|
|
+ component: () => import('@/views/dashboard/index.vue'),
|
|
|
+ name: 'dashboard',
|
|
|
+ meta: { title: 'dashboard', icon: 'icon-homepage', affix: true }
|
|
|
}
|
|
|
]
|
|
|
- },
|
|
|
- {
|
|
|
- path: '/login',
|
|
|
- component: () => import('@/views/login/index.vue'),
|
|
|
- meta: { hidden: true }
|
|
|
- },
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+export const sysErrorRoutes = [
|
|
|
{
|
|
|
path: '/404',
|
|
|
component: () => import('@/views/error-page/404.vue'),
|
|
@@ -47,40 +50,34 @@ export const constantRoutes: Array<AppRouteRecordRaw> = [
|
|
|
component: () => import('@/views/error-page/401.vue'),
|
|
|
meta: { hidden: true }
|
|
|
},
|
|
|
- // 用户
|
|
|
{
|
|
|
- path: '/profile',
|
|
|
- component: Layout,
|
|
|
- name: 'profile',
|
|
|
- meta: { hidden: true, title: '用户' },
|
|
|
- redirect: '/profile/index',
|
|
|
- children: [
|
|
|
- {
|
|
|
- path: 'index',
|
|
|
- component: () => import('@/views/profile/index.vue'),
|
|
|
- name: 'profileIndex',
|
|
|
- meta: {
|
|
|
- hidden: true,
|
|
|
- title: 'profile'
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ // redirect: '/404',
|
|
|
+ path: '/:pathMatch(.*)',
|
|
|
+ component: () => import('@/views/error-page/404.vue'),
|
|
|
+ meta: { hidden: true }
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+export const constantRoutes: AppRouteRecordRaw[] = [
|
|
|
+ // 首页
|
|
|
+ {
|
|
|
+ // path: '/dashboard',
|
|
|
+ path: HOME_URL,
|
|
|
+ component: () => import('@/views/dashboard/index.vue'),
|
|
|
+ name: 'dashboard',
|
|
|
+ meta: { title: 'dashboard', icon: 'icon-homepage', affix: true, parentName: 'mainLayout' }
|
|
|
},
|
|
|
- // 首页 // 主入口
|
|
|
+ /*// 外部链接
|
|
|
{
|
|
|
- path: '/',
|
|
|
- name: 'layout',
|
|
|
+ path: '/external-link',
|
|
|
component: Layout,
|
|
|
- redirect: '/dashboard',
|
|
|
children: [
|
|
|
{
|
|
|
- path: 'dashboard',
|
|
|
- component: () => import('@/views/dashboard/index.vue'),
|
|
|
- name: 'dashboard',
|
|
|
- meta: { title: 'dashboard', icon: 'icon-homepage', affix: true }
|
|
|
+ path: 'https://github.com/LanceJiang/Lance-Element-Admin',
|
|
|
+ meta: { title: '外部链接', icon: 'icon-link' }
|
|
|
}
|
|
|
]
|
|
|
- },
|
|
|
+ },*/
|
|
|
...(showDemoRoutes
|
|
|
? [
|
|
|
// 组件示例
|
|
@@ -101,7 +98,7 @@ export const constantRoutes: Array<AppRouteRecordRaw> = [
|
|
|
{
|
|
|
path: '/form',
|
|
|
component: Layout,
|
|
|
- // meta: { title: 'Form', icon: 'icon-guide' },
|
|
|
+ // meta: { title: 'Form', icon: 'guide' },
|
|
|
redirect: '/default',
|
|
|
children: [
|
|
|
{
|
|
@@ -116,7 +113,7 @@ export const constantRoutes: Array<AppRouteRecordRaw> = [
|
|
|
{
|
|
|
path: '/table',
|
|
|
component: Layout,
|
|
|
- redirect: '/default',
|
|
|
+ redirect: 'default',
|
|
|
meta: { title: 'table', icon: 'icon-table' },
|
|
|
children: [
|
|
|
{
|
|
@@ -166,112 +163,88 @@ export const constantRoutes: Array<AppRouteRecordRaw> = [
|
|
|
{
|
|
|
// demo演示
|
|
|
path: '/demo',
|
|
|
- component: Layout,
|
|
|
+ component: 'Layout',
|
|
|
redirect: '/demo/adminManage',
|
|
|
meta: { title: 'demo', icon: 'icon-peoples' },
|
|
|
children: [
|
|
|
{
|
|
|
+ // path: '/demo/pageConfig',
|
|
|
path: 'pageConfig',
|
|
|
- component: () => import('@/views/demo/pageConfig/index'),
|
|
|
- // component: 'demo/pageConfig/index',
|
|
|
+ // component: () => import('@/views/demo/pageConfig/index'),
|
|
|
+ component: 'demo/pageConfig/index',
|
|
|
name: 'pageConfig',
|
|
|
meta: { title: 'demo_pageConfig', icon: 'le-fangda1' }
|
|
|
},
|
|
|
{
|
|
|
// 管理员管理
|
|
|
+ // path: '/demo/adminManage',
|
|
|
path: 'adminManage',
|
|
|
name: 'adminManage',
|
|
|
- component: () => import('@/views/demo/adminManage/index'),
|
|
|
- // component: 'demo/adminManage/index',
|
|
|
+ component: 'demo/adminManage/index',
|
|
|
meta: { title: 'demo_adminManage', icon: 'Setting' }
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
]
|
|
|
- : [])
|
|
|
- // 仅用于研发测试 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: '组件通信方式' }
|
|
|
- }
|
|
|
- ]
|
|
|
- },*/
|
|
|
- // 仅用于研发测试 END
|
|
|
- // 外部链接
|
|
|
- /*{
|
|
|
- path: '/external-link',
|
|
|
- component: Layout,
|
|
|
- children: [
|
|
|
- {
|
|
|
- path: 'https://github.com/LanceJiang/vue3_element_admin',
|
|
|
- meta: { title: '外部链接', icon: 'icon-link' }
|
|
|
- }
|
|
|
- ]
|
|
|
- }*/
|
|
|
-]
|
|
|
-const getFlatMenuList_1children = (menuList: AppRouteRecordRaw[]) => {
|
|
|
- return menuList.reduce((res, v) => {
|
|
|
- // 过滤掉隐藏
|
|
|
- if (v.meta?.hidden) return res
|
|
|
- const children = v.children
|
|
|
- if (Array.isArray(children) && children.length) {
|
|
|
- if (children.length === 1) {
|
|
|
- const child0 = children[0]
|
|
|
- // delete v.children
|
|
|
- res.push({
|
|
|
- ...child0,
|
|
|
- path: /\/.*/.test(child0.path) ? child0.path : v.name !== 'layout' ? `${v.path}/${child0.path}` : `/${child0.path}`
|
|
|
- })
|
|
|
- } else {
|
|
|
- res.push({
|
|
|
- ...v,
|
|
|
- children: getFlatMenuList_1children(v.children as AppRouteRecordRaw[])
|
|
|
- })
|
|
|
+ : []),
|
|
|
+ // 用户
|
|
|
+ {
|
|
|
+ path: '/profile',
|
|
|
+ component: Layout,
|
|
|
+ name: 'profile',
|
|
|
+ meta: { hidden: true, title: '用户' },
|
|
|
+ redirect: '/profile/index',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ path: 'index',
|
|
|
+ component: () => import('@/views/profile/index.vue'),
|
|
|
+ name: 'profileIndex',
|
|
|
+ meta: {
|
|
|
+ hidden: true,
|
|
|
+ title: 'profile',
|
|
|
+ icon: 'le-account'
|
|
|
+ // parentName: 'mainLayout'
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- res.push(v)
|
|
|
- }
|
|
|
- return res
|
|
|
- }, [] as AppRouteRecordRaw[])
|
|
|
-}
|
|
|
-export const constantMenuList: Array<AppRouteRecordRaw> = getFlatMenuList_1children(constantRoutes)
|
|
|
-export const noFoundRouters = [
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ /*// 仅用于研发测试 START
|
|
|
{
|
|
|
- // redirect: '/404',
|
|
|
- path: '/:pathMatch(.*)',
|
|
|
- component: () => import('@/views/error-page/404.vue'),
|
|
|
- meta: { hidden: true }
|
|
|
+ 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: '组件通信方式' }
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
+ // 仅用于研发测试 END*/
|
|
|
]
|
|
|
|
|
|
/**
|
|
|
- * local_permissionsRoutes: 本地存储带权限路由 每次有新的路由配置 请做好标注!!!
|
|
|
+ * local_permissionsMenuList: 每次有新的路由配置 请做好标注!!!
|
|
|
* 本地 dev 调试 默认使用本地路由数据
|
|
|
* (若想要调试 接口数据 请在 env.development.local 修改 VITE_APP_USE_LOCAL_ROUTES 不为 1即可)
|
|
|
*/
|
|
|
-export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
|
|
|
- // todo 请添加相关新路由描述
|
|
|
+export const local_permissionsMenuList: Array<AppRouteRecordRaw> = [
|
|
|
+ ...constantRoutes,
|
|
|
// 设置 权限
|
|
|
{
|
|
|
path: '/setting',
|
|
|
- // component: Layout,
|
|
|
component: 'Layout',
|
|
|
- meta: { title: '设置', icon: 'icon-guide' },
|
|
|
+ meta: { title: '设置', icon: 'icon-swagger' },
|
|
|
redirect: '/setting/user',
|
|
|
children: [
|
|
|
{
|
|
@@ -279,7 +252,14 @@ export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
|
|
|
// component: () => import('@/views/setting/user/index.vue'),
|
|
|
component: 'setting/user/index',
|
|
|
name: 'user',
|
|
|
- meta: { title: '用户管理', icon: '' }
|
|
|
+ meta: { title: '用户管理', icon: 'icon-logo' } // 本地icon
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: 'role',
|
|
|
+ // component: () => import('@/views/setting/role/index.vue'),
|
|
|
+ component: 'setting/role/index',
|
|
|
+ name: 'role',
|
|
|
+ meta: { title: '角色管理', icon: 'le-amazon' } // le-iconfont
|
|
|
},
|
|
|
{
|
|
|
path: 'post',
|
|
@@ -288,13 +268,6 @@ export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
|
|
|
name: 'post',
|
|
|
meta: { title: '岗位管理', icon: '' }
|
|
|
},
|
|
|
- {
|
|
|
- path: 'role',
|
|
|
- // component: () => import('@/views/setting/role/index.vue'),
|
|
|
- component: 'setting/role/index',
|
|
|
- name: 'role',
|
|
|
- meta: { title: '角色管理', icon: '' }
|
|
|
- },
|
|
|
{
|
|
|
path: 'app',
|
|
|
// component: () => import('@/views/setting/app/index.vue'),
|
|
@@ -333,10 +306,10 @@ export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
|
|
|
},
|
|
|
{
|
|
|
path: 'menu',
|
|
|
- // component: () => import('@/views/setting/menu/index.vue'),
|
|
|
- component: 'setting/menu/index',
|
|
|
+ component: () => import('@/views/setting/menu/index.vue'),
|
|
|
+ // component: 'setting/menu/index',
|
|
|
name: 'menu',
|
|
|
- meta: { title: '菜单管理', icon: '' }
|
|
|
+ meta: { title: '菜单管理', icon: 'PriceTag' } // element icons
|
|
|
}
|
|
|
]
|
|
|
},
|
|
@@ -493,12 +466,13 @@ export const local_permissionsRoutes: Array<AppRouteRecordRaw> = [
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
+ // todo 请添加相关新路由描述
|
|
|
]
|
|
|
|
|
|
// 创建路由
|
|
|
const router = createRouter({
|
|
|
history: createWebHashHistory(),
|
|
|
- routes: constantRoutes.concat(noFoundRouters) as RouteRecordRaw[],
|
|
|
+ routes: sysStaticRouter.concat(sysErrorRoutes) as RouteRecordRaw[],
|
|
|
// 刷新时,滚动条位置还原
|
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
|
})
|
|
@@ -506,7 +480,7 @@ const router = createRouter({
|
|
|
// 重置路由
|
|
|
export function resetRouter() {
|
|
|
const { permission } = useStore()
|
|
|
- permission.routes.forEach(route => {
|
|
|
+ permission.showMenuListFlat.forEach(route => {
|
|
|
const name = route.name
|
|
|
if (name && router.hasRoute(name)) {
|
|
|
router.removeRoute(name)
|