import { defineStore } from 'pinia'
import { ITabe } from './type/index'
//定义state类型
export type TabsState = {
    tabsList: Array<ITabe>
    deleteTable: string
}
//定义store
export const tabStore = defineStore('tabStore', {
    state: (): TabsState => {
        return {
            tabsList: [],
            deleteTable: ""
        }
    },
    actions: {
        addTabe(tab: ITabe) {
            //判断是否已经存在，如果不存在，才放入
            if (this.tabsList.some(item => item.path === tab.path)) return;
            this.tabsList.push(tab);
        },
        deleteCurrentTabel(tab: string) {
            this.deleteTable = tab
        },
        resetTabsList() {
            this.tabsList = [{path:"/dashboard", title:"首页", name:"dashboard"}]
        }
    },
    getters: {
        getTabs(state) {
            return state.tabsList;
        },
        getDeleteTable(state) {
            return state.deleteTable;
        },
    }
})