/**
 * 组件缓存
 */
import { defineStore } from "pinia";

export const useCachedViewsStore=defineStore('cachedViews',{
    state:()=>{
        return {
            cachesList:[]
        }
    },
    actions:{
        // 将组件加入缓存
        addCaches(name){
            if(!this.cachesList.includes(name)){
                console.log('添加缓存',name);
                this.cachesList.push(name)
            }
        },
        //将组件移除缓存
        removeCaches(name){
            return new Promise((resolve)=>{
                if(name===-1){
                    this.cachesList=[]
                }else{
                    const index=this.cachesList.indexOf(name)
                    if(index!==-1){
                        console.log('移除缓存',name);
                        this.cachesList.splice(index,1)
                    }
                }
                resolve(true)
            })
        }
    }
})