UNPKG

@jecloud/utils

Version:

JECloud 工具库

1 lines 1.54 kB
import{cloneDeep as e,isEmpty as t}from"lodash-es";import{loadDDItemByCode as n,loadDDItemByCodes as o,findDDAsyncNodes as r,loadDDItemByCode4Tree as a,initDDData as D}from"./api/dictionary";export{r as findDDAsyncNodes,a as loadDDItemByCode4Tree};export var ddCache=new Map;export var ddItemCache=new Map;export var DDType=Object.freeze({LIST:"LIST",TREE:"TREE",DYNA_TREE:"DYNA_TREE",SQL:"SQL",SQL_TREE:"SQL_TREE",CUSTOM:"CUSTOM"});export function loadDDItemByCode(e,o){return t(o)&&ddItemCache.has(e)?Promise.resolve(getDDItemCache(e)):n({code:e,querys:o}).then((function(n){return t(o)&&ddItemCache.set(e,n),getDDItemCache(e)}))}export function loadDDItemByCodes(e){var t=e.filter((function(e){return!ddItemCache.has(e)}));return t.length?o({codes:t}).then((function(e){Object.keys(e).forEach((function(t){ddItemCache.set(t,e[t])}))})):Promise.resolve()}export function getDDItemCache(t){return e(ddItemCache.get(t))}export function getDDItemInfo(e,t){var n=ddItemCache.get(e);return null==n?void 0:n.find((function(e){return e.code===t}))}export function getDDCache(t){return e(ddCache.get(t))}export function toDDItemText(e,t){var n=ddItemCache.get(e);return n&&t?t.split(",").map((function(e){var t;return null===(t=n.find((function(t){return t.code===e})))||void 0===t?void 0:t.text})).join(","):t}export function initDDData(){return ddCache.clear(),D().then((function(e){e.forEach((function(e){ddCache.set(e.DICTIONARY_DDCODE,{id:e.JE_CORE_DICTIONARY_ID,code:e.DICTIONARY_DDCODE,name:e.DICTIONARY_DDNAME,type:e.DICTIONARY_DDTYPE})}))}))}