zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as api from '@/api';
 
const dictCache = {};
 
const useDictMap = (groups) => {
  const dictMapEntity = reactive({});
  const dictMapCode = reactive({});
 
  onMounted(async () => {
    const res = await Promise.all(groups.filter(e => !dictCache[e]).map(key => api.entity.getOldEntitySet({
      dataName: 'dictitem', filter: " parent_id = '" + key + "'"
    })));
 
    groups.filter(e => !dictCache[e]).forEach((e, i) => {
      dictCache[e] = res[i].data.entityset;
    });
 
    groups.forEach(e => {
      dictMapEntity[e] = dictCache[e];
      dictMapCode[e] = Object.fromEntries(dictCache[e].map(({code, value}) => [code, value]));
    });
  })
 
  return [dictMapEntity, dictMapCode];
}
 
export default {useDictMap};