diff --git a/src/utils/index.ts b/src/utils/index.ts index 2caab0a3..310eb614 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -245,9 +245,9 @@ export const custom_condition_judg = (fieldValue: any, type: string, value: numb case 'less-than': case 'equal': // 根据字段值的类型,进行数字间的比较 - if (typeof fieldValue === 'number') { - return compare_numbers(fieldValue, numberValue, type); - } else if (Array.isArray(fieldValue) || typeof fieldValue === 'string') { + if (typeof fieldValue === 'number' || (typeof fieldValue === 'string' && isPureNumber(fieldValue))) { + return compare_numbers(Number(fieldValue), numberValue, type); + } else if (Array.isArray(fieldValue) || (typeof fieldValue === 'string' && !isPureNumber(fieldValue))) { // 如果字段值是数组或字符串,比较数组长度和指定值 const valueLength = fieldValue?.length || 0; return compare_numbers(valueLength, numberValue, type); @@ -260,6 +260,10 @@ export const custom_condition_judg = (fieldValue: any, type: string, value: numb return true; } } +// 判断是否是纯数字 +function isPureNumber(input: string) { + return /^\d+$/.test(input); +} /** * 比较两个数字的大小