修复字典键值为bool类型和字符串类型时,下拉列表逻辑Bug,增加自动检测类型,不强制手动传入valueType
parent
26df81a16f
commit
be137ca82b
|
|
@ -38,11 +38,26 @@ export function getDictOpts(dictType: string) {
|
||||||
*/
|
*/
|
||||||
return getDictDatas(dictType)
|
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') {
|
export function getDictOptions(dictType: string, valueType?: 'string' | 'number' | 'boolean') {
|
||||||
const dictOption: DictDataType[] = []
|
const dictOption: DictDataType[] = []
|
||||||
const dictOptions: DictDataType[] = getDictDatas(dictType)
|
const dictOptions: DictDataType[] = getDictDatas(dictType)
|
||||||
if (dictOptions && dictOptions.length > 0) {
|
if (dictOptions && dictOptions.length > 0) {
|
||||||
|
if(!valueType){
|
||||||
|
valueType = determineType(dictOptions[0].value);
|
||||||
|
}
|
||||||
dictOptions.forEach((dict: DictDataType) => {
|
dictOptions.forEach((dict: DictDataType) => {
|
||||||
dictOption.push({
|
dictOption.push({
|
||||||
...dict,
|
...dict,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue