import { createRouter, createWebHashHistory } from 'vue-router' import type { RouteRecordRaw } from 'vue-router' import type { App } from 'vue' import { Layout, getParentLayout } from '@/utils/routerHelper' import { useI18n } from '@/hooks/web/useI18n' const { t } = useI18n() export const constantRouterMap: AppRouteRecordRaw[] = [ { path: '/', component: Layout, redirect: '/dashboard/workplace', name: 'Root', meta: { hidden: true } }, { path: '/redirect', component: Layout, name: 'Redirect', children: [ { path: '/redirect/:path(.*)', name: 'Redirect', component: () => import('@/views/Redirect/Redirect.vue'), meta: {} } ], meta: { hidden: true, noTagsView: true } }, { path: '/login', component: () => import('@/views/Login/Login.vue'), name: 'Login', meta: { hidden: true, title: t('router.login'), noTagsView: true } }, { path: '/404', component: () => import('@/views/Error/404.vue'), name: 'NoFind', meta: { hidden: true, title: '404', noTagsView: true } } ] export const asyncRouterMap: AppRouteRecordRaw[] = [ { path: '/dashboard', component: Layout, redirect: '/dashboard/workplace', name: 'Dashboard', meta: { title: t('router.dashboard'), icon: 'ant-design:dashboard-filled', alwaysShow: true }, children: [ { path: 'workplace', component: () => import('@/views/Dashboard/Workplace.vue'), name: 'Workplace', meta: { title: t('router.workplace'), noCache: true } } ] }, { path: '/manage', component: Layout, redirect: '/manage/news-page', name: 'Manage', meta: { title: '模块管理', icon: 'ep:menu', alwaysShow: true }, children: [ { path: 'news-page', component: () => import('@/views/Manage/News/NewsPage.vue'), name: 'NewsPage', meta: { title: '文案管理' } }, { path: 'news-add', component: () => import('@/views/Manage/News/NewsAdd.vue'), name: 'NewsAdd', meta: { title: '新增文案', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/news-page' } }, { path: 'news-edit', component: () => import('@/views/Manage/News/NewsEdit.vue'), name: 'NewsEdit', meta: { title: '编辑文案', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/news-page' } }, { path: 'news-detail', component: () => import('@/views/Manage/News/NewsDetail.vue'), name: 'NewsDetail', meta: { title: '文案详情', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/news-page' } }, { path: 'product-page', component: () => import('@/views/Manage/Product/ProductPage.vue'), name: 'ProductPage', meta: { title: '产品管理' } }, { path: 'product-add', component: () => import('@/views/Manage/Product/ProductAdd.vue'), name: 'ProductAdd', meta: { title: '新增产品', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/product-page' } }, { path: 'product-edit', component: () => import('@/views/Manage/Product/ProductEdit.vue'), name: 'ProductEdit', meta: { title: '编辑产品', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/product-page' } }, { path: 'product-detail', component: () => import('@/views/Manage/Product/ProductDetail.vue'), name: 'ProductDetail', meta: { title: '产品详情', noTagsView: true, noCache: true, hidden: true, canTo: true, activeMenu: '/manage/product-page' } }, { path: 'file-page', component: () => import('@/views/Manage/File/FilePage.vue'), name: 'FilePage', meta: { title: '文件管理' } }, { path: 'img-page', component: () => import('@/views/Manage/Img/ImgPage.vue'), name: 'ImgPage', meta: { title: '图片管理' } }, { path: 'company-page', component: () => import('@/views/Manage/Company/CompanyPage.vue'), name: 'CompanyPage', meta: { title: '公司信息管理' } } ] }, { path: '/authorization', component: Layout, redirect: '/authorization/user', name: 'Authorization', meta: { title: t('router.authorization'), icon: 'eos-icons:role-binding', alwaysShow: true }, children: [ // { // path: 'department', // component: () => import('@/views/Authorization/Department/Department.vue'), // name: 'Department', // meta: { // title: t('router.department') // } // }, { path: 'user', component: () => import('@/views/Authorization/User/User.vue'), name: 'User', meta: { title: t('router.user') } } // { // path: 'menu', // component: () => import('@/views/Authorization/Menu/Menu.vue'), // name: 'Menu', // meta: { // title: t('router.menuManagement') // } // }, // { // path: 'role', // component: () => import('@/views/Authorization/Role/Role.vue'), // name: 'Role', // meta: { // title: t('router.role') // } // }, // { // path: 'test', // component: () => import('@/views/Authorization/Test/Test.vue'), // name: 'Test', // meta: { // title: t('router.permission'), // permission: ['add', 'edit', 'delete'] // } // } ] } ] const router = createRouter({ history: createWebHashHistory(), strict: true, routes: constantRouterMap as RouteRecordRaw[], scrollBehavior: () => ({ left: 0, top: 0 }) }) export const resetRouter = (): void => { const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'] router.getRoutes().forEach((route) => { const { name } = route if (name && !resetWhiteNameList.includes(name as string)) { router.hasRoute(name) && router.removeRoute(name) } }) } export const setupRouter = (app: App) => { app.use(router) } export default router