import useDictStore from '../stores/dict'
|
import { ref, toRefs,} from "vue";
|
|
/**
|
* 获取字典数据
|
*/
|
export async function useDict(...args) {
|
const res = ref({});
|
|
for (const dictType of args) {
|
res.value[dictType] = [];
|
const dicts = useDictStore().getDict(dictType);
|
|
if (dicts) {
|
res.value[dictType] = dicts;
|
} else {
|
try {
|
const resp = await uni.$uapi.get("/system/dict/data/type/" + dictType);
|
res.value[dictType] = resp.data.map(p => ({
|
label: p.dictLabel,
|
value: p.dictValue,
|
elTagType: p.listClass,
|
elTagClass: p.cssClass
|
}));
|
useDictStore().setDict(dictType, res.value[dictType]);
|
} catch (error) {
|
console.error(`Failed to fetch dict ${dictType}:`, error);
|
// 可以根据需要处理错误,比如设置默认值或抛出错误
|
}
|
}
|
}
|
// console.log(res.value.sys_user_sex,'2');
|
|
return toRefs(res.value);
|
}
|