dict.js 730 B

12345678910111213141516171819202122232425
  1. import { getDicts } from '@/api/system/dict.js';
  2. import {ref,toRefs} from 'vue'
  3. function setDict(_key, value) {
  4. const dict = [];
  5. if (_key !== null && _key !== "") {
  6. dict.push({
  7. key: _key,
  8. value: value
  9. });
  10. }
  11. return dict;
  12. }
  13. export function useDict(...args) {
  14. const res = ref({});
  15. return (() => {
  16. args.forEach((dictType, index) => {
  17. res.value[dictType] = [];
  18. getDicts(dictType).then(resp => {
  19. res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
  20. setDict(dictType, res.value[dictType]);
  21. })
  22. })
  23. return toRefs(res.value);
  24. })()
  25. }