import Storage from '@/common/utils/storage'
import { defineStore } from 'pinia'

export const selectStore = defineStore('select', {
  state: () => ({
    options: <any>{},
  }),
  actions: {
    save(data:any, type:string=''){  // 保存下拉数据到store
        return new Promise(resolve => {
            if(type){
                Object.assign(this.options, {
                    [type]: data
                })
            }
            resolve(data)
        })
    },
    clear(type:string=''){
        return new Promise(resolve => {
            if(type){
                delete this.options[type]
            }
            else {
                this.options = {}
            }
            resolve(type)
        })
    },
    clearAll(type:string=''){
        return new Promise(resolve => {
            this.options = {}
            resolve(type)
        })
    }
  }
})
