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,6 +12,23 @@ export interface BasicCreateFormParams { | ||
12 | 12 | ||
13 | useComponentRegister('JSONEditor', JSONEditor); | 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 | export const useGenDynamicForm = () => { | 32 | export const useGenDynamicForm = () => { |
16 | const createInputNumber = ({ | 33 | const createInputNumber = ({ |
17 | identifier, | 34 | identifier, |
@@ -30,19 +47,19 @@ export const useGenDynamicForm = () => { | @@ -30,19 +47,19 @@ export const useGenDynamicForm = () => { | ||
30 | type: 'number', | 47 | type: 'number', |
31 | trigger: 'change', | 48 | trigger: 'change', |
32 | validator: (_rule, value) => { | 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 | return Promise.resolve(value); | 54 | return Promise.resolve(value); |
40 | }, | 55 | }, |
41 | }, | 56 | }, |
42 | ], | 57 | ], |
43 | componentProps: { | 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 | step, | 63 | step, |
47 | placeholder: `请输入${functionName}`, | 64 | placeholder: `请输入${functionName}`, |
48 | precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2, | 65 | precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2, |
@@ -136,7 +153,7 @@ export const useGenDynamicForm = () => { | @@ -136,7 +153,7 @@ export const useGenDynamicForm = () => { | ||
136 | fieldTypeMap.clear(); | 153 | fieldTypeMap.clear(); |
137 | const formSchema = schemas.map((item) => { | 154 | const formSchema = schemas.map((item) => { |
138 | const { functionName, identifier, dataType } = item; | 155 | const { functionName, identifier, dataType } = item; |
139 | - console.log(item, 'item'); | 156 | + |
140 | const { type } = dataType || {}; | 157 | const { type } = dataType || {}; |
141 | 158 | ||
142 | fieldTypeMap.set(identifier!, dataType!.type); | 159 | fieldTypeMap.set(identifier!, dataType!.type); |