routes.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. export const constantRoutes = [
  2. {
  3. path: '/login',
  4. meta: { title: '登录' },
  5. type: 'sys',
  6. label: '',
  7. icon: 'el-icon-star-on',
  8. component: () => import('@/views/login/index.vue'),
  9. hidden: true
  10. },
  11. {
  12. path: '/gislogin',
  13. meta: { title: '登录' },
  14. type: 'sys',
  15. label: '',
  16. icon: 'el-icon-star-on',
  17. component: () => import('@/views/gislogin/index.vue'),
  18. hidden: true
  19. },
  20. {
  21. path: '/404',
  22. hidden: true,
  23. component: () => import('@/views/404.vue')
  24. }
  25. ]
  26. // 404
  27. export const ERROR = [
  28. {
  29. path: '*',
  30. redirect: '/404',
  31. hidden: true
  32. }
  33. ]
  34. import _import from './_import' // 获取组件的方法
  35. /**
  36. * 生成路由
  37. * @param {Array} routerlist 格式化路由
  38. * @returns
  39. */
  40. export function packageRouter(routerlist) {
  41. function extractIcon(icon) {
  42. let result
  43. if (icon !== null && icon) {
  44. result = icon.substr(9)
  45. } else result = ''
  46. return `iconfont ${result}`
  47. }
  48. const router: any[] = []
  49. routerlist.forEach((e) => {
  50. if (e.statusFlag == '1') {
  51. const meta = () => {
  52. let temp = {}
  53. try {
  54. temp = JSON.parse(e.meta || '{}')
  55. } catch (error) {
  56. console.log({ meta: e.meta, error })
  57. }
  58. return temp
  59. }
  60. let e_new = {
  61. path: e.path || '',
  62. name: e.name,
  63. id: e.pathId,
  64. type: e.type,
  65. label: e.label,
  66. icon: extractIcon(e.icon),
  67. widgetid: e.widgetid || '',
  68. component: _import(e.component),
  69. meta: meta(),
  70. parentPathid: e.parentPathid || ''
  71. }
  72. if (e.childrens && e.childrens.length > 0) {
  73. e_new = Object.assign({}, e_new, {
  74. children: packageRouter(e.childrens)
  75. })
  76. }
  77. if (e.redirect) {
  78. e_new = Object.assign({}, e_new, { redirect: e.redirect })
  79. }
  80. if (e.path === '/map') {
  81. e_new = Object.assign({}, e_new, { hidden: true })
  82. }
  83. router.push(e_new)
  84. }
  85. })
  86. return router
  87. }