461 lines
12 KiB
TypeScript
461 lines
12 KiB
TypeScript
// import { markRaw } from 'vue';
|
||
import { createRouter, createWebHistory } from 'vue-router'; // createWebHashHistory, createWebHistory
|
||
import type { Router, RouteRecordRaw, RouteComponent } from 'vue-router';
|
||
// import { Help as IconHelp } from '@element-plus/icons-vue';
|
||
|
||
/* Layout */
|
||
const Layout = ():RouteComponent => import('@/layout/index.vue');
|
||
|
||
/* Router Modules */
|
||
// import componentsRouter from './modules/components';
|
||
// import chartsRouter from './modules/charts';
|
||
// import nestedRouter from './modules/nested';
|
||
// import tableRouter from './modules/table';
|
||
|
||
/**
|
||
* constantRoutes
|
||
* a base page that does not have permission requirements
|
||
* all roles can be accessed
|
||
*
|
||
* 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
|
||
*/
|
||
export const constantRoutes:RouteRecordRaw[] = [
|
||
{
|
||
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: '/auth-redirect',
|
||
component: () => import('@/views/login/auth-redirect.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: '首页', icon: 'dashboard', affix: true }
|
||
}
|
||
]
|
||
},
|
||
// {
|
||
// path: '/documentation',
|
||
// component: Layout,
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/documentation/Message.vue'),
|
||
// name: 'Documentation',
|
||
// meta: { title: 'Documentation', icon: 'documentation', affix: true }
|
||
// }
|
||
// ]
|
||
// },
|
||
// {
|
||
// path: '/guide',
|
||
// component: Layout,
|
||
// redirect: '/guide/index',
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/guide/Message.vue'),
|
||
// name: 'Guide',
|
||
// meta: { title: 'Guide', icon: 'guide', noCache: true }
|
||
// }
|
||
// ]
|
||
// },
|
||
{
|
||
path: '/profile',
|
||
component: Layout,
|
||
redirect: '/profile/index',
|
||
meta: { hidden: true },
|
||
children: [
|
||
{
|
||
path: 'index',
|
||
component: () => import('@/views/profile/index.vue'),
|
||
name: 'Profile',
|
||
meta: { title: 'Profile', icon: 'user', noCache: true }
|
||
}
|
||
]
|
||
}
|
||
];
|
||
|
||
/**
|
||
* asyncRoutes
|
||
* the routes that need to be dynamically loaded based on user roles
|
||
*
|
||
* 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
|
||
*/
|
||
export const asyncRoutes:RouteRecordRaw[] = [
|
||
// {
|
||
// path: '/permission',
|
||
// component: Layout,
|
||
// redirect: '/permission/page',
|
||
// name: 'Permission',
|
||
// meta: {
|
||
// alwaysShow: true, // will always show the root menu
|
||
// title: 'Permission',
|
||
// icon: 'lock',
|
||
// roles: ['admin', 'editor','teacher_user'] // you can set roles in root nav
|
||
// },
|
||
// children: [
|
||
// {
|
||
// path: 'page',
|
||
// component: () => import('@/views/permission/page.vue'),
|
||
// name: 'PagePermission',
|
||
// meta: {
|
||
// title: 'Page Permission',
|
||
// roles: ['admin','teacher_user'] // or you can only set roles in sub nav
|
||
// }
|
||
// },
|
||
// {
|
||
// path: 'directive',
|
||
// component: () => import('@/views/permission/directive.vue'),
|
||
// name: 'DirectivePermission',
|
||
// meta: {
|
||
// title: 'Directive Permission'
|
||
// // if do not set roles, means: this page does not require permission
|
||
// }
|
||
// },
|
||
// {
|
||
// path: 'role',
|
||
// component: () => import('@/views/permission/role.vue'),
|
||
// name: 'RolePermission',
|
||
// meta: {
|
||
// title: 'Role Permission',
|
||
// roles: ['admin','teacher']
|
||
// }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// 个人项目
|
||
{
|
||
path: '/myself',
|
||
component: Layout,
|
||
redirect: '/myself',
|
||
meta: {
|
||
alwaysShow: true, // will always show the root menu
|
||
title: '个人项目',
|
||
icon: 'nested',
|
||
roles: ['admin', 'teacher_user', 'principle', 'developer', 'console']
|
||
},
|
||
children: [
|
||
{
|
||
// 我负责的
|
||
path: 'charge',
|
||
component: () => import('@/views/personal/project/charge.vue'),
|
||
name: 'Charge',
|
||
meta: { title: '我负责的', icon: 'user', affix: true, role: ['console'] }
|
||
},
|
||
{
|
||
// 我管理的
|
||
path: 'manage',
|
||
component: () => import('@/views/personal/project/manage.vue'),
|
||
name: 'Manage',
|
||
meta: { title: '我管理的', icon: 'user', affix: true, role: ['principle', 'developer', 'console'] }
|
||
},
|
||
{
|
||
// 我参与的
|
||
path: 'participate',
|
||
component: () => import('@/views/personal/project/participate.vue'),
|
||
name: 'Participate',
|
||
meta: { title: '我参与的', icon: 'user', affix: true, role: ['principle', 'developer', 'console'] }
|
||
},
|
||
|
||
|
||
|
||
|
||
]
|
||
},
|
||
|
||
|
||
// {
|
||
// path: '/icon',
|
||
// component: Layout,
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/icons/Message.vue'),
|
||
// name: 'Icons',
|
||
// meta: { title: 'Icons', icon: 'icon', noCache: true }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// /** when your routing map is too long, you can split it into small modules **/
|
||
// componentsRouter,
|
||
// chartsRouter,
|
||
// nestedRouter,
|
||
// tableRouter,
|
||
|
||
// {
|
||
// path: '/example',
|
||
// component: Layout,
|
||
// redirect: '/example/list',
|
||
// name: 'Example',
|
||
// meta: {
|
||
// title: 'Example',
|
||
// icon: markRaw(IconHelp)
|
||
// },
|
||
// children: [
|
||
// {
|
||
// path: 'create',
|
||
// component: () => import('@/views/example/create.vue'),
|
||
// name: 'CreateArticle',
|
||
// meta: { title: 'Create Article', icon: 'edit' }
|
||
// },
|
||
// {
|
||
// path: 'edit/:id(\\d+)',
|
||
// component: () => import('@/views/example/edit.vue'),
|
||
// name: 'EditArticle',
|
||
// meta: { hidden: true, title: 'Edit Article', noCache: true, activeMenu: '/example/list' }
|
||
// },
|
||
// {
|
||
// path: 'list',
|
||
// component: () => import('@/views/example/list.vue'),
|
||
// name: 'ArticleList',
|
||
// meta: { title: 'Article List', icon: 'list' }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
{
|
||
path: '/daily',
|
||
component: Layout,
|
||
children: [
|
||
{
|
||
path: 'd',
|
||
component: () => import('@/views/daily/index.vue'),
|
||
name: 'Tab',
|
||
meta: { title: '日报', icon: 'tab', role: ['principle', 'developer', 'console'] }
|
||
}
|
||
]
|
||
},
|
||
|
||
// {
|
||
// path: '/error',
|
||
// component: Layout,
|
||
// redirect: 'noRedirect',
|
||
// name: 'ErrorPages',
|
||
// meta: {
|
||
// title: 'Error Pages',
|
||
// icon: '404'
|
||
// },
|
||
// children: [
|
||
// {
|
||
// path: '401',
|
||
// component: () => import('@/views/error-page/401.vue'),
|
||
// name: 'Page401',
|
||
// meta: { title: '401', noCache: true }
|
||
// },
|
||
// {
|
||
// path: '404',
|
||
// component: () => import('@/views/error-page/404.vue'),
|
||
// name: 'Page404',
|
||
// meta: { title: '404', noCache: true }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
{
|
||
path: '/message',
|
||
component: Layout,
|
||
children: [
|
||
{
|
||
path: 'ms',
|
||
component: () => import('@/views/Message/Message.vue'),
|
||
name: 'email',
|
||
meta: { title: '信息', icon: 'email', role: ['principle', 'developer', 'console'] }
|
||
}
|
||
]
|
||
},
|
||
|
||
{
|
||
path: '/examine',
|
||
component: Layout,
|
||
redirect: '/examine/export-examine',
|
||
name: 'examine',
|
||
meta: {
|
||
title: '申请和审批',
|
||
icon: 'excel'
|
||
},
|
||
children: [
|
||
{
|
||
path: 'submit-application',
|
||
component: () => import('@/views/examine/submit-application.vue'),
|
||
name: 'ExportExcel',
|
||
meta: { title: '提交申请' }
|
||
},
|
||
{
|
||
path: 'export-selected-examine',
|
||
component: () => import('@/views/examine/My-review.vue'),
|
||
name: 'MyReview',
|
||
meta: { title: '我的审批' }
|
||
},
|
||
{
|
||
path: 'search-record',
|
||
component: () => import('@/views/examine/search-records.vue'),
|
||
name: 'searchRecord',
|
||
meta: { title: '记录查询' }
|
||
}
|
||
]
|
||
},
|
||
|
||
// {
|
||
// path: '/zip',
|
||
// component: Layout,
|
||
// redirect: '/zip/download',
|
||
// name: 'Zip',
|
||
// meta: { alwaysShow: true, title: 'Zip', icon: 'zip' },
|
||
// children: [
|
||
// {
|
||
// path: 'download',
|
||
// component: () => import('@/views/zip/Message.vue'),
|
||
// name: 'ExportZip',
|
||
// meta: { title: 'Export Zip' }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// {
|
||
// path: '/pdf',
|
||
// component: Layout,
|
||
// redirect: '/pdf/index',
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/pdf/Message.vue'),
|
||
// name: 'PDF',
|
||
// meta: { title: 'PDF', icon: 'pdf' }
|
||
// }
|
||
// ]
|
||
// },
|
||
// {
|
||
// path: '/pdf/download',
|
||
// component: () => import('@/views/pdf/download.vue'),
|
||
// meta: { hidden: true }
|
||
// },
|
||
//
|
||
// {
|
||
// path: '/theme',
|
||
// component: Layout,
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/theme/Message.vue'),
|
||
// name: 'Theme',
|
||
// meta: { title: 'Theme', icon: 'theme' }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// {
|
||
// path: '/clipboard',
|
||
// component: Layout,
|
||
// children: [
|
||
// {
|
||
// path: 'index',
|
||
// component: () => import('@/views/clipboard/Message.vue'),
|
||
// name: 'ClipboardDemo',
|
||
// meta: { title: 'Clipboard', icon: 'clipboard' }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// {
|
||
// path: '/external-link',
|
||
// component: Layout,
|
||
// children: [
|
||
// {
|
||
// path: 'https://element-plus.midfar.com',
|
||
// meta: { title: 'External Link', icon: 'link' },
|
||
// redirect: ''
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// {
|
||
// path: '/my-demo',
|
||
// component: Layout,
|
||
// name: 'MyDemo',
|
||
// meta: {
|
||
// title: 'MyDemo',
|
||
// icon: 'component'
|
||
// },
|
||
// children: [
|
||
// {
|
||
// path: 'element-demo',
|
||
// component: () => import('@/views/mydemo/ElementDemo.vue'),
|
||
// name: 'ElementDemo',
|
||
// meta: { title: 'ElementDemo', icon: 'skill' }
|
||
// },
|
||
// {
|
||
// path: 'store-demo',
|
||
// component: () => import('@/views/mydemo/StoreDemo.vue'),
|
||
// name: 'StoreDemo',
|
||
// meta: { title: 'StoreDemo', icon: 'lock' }
|
||
// },
|
||
// {
|
||
// path: 'webSocket-demo',
|
||
// component: () => import('@/views/mydemo/WebSocketDemo.vue'),
|
||
// name: 'WebSocketDemo',
|
||
// meta: { title: 'WebSocketDemo', icon: 'lock' }
|
||
// }
|
||
// ]
|
||
// },
|
||
|
||
// 404 page must be placed at the end !!!
|
||
{ path: '/:pathMatch(.*)*', redirect: '/404', meta: { hidden: true }}
|
||
];
|
||
|
||
console.log('BASE_URL=', import.meta.env);
|
||
|
||
const createTheRouter = ():Router => createRouter({
|
||
// history: createWebHashHistory(import.meta.env.BASE_URL),
|
||
// 注意,如果要配置 HTML5 模式,则需要修改nginx配置,参考资料:
|
||
// https://router.vuejs.org/zh/guide/essentials/history-mode.html
|
||
history: createWebHistory(import.meta.env.BASE_URL),
|
||
scrollBehavior: () => ({ top: 0 }),
|
||
routes: constantRoutes
|
||
});
|
||
|
||
interface RouterPro extends Router {
|
||
matcher: unknown;
|
||
}
|
||
|
||
const router = createTheRouter() as RouterPro;
|
||
|
||
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
|
||
export function resetRouter() {
|
||
const newRouter = createTheRouter() as RouterPro;
|
||
router.matcher = newRouter.matcher; // reset router
|
||
}
|
||
|
||
export default router;
|