import { getAllChildren } from "@/api/system"; let cache = {} export const refresh = () => { getAllChildren() } export const getDict = (enumid, refresh = false) => { if(refresh || (! cache[enumid])) { return getAllChildren({ enumid: enumid, isQueryFristNode: false, }).then(resp => { const list = resp.data || [] cache[enumid] = list return Promise.resolve(cache[enumid]) }) }else { return Promise.resolve(cache[enumid]) } } export const getDict2 = (enumid, firstNode = false, refresh = false) => { const key = `${enumid}_${firstNode}` if(refresh || (! cache[key])) { return getAllChildren({ enumid: enumid, isQueryFristNode: firstNode, }).then(resp => { const list = resp.data || [] cache[key] = list return Promise.resolve(cache[key]) }) }else { return Promise.resolve(cache[key]) } } export const dictNameByParentId = (parentId, enumid, def = '', forceRefresh = false) => { return getDict(parentId, forceRefresh).then(list => { const name = list.find(d => d.enumid == enumid)?.enumname return name ? name : def }) } export const dictNameByParentIdBatch = (dataList, parentId, field, def = '', forceRefresh = false) => { const map = {} dataList.forEach(d => { map[d[field]] = def }) return getDict(parentId, forceRefresh).then(list => { Object.keys(map).forEach(key => { const name = list.find(d => d.enumid == key)?.enumname map[key] = name ? name : def }) return map }) }