breadCrumb.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { defineStore } from 'pinia'
  2. interface Route {
  3. breadName: string
  4. path: string
  5. query?: string
  6. }
  7. interface BreadCrumb {
  8. routeList: Route[]
  9. }
  10. // 需要添加多级菜单的页面,值为route的name
  11. const whiteList = [
  12. 'Booking Detail',
  13. 'Tracking Detail',
  14. 'Tracking Download Attachment',
  15. 'Add VGM',
  16. 'Public Tracking Detail',
  17. 'Create New Rule',
  18. 'System Message Detail',
  19. 'Configurations',
  20. 'Create New Booking',
  21. 'Destination Create New Rule',
  22. 'Create Report Template',
  23. 'Report Schedule',
  24. 'Report Detail',
  25. 'Modify Booking',
  26. 'System Message Detail',
  27. 'Public Tracking Detail',
  28. 'Configurations'
  29. ]
  30. export const useBreadCrumb = defineStore('breadCrumb', {
  31. state: (): BreadCrumb => ({
  32. routeList: JSON.parse(localStorage.getItem('routeList')) || []
  33. }),
  34. getters: {},
  35. actions: {
  36. setRouteList(toRoute: any) {
  37. const index = this.routeList.findIndex((item) => item.label === toRoute.name)
  38. // 返回之前的路由时,删除之后的所有路由
  39. if (index !== -1) {
  40. this.routeList.splice(index + 1)
  41. return
  42. }
  43. if (toRoute.name === 'Destination Create New Rule') {
  44. let breadName = ''
  45. if (toRoute.query.a != undefined) {
  46. breadName = 'Modify Rule'
  47. } else {
  48. breadName = 'Create New Rule'
  49. }
  50. this.routeList = [
  51. {
  52. breadName: 'Destination Delivery',
  53. label: 'Destination Delivery',
  54. path: '/destination-delivery',
  55. query: ''
  56. },
  57. {
  58. breadName: 'Configurations',
  59. label: 'Configurations',
  60. path: '/destination-delivery/configurations',
  61. query: ''
  62. },
  63. {
  64. breadName: breadName,
  65. label: toRoute.name,
  66. path: '/destination-delivery/create-new-rule',
  67. query: toRoute.query
  68. }
  69. ]
  70. } else if (toRoute.name === 'Create New Booking') {
  71. let breadName = ''
  72. if (toRoute.query.a != undefined) {
  73. breadName = 'Modify Booking'
  74. } else {
  75. breadName = 'Create New Booking'
  76. }
  77. this.routeList = [
  78. {
  79. breadName: 'Destination Delivery',
  80. label: 'Destination Delivery',
  81. path: '/destination-delivery',
  82. query: ''
  83. },
  84. {
  85. breadName: breadName,
  86. label: toRoute.name,
  87. path: '/destination-delivery/create-new-booking',
  88. query: toRoute.query
  89. }
  90. ]
  91. } else if (toRoute.name && whiteList.includes(toRoute.name)) {
  92. this.routeList.push({
  93. breadName: toRoute?.meta?.breadName || toRoute.name,
  94. label: toRoute.name,
  95. path: toRoute.path,
  96. query: toRoute.query
  97. })
  98. } else {
  99. this.routeList = [
  100. {
  101. label: toRoute.name,
  102. breadName: toRoute?.meta?.breadName || toRoute.name,
  103. path: toRoute.path,
  104. query: toRoute.query
  105. }
  106. ]
  107. }
  108. localStorage.setItem('routeList', JSON.stringify(this.routeList))
  109. },
  110. getUpperRoute() {
  111. return this.routeList[this.routeList.length - 2]
  112. }
  113. }
  114. })