breadCrumb.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. '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. ]
  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 === 'Configurations') {
  34. this.routeList = [
  35. {
  36. label: 'Destination Delivery',
  37. path: '/destination-delivery',
  38. query: ''
  39. },
  40. {
  41. label: 'Configurations',
  42. path: '/destination-delivery/ConfiguRations',
  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 === 'Destination Create New Rule') {
  100. let label = ''
  101. if (toRoute.query.a != undefined) {
  102. label = 'Modify Rule'
  103. } else {
  104. label = 'Create New Rule'
  105. }
  106. this.routeList = [
  107. {
  108. label: 'Destination Delivery',
  109. path: '/destination-delivery',
  110. query: ''
  111. },
  112. {
  113. label: 'Configurations',
  114. path: '/destination-delivery/ConfiguRations',
  115. query: ''
  116. },
  117. {
  118. label: label,
  119. path: '/destination-delivery/CreateNewRule',
  120. query: toRoute.query
  121. }
  122. ]
  123. } else if (toRoute.name === 'Create New Booking') {
  124. let label = ''
  125. if (toRoute.query.a != undefined) {
  126. label = 'Modify Booking'
  127. } else {
  128. label = 'Create New Booking'
  129. }
  130. this.routeList = [
  131. {
  132. label: 'Destination Delivery',
  133. path: '/destination-delivery',
  134. query: ''
  135. },
  136. {
  137. label: label,
  138. path: '/destination-delivery/CreateNewBooking',
  139. query: toRoute.query
  140. }
  141. ]
  142. } else if (toRoute.name && whiteList.includes(toRoute.name)) {
  143. this.routeList.push({
  144. label: toRoute?.meta?.breadName || toRoute.name,
  145. path: toRoute.path,
  146. query: toRoute.query
  147. })
  148. } else {
  149. this.routeList = [
  150. {
  151. label: toRoute.name,
  152. path: toRoute.path,
  153. query: toRoute.query
  154. }
  155. ]
  156. }
  157. localStorage.setItem('routeList', JSON.stringify(this.routeList))
  158. },
  159. getUpperRoute() {
  160. return this.routeList[this.routeList.length - 2]
  161. }
  162. }
  163. })