
import {ajaxGetDictItems} from '@/api/api';

import store from '@/store/index.js';
import Vue from 'vue';
/**
 * 获取字典数组
 * @param dictCode 字典Code
 * @return List<Map>
 */
export async function initDictOptions(dictCode) {
  if (!dictCode) {
    return '字典Code不能为空!';
  }
  //优先从缓存中读取字典配置
  if(getDictItemsFromCache(dictCode)){
    let res = {}
    res.result = getDictItemsFromCache(dictCode);
    res.success = true;
    return res;
  }
  //获取字典数组
  let res = await ajaxGetDictItems(dictCode);
  return res;
}

function getDictItemsFromCache(dictCode) {
  if (store.state.dicts != null && store.state.dicts[dictCode]) {
    let dictItems = store.state.dicts[dictCode];
    return dictItems;
  }
}