breadCrumb.ts 4.4 KB

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