index.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import type { RouteRecordRaw } from 'vue-router'
  3. import type { App } from 'vue'
  4. import { Layout, getParentLayout } from '@/utils/routerHelper'
  5. import { useI18n } from '@/hooks/web/useI18n'
  6. const { t } = useI18n()
  7. export const constantRouterMap: AppRouteRecordRaw[] = [
  8. {
  9. path: '/',
  10. component: Layout,
  11. redirect: '/dashboard/workplace',
  12. name: 'Root',
  13. meta: {
  14. hidden: true
  15. }
  16. },
  17. {
  18. path: '/redirect',
  19. component: Layout,
  20. name: 'Redirect',
  21. children: [
  22. {
  23. path: '/redirect/:path(.*)',
  24. name: 'Redirect',
  25. component: () => import('@/views/Redirect/Redirect.vue'),
  26. meta: {}
  27. }
  28. ],
  29. meta: {
  30. hidden: true,
  31. noTagsView: true
  32. }
  33. },
  34. {
  35. path: '/login',
  36. component: () => import('@/views/Login/Login.vue'),
  37. name: 'Login',
  38. meta: {
  39. hidden: true,
  40. title: t('router.login'),
  41. noTagsView: true
  42. }
  43. },
  44. {
  45. path: '/404',
  46. component: () => import('@/views/Error/404.vue'),
  47. name: 'NoFind',
  48. meta: {
  49. hidden: true,
  50. title: '404',
  51. noTagsView: true
  52. }
  53. }
  54. ]
  55. export const asyncRouterMap: AppRouteRecordRaw[] = [
  56. {
  57. path: '/dashboard',
  58. component: Layout,
  59. redirect: '/dashboard/workplace',
  60. name: 'Dashboard',
  61. meta: {
  62. title: t('router.dashboard'),
  63. icon: 'ant-design:dashboard-filled',
  64. alwaysShow: true
  65. },
  66. children: [
  67. {
  68. path: 'workplace',
  69. component: () => import('@/views/Dashboard/Workplace.vue'),
  70. name: 'Workplace',
  71. meta: {
  72. title: t('router.workplace'),
  73. noCache: true
  74. }
  75. }
  76. ]
  77. },
  78. {
  79. path: '/manage',
  80. component: Layout,
  81. redirect: '/manage/news-page',
  82. name: 'Manage',
  83. meta: {
  84. title: '模块管理',
  85. icon: 'ep:menu',
  86. alwaysShow: true
  87. },
  88. children: [
  89. {
  90. path: 'news-page',
  91. component: () => import('@/views/Manage/News/NewsPage.vue'),
  92. name: 'NewsPage',
  93. meta: {
  94. title: '文案管理'
  95. }
  96. },
  97. {
  98. path: 'news-add',
  99. component: () => import('@/views/Manage/News/NewsAdd.vue'),
  100. name: 'NewsAdd',
  101. meta: {
  102. title: '新增文案',
  103. noTagsView: true,
  104. noCache: true,
  105. hidden: true,
  106. canTo: true,
  107. activeMenu: '/manage/news-page'
  108. }
  109. },
  110. {
  111. path: 'news-edit',
  112. component: () => import('@/views/Manage/News/NewsEdit.vue'),
  113. name: 'NewsEdit',
  114. meta: {
  115. title: '编辑文案',
  116. noTagsView: true,
  117. noCache: true,
  118. hidden: true,
  119. canTo: true,
  120. activeMenu: '/manage/news-page'
  121. }
  122. },
  123. {
  124. path: 'news-detail',
  125. component: () => import('@/views/Manage/News/NewsDetail.vue'),
  126. name: 'NewsDetail',
  127. meta: {
  128. title: '文案详情',
  129. noTagsView: true,
  130. noCache: true,
  131. hidden: true,
  132. canTo: true,
  133. activeMenu: '/manage/news-page'
  134. }
  135. },
  136. {
  137. path: 'product-page',
  138. component: () => import('@/views/Manage/Product/ProductPage.vue'),
  139. name: 'ProductPage',
  140. meta: {
  141. title: '产品管理'
  142. }
  143. },
  144. {
  145. path: 'product-add',
  146. component: () => import('@/views/Manage/Product/ProductAdd.vue'),
  147. name: 'ProductAdd',
  148. meta: {
  149. title: '新增产品',
  150. noTagsView: true,
  151. noCache: true,
  152. hidden: true,
  153. canTo: true,
  154. activeMenu: '/manage/product-page'
  155. }
  156. },
  157. {
  158. path: 'product-edit',
  159. component: () => import('@/views/Manage/Product/ProductEdit.vue'),
  160. name: 'ProductEdit',
  161. meta: {
  162. title: '编辑产品',
  163. noTagsView: true,
  164. noCache: true,
  165. hidden: true,
  166. canTo: true,
  167. activeMenu: '/manage/product-page'
  168. }
  169. },
  170. {
  171. path: 'product-detail',
  172. component: () => import('@/views/Manage/Product/ProductDetail.vue'),
  173. name: 'ProductDetail',
  174. meta: {
  175. title: '产品详情',
  176. noTagsView: true,
  177. noCache: true,
  178. hidden: true,
  179. canTo: true,
  180. activeMenu: '/manage/product-page'
  181. }
  182. },
  183. {
  184. path: 'file-page',
  185. component: () => import('@/views/Manage/File/FilePage.vue'),
  186. name: 'FilePage',
  187. meta: {
  188. title: '文件管理'
  189. }
  190. },
  191. {
  192. path: 'img-page',
  193. component: () => import('@/views/Manage/Img/ImgPage.vue'),
  194. name: 'ImgPage',
  195. meta: {
  196. title: '图片管理'
  197. }
  198. },
  199. {
  200. path: 'company-page',
  201. component: () => import('@/views/Manage/Company/CompanyPage.vue'),
  202. name: 'CompanyPage',
  203. meta: {
  204. title: '公司信息管理'
  205. }
  206. }
  207. ]
  208. },
  209. {
  210. path: '/authorization',
  211. component: Layout,
  212. redirect: '/authorization/user',
  213. name: 'Authorization',
  214. meta: {
  215. title: t('router.authorization'),
  216. icon: 'eos-icons:role-binding',
  217. alwaysShow: true
  218. },
  219. children: [
  220. // {
  221. // path: 'department',
  222. // component: () => import('@/views/Authorization/Department/Department.vue'),
  223. // name: 'Department',
  224. // meta: {
  225. // title: t('router.department')
  226. // }
  227. // },
  228. {
  229. path: 'user',
  230. component: () => import('@/views/Authorization/User/User.vue'),
  231. name: 'User',
  232. meta: {
  233. title: t('router.user')
  234. }
  235. }
  236. // {
  237. // path: 'menu',
  238. // component: () => import('@/views/Authorization/Menu/Menu.vue'),
  239. // name: 'Menu',
  240. // meta: {
  241. // title: t('router.menuManagement')
  242. // }
  243. // },
  244. // {
  245. // path: 'role',
  246. // component: () => import('@/views/Authorization/Role/Role.vue'),
  247. // name: 'Role',
  248. // meta: {
  249. // title: t('router.role')
  250. // }
  251. // },
  252. // {
  253. // path: 'test',
  254. // component: () => import('@/views/Authorization/Test/Test.vue'),
  255. // name: 'Test',
  256. // meta: {
  257. // title: t('router.permission'),
  258. // permission: ['add', 'edit', 'delete']
  259. // }
  260. // }
  261. ]
  262. }
  263. ]
  264. const router = createRouter({
  265. history: createWebHashHistory(),
  266. strict: true,
  267. routes: constantRouterMap as RouteRecordRaw[],
  268. scrollBehavior: () => ({ left: 0, top: 0 })
  269. })
  270. export const resetRouter = (): void => {
  271. const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
  272. router.getRoutes().forEach((route) => {
  273. const { name } = route
  274. if (name && !resetWhiteNameList.includes(name as string)) {
  275. router.hasRoute(name) && router.removeRoute(name)
  276. }
  277. })
  278. }
  279. export const setupRouter = (app: App<Element>) => {
  280. app.use(router)
  281. }
  282. export default router