123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- 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<Element>) => {
- app.use(router)
- }
- export default router
|