You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
588 B
JavaScript

import {
getDicts
} from '@/api/dict.js'
import {
ref
} from 'vue'
export const useDict = (key) => {
if (!key) return
let keys = []
if (typeof key === 'string') {
keys = [key]
} else if (Array.isArray(key)) {
keys = key
} else {
return
}
const res = ref({});
keys.forEach(async (dictType) => {
res.value[dictType] = [];
await getDicts(dictType).then((resp) => {
res.value[dictType] = resp.data.map(
(p) => ({
label: p.dictLabel,
value: p.dictValue,
elTagType: p.listClass,
elTagClass: p.cssClass
})
);
});
});
return res.value
}