
export const comNavStore = defineStore('main_com_nav', {
    state: () => {
        return {
            topNavList: [] as any, //loading控制,
            maxNavCount: 8,
            currentNav:'',
            defaultActive:''
        }
    },
    getters: {},
    actions: {
        addNavTarget(ev: any) {
            console.log("topNavList", this.topNavList,ev)
            this.currentNav = ev.path
            if (!this.topNavList.map((ele: any) => ele.path).includes(ev.path)) {
                this.topNavList.push(ev)
            }
            if (this.topNavList.length > this.maxNavCount) {
                this.topNavList.splice(0,1)
            }
        },
        deleteNavTarget(index: any) {
            if (this.topNavList.length > 0) {
                this.topNavList.splice(index, 1)
            }
            this.currentNav = this.topNavList[index]
        },
        clearTarget(val: any) {
            this.topNavList = []
        },
        setCurrentNav(ev:any){
            console.log("setCurrentNav00",ev)
            this.currentNav = ev
        } ,  
        setDefaultActive(ev:any){
            console.log("setCurrentNav")
            this.defaultActive = ev.path+'&&'+ev.title
        }

        
    },
    persist: {
        enabled: true, // 开启数据缓存
        strategies: [
            {
                // 自定义存储的 key，默认是 store.$id
                key: 'main_com_nav',
                storage: sessionStorage, //缓存模式 可选 localStorage sessionStorage
                // state 中的字段名，按组打包储存
                paths: ['topNavList','currentNav','defaultActive'] //需要缓存的字段 与 state中相关联
            }
        ]
    }
})

// [ { "title": "企业类型", "name": "configuration", "path": "/index/enterpriseTypeManage/enterpriseType" }, { "title": "企业类型", "path": "configuration" } ]
