breadCrumb.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ]
  20. export const useBreadCrumb = defineStore('breadCrumb', {
  21. state: (): BreadCrumb => ({
  22. routeList: JSON.parse(localStorage.getItem('routeList')) || []
  23. }),
  24. getters: {},
  25. actions: {
  26. setRouteList(toRoute: any) {
  27. const index = this.routeList.findIndex((item) => item.label === toRoute.name)
  28. if (index !== -1) {
  29. this.routeList.splice(index + 1)
  30. } else if (toRoute.name === 'Public Tracking Detail') {
  31. this.routeList = [
  32. {
  33. label: 'Public Tracking',
  34. path: '/public-tracking',
  35. query: ''
  36. },
  37. {
  38. label: 'Public Tracking Detail',
  39. path: '/public-tracking/detail',
  40. query: toRoute.query
  41. }
  42. ]
  43. } else if (toRoute.name === 'System Message Detail') {
  44. this.routeList = [
  45. {
  46. label: 'System Message',
  47. path: '/system-message',
  48. query: ''
  49. },
  50. {
  51. label: 'System Message Detail',
  52. path: '/system-message/detail',
  53. query: toRoute.query
  54. }
  55. ]
  56. } else if (toRoute.name === 'Shipment Detail') {
  57. this.routeList = [
  58. {
  59. label: 'System Settings',
  60. path: '/SystemSettings',
  61. query: ''
  62. },
  63. {
  64. label: 'Shipment Detail',
  65. path: '/shipment/detail',
  66. query: toRoute.query
  67. }
  68. ]
  69. } else if (toRoute.name && whiteList.includes(toRoute.name)) {
  70. this.routeList.push({
  71. label: toRoute?.meta?.breadName || toRoute.name,
  72. path: toRoute.path,
  73. query: toRoute.query
  74. })
  75. } else {
  76. this.routeList = [
  77. {
  78. label: toRoute.name,
  79. path: toRoute.path,
  80. query: toRoute.query
  81. }
  82. ]
  83. }
  84. localStorage.setItem('routeList', JSON.stringify(this.routeList))
  85. },
  86. getUpperRoute() {
  87. return this.routeList[this.routeList.length - 2]
  88. }
  89. }
  90. })