|
|
@@ -0,0 +1,44 @@
|
|
|
+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']
|
|
|
+
|
|
|
+export const useBreadCrumb = defineStore('breadCrumb', {
|
|
|
+ state: (): BreadCrumb => ({
|
|
|
+ routeList: JSON.parse(localStorage.getItem('routeList')) || []
|
|
|
+ }),
|
|
|
+ getters: {},
|
|
|
+ actions: {
|
|
|
+ setRouteList(toRoute: any, fromRoute: any) {
|
|
|
+ const index = this.routeList.findIndex((item) => item.label === toRoute.name)
|
|
|
+ if (index !== -1) {
|
|
|
+ this.routeList.splice(index + 1)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (toRoute.name && whiteList.includes(toRoute.name)) {
|
|
|
+ this.routeList.push({
|
|
|
+ label: 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))
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|