修复字典键值为bool类型和字符串类型时,下拉列表逻辑Bug,增加自动检测类型,不强制手动传入valueType

pull/46/head
zqx 2024-09-04 22:12:10 +08:00
parent 26df81a16f
commit be137ca82b
1 changed files with 16 additions and 1 deletions

View File

@ -38,11 +38,26 @@ export function getDictOpts(dictType: string) {
*/
return getDictDatas(dictType)
}
/**
*
* @param dictType
*/
function determineType(dictType) {
if (dictType === "true" || dictType === "false") {
return "boolean";
} else if (!isNaN(parseFloat(dictType)) && parseFloat(dictType).toString() === dictType) {
return "number";
} else {
return "string";
}
}
export function getDictOptions(dictType: string, valueType?: 'string' | 'number' | 'boolean') {
const dictOption: DictDataType[] = []
const dictOptions: DictDataType[] = getDictDatas(dictType)
if (dictOptions && dictOptions.length > 0) {
if(!valueType){
valueType = determineType(dictOptions[0].value);
}
dictOptions.forEach((dict: DictDataType) => {
dictOption.push({
...dict,