mallBackend/src/store/comNav.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-12-04 19:10:26 +08:00
2023-12-03 15:48:43 +08:00
export const comNavStore = defineStore('main_com_nav', {
state: () => {
return {
topNavList: [] as any, //loading控制,
2023-12-05 16:51:34 +08:00
maxNavCount: 8,
currentNav:''
2023-12-03 15:48:43 +08:00
}
},
getters: {},
actions: {
2023-12-04 19:10:26 +08:00
addNavTarget(ev: any) {
2023-12-05 16:51:34 +08:00
console.log("topNavList", this.topNavList,ev)
this.currentNav = ev.path
2023-12-04 19:10:26 +08:00
if (!this.topNavList.map((ele: any) => ele.path).includes(ev.path)) {
2023-12-03 15:48:43 +08:00
this.topNavList.push(ev)
2023-12-04 19:10:26 +08:00
}
if (this.topNavList.length > this.maxNavCount) {
this.topNavList.splice(0,1)
}
2023-12-03 15:48:43 +08:00
},
2023-12-04 19:10:26 +08:00
deleteNavTarget(index: any) {
if (this.topNavList.length > 0) {
this.topNavList.splice(index, 1)
}
2023-12-03 15:48:43 +08:00
},
clearTarget(val: any) {
2023-12-04 19:10:26 +08:00
this.topNavList = []
2023-12-05 16:51:34 +08:00
},
setCurrentNav(ev:any){
console.log("setCurrentNav")
this.currentNav = ev
2023-12-03 15:48:43 +08:00
}
},
persist: {
enabled: true, // 开启数据缓存
strategies: [
{
// 自定义存储的 key默认是 store.$id
key: 'main_com_nav',
storage: localStorage, //缓存模式 可选 localStorage sessionStorage
// state 中的字段名,按组打包储存
paths: ['topNavList'] //需要缓存的字段 与 state中相关联
}
]
}
})