breadCrumb.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { defineStore } from 'pinia'
  2. import { collapseTextChangeRangesAcrossMultipleVersions } from 'typescript'
  3. interface Route {
  4. label: string
  5. path: string
  6. query?: string
  7. }
  8. interface BreadCrumb {
  9. routeList: Route[]
  10. }
  11. // 需要添加多级菜单的页面,值为route的name
  12. const whiteList = [
  13. 'Booking Detail',
  14. 'Tracking Detail',
  15. 'Add VGM',
  16. 'Public Tracking Detail',
  17. 'Create New Rule',
  18. 'System Message Detail',
  19. 'Destination Delivery',
  20. 'Configurations',
  21. 'Destination Create New Rule',
  22. ]
  23. export const useBreadCrumb = defineStore('breadCrumb', {
  24. state: (): BreadCrumb => ({
  25. routeList: JSON.parse(localStorage.getItem('routeList')) || []
  26. }),
  27. getters: {},
  28. actions: {
  29. setRouteList(toRoute: any) {
  30. const index = this.routeList.findIndex((item) => item.label === toRoute.name)
  31. if (index !== -1) {
  32. this.routeList.splice(index + 1)
  33. if (toRoute.name === 'Destination Delivery') {
  34. this.routeList = [
  35. {
  36. label: 'Destination Delivery',
  37. path: '/booking',
  38. query: ''
  39. },
  40. {
  41. label: 'Configurations',
  42. path: '/Booking/DestinationDelivery',
  43. query: toRoute.query
  44. }
  45. ]
  46. }
  47. } else if (toRoute.name === 'Public Tracking Detail') {
  48. this.routeList = [
  49. {
  50. label: 'Public Tracking',
  51. path: '/public-tracking',
  52. query: ''
  53. },
  54. {
  55. label: 'Public Tracking Detail',
  56. path: '/public-tracking/detail',
  57. query: toRoute.query
  58. }
  59. ]
  60. } else if (toRoute.name === 'System Message Detail') {
  61. this.routeList = [
  62. {
  63. label: 'System Message',
  64. path: '/system-message',
  65. query: ''
  66. },
  67. {
  68. label: 'System Message Detail',
  69. path: '/system-message/detail',
  70. query: toRoute.query
  71. }
  72. ]
  73. } else if (toRoute.name === 'Shipment Detail') {
  74. this.routeList = [
  75. {
  76. label: 'System Settings',
  77. path: '/SystemSettings',
  78. query: ''
  79. },
  80. {
  81. label: 'Shipment Detail',
  82. path: '/shipment/detail',
  83. query: toRoute.query
  84. }
  85. ]
  86. } else if (toRoute.name === 'Modify Booking') {
  87. this.routeList = [
  88. {
  89. label: 'Destination Delivery',
  90. path: '/destination-delivery',
  91. query: ''
  92. },
  93. {
  94. label: 'Modify Booking',
  95. path: '/destination-delivery/modify-booking',
  96. query: toRoute.query
  97. }
  98. ]
  99. } else if (toRoute.name === 'Configurations') {
  100. this.routeList = [
  101. {
  102. label: 'Destination Delivery',
  103. path: '/booking',
  104. query: ''
  105. },
  106. {
  107. label: 'Configurations',
  108. path: '/Booking/DestinationDelivery',
  109. query: toRoute.query
  110. }
  111. ]
  112. } else if (toRoute.name === 'Destination Create New Rule') {
  113. this.routeList = [
  114. {
  115. label: 'Destination Delivery',
  116. path: '/booking',
  117. query: ''
  118. },
  119. {
  120. label: 'Configurations',
  121. path: '/Booking/DestinationDelivery',
  122. query: ''
  123. },
  124. {
  125. label: 'Create New Rule',
  126. path: '/Booking/DestinationDelivery/CreateNewRule',
  127. query: toRoute.query
  128. }
  129. ]
  130. } else if (toRoute.name && whiteList.includes(toRoute.name)) {
  131. this.routeList.push({
  132. label: toRoute?.meta?.breadName || toRoute.name,
  133. path: toRoute.path,
  134. query: toRoute.query
  135. })
  136. } else {
  137. this.routeList = [
  138. {
  139. label: toRoute.name,
  140. path: toRoute.path,
  141. query: toRoute.query
  142. }
  143. ]
  144. }
  145. localStorage.setItem('routeList', JSON.stringify(this.routeList))
  146. },
  147. getUpperRoute() {
  148. return this.routeList[this.routeList.length - 2]
  149. }
  150. }
  151. })