Commit caa8a7fe830db7c9cb74200cc224a818c3138b49
Merge branch 'fix/DEFECT-1536' into 'main_dev'
fix: DEFECT-1536 物模型为设置取值范围时输入框验证默认取值范围 See merge request yunteng/thingskit-front!860
Showing
1 changed file
with
25 additions
and
8 deletions
... | ... | @@ -12,6 +12,23 @@ export interface BasicCreateFormParams { |
12 | 12 | |
13 | 13 | useComponentRegister('JSONEditor', JSONEditor); |
14 | 14 | |
15 | +const validateDouble = ( | |
16 | + value: number, | |
17 | + type: DataTypeEnum, | |
18 | + min?: number | string, | |
19 | + max?: number | string | |
20 | +) => { | |
21 | + min = | |
22 | + Number(min) || type === DataTypeEnum.IS_NUMBER_INT ? Number.MIN_SAFE_INTEGER : Number.MIN_VALUE; | |
23 | + max = | |
24 | + Number(max) || type === DataTypeEnum.IS_NUMBER_INT ? Number.MAX_SAFE_INTEGER : Number.MAX_VALUE; | |
25 | + | |
26 | + return { | |
27 | + flag: value < min || value > max, | |
28 | + message: `取值范围在${min}~${max}之间`, | |
29 | + }; | |
30 | +}; | |
31 | + | |
15 | 32 | export const useGenDynamicForm = () => { |
16 | 33 | const createInputNumber = ({ |
17 | 34 | identifier, |
... | ... | @@ -30,19 +47,19 @@ export const useGenDynamicForm = () => { |
30 | 47 | type: 'number', |
31 | 48 | trigger: 'change', |
32 | 49 | validator: (_rule, value) => { |
33 | - if ( | |
34 | - value < (min ?? Number.MIN_SAFE_INTEGER) || | |
35 | - value > (max || Number.MAX_SAFE_INTEGER) | |
36 | - ) { | |
37 | - return Promise.reject(`${functionName}取值范围在${min}~${max}之间`); | |
50 | + const { flag, message } = validateDouble(value, type, min, max); | |
51 | + if (flag) { | |
52 | + return Promise.reject(`${functionName}${message}`); | |
38 | 53 | } |
39 | 54 | return Promise.resolve(value); |
40 | 55 | }, |
41 | 56 | }, |
42 | 57 | ], |
43 | 58 | componentProps: { |
44 | - max: max ?? Number.MAX_SAFE_INTEGER, | |
45 | - min: min ?? Number.MIN_SAFE_INTEGER, | |
59 | + max: | |
60 | + max ?? type === DataTypeEnum.IS_NUMBER_INT ? Number.MAX_SAFE_INTEGER : Number.MAX_VALUE, | |
61 | + min: | |
62 | + min ?? type === DataTypeEnum.IS_NUMBER_INT ? Number.MIN_SAFE_INTEGER : Number.MIN_VALUE, | |
46 | 63 | step, |
47 | 64 | placeholder: `请输入${functionName}`, |
48 | 65 | precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2, |
... | ... | @@ -136,7 +153,7 @@ export const useGenDynamicForm = () => { |
136 | 153 | fieldTypeMap.clear(); |
137 | 154 | const formSchema = schemas.map((item) => { |
138 | 155 | const { functionName, identifier, dataType } = item; |
139 | - console.log(item, 'item'); | |
156 | + | |
140 | 157 | const { type } = dataType || {}; |
141 | 158 | |
142 | 159 | fieldTypeMap.set(identifier!, dataType!.type); | ... | ... |