import { defineStore } from 'pinia' export const useLayoutStore = defineStore('layout', { state: () => ({ isAddRoute: false, // 是否添加过路由 menuList: [], // 菜单列表 menuActivePath: '/main', // 默认选中菜单 / tab menuIsCollapse: false, // 菜单折叠状态 tagsList: [] // tags标签栏列表 }), actions: { /* 设置选中菜单 */ setMenuActivePathAction(path: string) { this.menuActivePath = path }, /* 设置tags列表 */ setTagsListAction(item: any) { /* tags列表去重 */ const isExist = this.tagsList.some((tabItem: any) => { return tabItem.path === item.path }) if (!isExist) { // 不存在 ;(this.tagsList as any).push(item) } } }, persist: { key: 'layout', storage: window.sessionStorage, paths: ['menuList', 'menuActivePath', 'menuIsCollapse', 'tagsList'] } })