feat:字典详情
This commit is contained in:
parent
89709d8058
commit
e7b9aa637e
70
src/utils/dict.ts
Normal file
70
src/utils/dict.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { fetchGetDictionaryDataList, fetchGetDictionaryTypeList } from '@/service/api';
|
||||||
|
// export dict
|
||||||
|
// {
|
||||||
|
// type:{
|
||||||
|
// sys_sex:[
|
||||||
|
// {label:"男",
|
||||||
|
// value: "1"},
|
||||||
|
// {label:"女",
|
||||||
|
// value: "2"}
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
type indexAbleDictData = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
type indexAbleDictType = {
|
||||||
|
[key: string]: indexAbleDictData[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type indexAbleDict = {
|
||||||
|
type: indexAbleDictType;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
// const dictTypeList = reactive<Api.DictionaryType.DictionaryType[]>([]);
|
||||||
|
// const dict: indexAbleDict = {
|
||||||
|
// type: {
|
||||||
|
// fruits: [
|
||||||
|
// { label: '苹果', value: 'apple' },
|
||||||
|
// { label: '香蕉', value: 'banana' },
|
||||||
|
// { label: '橙子', value: 'orange' }
|
||||||
|
// ],
|
||||||
|
// colors: [
|
||||||
|
// { label: '红色', value: 'red' },
|
||||||
|
// { label: '绿色', value: 'green' },
|
||||||
|
// { label: '蓝色', value: 'blue' }
|
||||||
|
// ],
|
||||||
|
// animals: [
|
||||||
|
// { label: '狗', value: 'dog' },
|
||||||
|
// { label: '猫', value: 'cat' },
|
||||||
|
// { label: '鸟', value: 'bird' }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
const typeList: string[] = (await fetchGetDictionaryTypeList()).data?.data.map(item => item.dictType) || [];
|
||||||
|
const dataList: any[] =
|
||||||
|
(await fetchGetDictionaryDataList()).data?.data.map(item => ({
|
||||||
|
dictType: item.dictType,
|
||||||
|
dictLabel: item.dictLabel,
|
||||||
|
dictValue: item.dictValue
|
||||||
|
})) || [];
|
||||||
|
const dict: indexAbleDict = {
|
||||||
|
type: Array.from(typeList).reduce((acc, dictType) => {
|
||||||
|
// 筛选出当前 dictType 对应的数据
|
||||||
|
const items = dataList.filter(item => item.dictType === dictType);
|
||||||
|
// 将数据转换为 indexAbleDictData 类型
|
||||||
|
acc[dictType] = items.map(item => ({
|
||||||
|
label: item.dictLabel,
|
||||||
|
value: item.dictValue
|
||||||
|
}));
|
||||||
|
return acc;
|
||||||
|
}, {} as indexAbleDictType)
|
||||||
|
};
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
const dict = init();
|
||||||
|
|
||||||
|
export default dict;
|
Loading…
Reference in New Issue
Block a user