import { getDictionary } from "@/api/system/dict";
import { getStore, setStore } from '@/util/store'

export const getDictValue = (params) => {
  return new Promise((resolve, reject) => {
    let { code } = params;
    let data = getStore({name: code})
    if (data) {
      resolve(data);
    }else{
      getDictionary(params).then((res => {
        let obj = {};
        res.data.data.forEach(element => {
          obj[element.dictKey] = element.dictValue;
        });
        setStore({
          name: code,
          content: obj,
          type:true,//sessionStorage
        });
        resolve(obj);
      })).catch(error => {
        reject(error)
      })
    }
  })
}