| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import { defineStore } from 'pinia'
- interface Route {
- label: string
- path: string
- query?: string
- }
- interface BreadCrumb {
- routeList: Route[]
- }
- // 需要添加多级菜单的页面,值为route的name
- const whiteList = [
- 'Booking Detail',
- 'Tracking Detail',
- 'Add VGM',
- 'Public Tracking Detail',
- 'Create New Rule',
- 'System Message Detail',
- 'Configurations',
- 'Create New Booking',
- 'Destination Create New Rule',
- ]
- export const useBreadCrumb = defineStore('breadCrumb', {
- state: (): BreadCrumb => ({
- routeList: JSON.parse(localStorage.getItem('routeList')) || []
- }),
- getters: {},
- actions: {
- setRouteList(toRoute: any) {
- const index = this.routeList.findIndex((item) => item.label === toRoute.name)
- if (index !== -1) {
- this.routeList.splice(index + 1)
- if (toRoute.name === 'Configurations') {
- this.routeList = [
- {
- label: 'Destination Delivery',
- path: '/destination-delivery',
- query: ''
- },
- {
- label: 'Configurations',
- path: '/destination-delivery/ConfiguRations',
- query: toRoute.query
- }
- ]
- }
- } else if (toRoute.name === 'Public Tracking Detail') {
- this.routeList = [
- {
- label: 'Public Tracking',
- path: '/public-tracking',
- query: ''
- },
- {
- label: 'Public Tracking Detail',
- path: '/public-tracking/detail',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name === 'System Message Detail') {
- this.routeList = [
- {
- label: 'System Message',
- path: '/system-message',
- query: ''
- },
- {
- label: 'System Message Detail',
- path: '/system-message/detail',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name === 'Shipment Detail') {
- this.routeList = [
- {
- label: 'System Settings',
- path: '/SystemSettings',
- query: ''
- },
- {
- label: 'Shipment Detail',
- path: '/shipment/detail',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name === 'Modify Booking') {
- this.routeList = [
- {
- label: 'Destination Delivery',
- path: '/destination-delivery',
- query: ''
- },
- {
- label: 'Modify Booking',
- path: '/destination-delivery/modify-booking',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name === 'Destination Create New Rule') {
- let label = ''
- if(toRoute.query.a != undefined) {
- label = 'Modify Rule'
- } else {
- label = 'Create New Rule'
- }
- this.routeList = [
- {
- label: 'Destination Delivery',
- path: '/destination-delivery',
- query: ''
- },
- {
- label: 'Configurations',
- path: '/destination-delivery/ConfiguRations',
- query: ''
- },
- {
- label: label,
- path: '/destination-delivery/CreateNewRule',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name === 'Create New Booking') {let label = ''
- if(toRoute.query.a != undefined) {
- label = 'Modify Booking'
- } else {
- label = 'Create New Booking'
- }
- this.routeList = [
- {
- label: 'Destination Delivery',
- path: '/destination-delivery',
- query: ''
- },
- {
- label: label,
- path: '/destination-delivery/CreateNewBooking',
- query: toRoute.query
- }
- ]
- } else if (toRoute.name && whiteList.includes(toRoute.name)) {
- this.routeList.push({
- label: toRoute?.meta?.breadName || toRoute.name,
- path: toRoute.path,
- query: toRoute.query
- })
- } else {
- this.routeList = [
- {
- label: toRoute.name,
- path: toRoute.path,
- query: toRoute.query
- }
- ]
- }
- localStorage.setItem('routeList', JSON.stringify(this.routeList))
- },
- getUpperRoute() {
- return this.routeList[this.routeList.length - 2]
- }
- }
- })
|