/**
 * ruoyi字典数据仓库
 */
import { defineStore } from 'pinia'

import { getConfigKey } from '@/api/system/config'

import { ref } from 'vue'
/**
 * 授权仓库
 */
export const useConfigStore = defineStore('useConfigStore', {
  state: () => {
    return {
		config:{}
    }
  },
  //计算字段
  getters: {
	
  },
  //方法
  actions: {
	load(...args) {
		const res = ref({});
		return (() => {
		 args.forEach((key, index) => {
		   if (this.config[key]) {
			 	res.value[key] = this.config[key];
		   } else {
        getConfigKey(key).then(resp => {
			  this.config[key] = resp.msg;
			  res.value[key] = this.config[key];
			 })
		   }
		 })
		 return res.value;
		})()
	},
	get(key) {
		return this.load(key)[key];
	},
  asyncData(key) {
		return new Promise((resolve,reject)=>{
			if (this.config[key]) {
				resolve(this.config[key]);
			}else{
				getConfigKey(key).then(resp => {
					this.config[key] = resp.msg;
					resolve(this.config[key]);
				 }).catch(e=>{
					reject(e);
				 })
			}
		})
	}
	
	
	
	
  },
  unistorage: false // 开启后对 state 的数据读写都将持久化

})