chore: 优化字典hooks使用

This commit is contained in:
xlsea
2024-09-11 16:37:35 +08:00
parent 2b14b84c67
commit 9cbbaff297
13 changed files with 94 additions and 52 deletions

View File

@ -40,6 +40,11 @@ export function useDict(dictType: string, immediate: boolean = true) {
options.value = data.value.map(dict => ({ label: dict.dictLabel!, value: dict.dictValue! }));
}
function transformDictData(dictValue: string): Api.System.DictData | undefined {
if (!data.value.length || !dictValue) return undefined;
return data.value.find(dict => dict.dictValue === dictValue);
}
if (immediate) {
getData().then(() => {
getRecord();
@ -64,6 +69,7 @@ export function useDict(dictType: string, immediate: boolean = true) {
options,
getData,
getRecord,
getOptions
getOptions,
transformDictData
};
}