dict.js 718 B

123456789101112131415161718192021222324
  1. import useDictStore from '@/store/modules/dict'
  2. import { getDicts } from '@/api/system/dict/data'
  3. /**
  4. * 获取字典数据
  5. */
  6. export function useDict(...args) {
  7. const res = ref({});
  8. return (() => {
  9. args.forEach((dictType, index) => {
  10. res.value[dictType] = [];
  11. const dicts = useDictStore().getDict(dictType);
  12. if (dicts) {
  13. res.value[dictType] = dicts;
  14. } else {
  15. getDicts(dictType).then(resp => {
  16. res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
  17. useDictStore().setDict(dictType, res.value[dictType]);
  18. })
  19. }
  20. })
  21. return toRefs(res.value);
  22. })()
  23. }