Commit 430faab6210c8f62885a9f3080fb8fbd52a36a00
Merge branch 'fix/DEFECT-1326' into 'main_dev'
fix: 修复物模型步长验证逻辑问题 See merge request yunteng/thingskit-front!635
Showing
2 changed files
with
11 additions
and
5 deletions
| 1 | 1 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
| 2 | 2 | import { findDictItemByCode } from '/@/api/system/dict'; |
| 3 | 3 | import { FormSchema } from '/@/components/Table'; |
| 4 | +import { isNullOrUnDef } from '/@/utils/is'; | |
| 4 | 5 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
| 5 | 6 | |
| 6 | 7 | export enum DataTypeEnum { |
| ... | ... | @@ -133,11 +134,12 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => { |
| 133 | 134 | values[FormField.TYPE] === DataTypeEnum.IS_NUMBER_DOUBLE, |
| 134 | 135 | dynamicRules: ({ model }) => { |
| 135 | 136 | const valueRange = model[FormField.VALUE_RANGE] || {}; |
| 136 | - const { min = 0, max = 0 } = valueRange; | |
| 137 | + const { min, max } = valueRange; | |
| 137 | 138 | const step = model[FormField.STEP]; |
| 138 | 139 | return [ |
| 139 | 140 | { |
| 140 | 141 | validator: () => { |
| 142 | + if ([min, max].every(isNullOrUnDef)) return Promise.resolve(); | |
| 141 | 143 | if (step > max - min) { |
| 142 | 144 | return Promise.reject('步长不能大于取值范围的差值'); |
| 143 | 145 | } | ... | ... |
| ... | ... | @@ -19,7 +19,8 @@ export const useGenDynamicForm = () => { |
| 19 | 19 | }: BasicCreateFormParams): FormSchema => { |
| 20 | 20 | const { specs, type } = dataType; |
| 21 | 21 | const { valueRange, step } = specs! as Partial<Specs>; |
| 22 | - const { max = 2147483647, min = -2147483648 } = valueRange || {}; | |
| 22 | + const { max, min } = valueRange || {}; | |
| 23 | + console.log({ max, min }); | |
| 23 | 24 | return { |
| 24 | 25 | field: identifier, |
| 25 | 26 | label: functionName, |
| ... | ... | @@ -29,7 +30,10 @@ export const useGenDynamicForm = () => { |
| 29 | 30 | type: 'number', |
| 30 | 31 | trigger: 'change', |
| 31 | 32 | validator: (_rule, value) => { |
| 32 | - if (value < min || value > max) { | |
| 33 | + if ( | |
| 34 | + value < (min ?? Number.MIN_SAFE_INTEGER) || | |
| 35 | + value > (max || Number.MAX_SAFE_INTEGER) | |
| 36 | + ) { | |
| 33 | 37 | return Promise.reject(`${functionName}取值范围在${min}~${max}之间`); |
| 34 | 38 | } |
| 35 | 39 | return Promise.resolve(value); |
| ... | ... | @@ -37,8 +41,8 @@ export const useGenDynamicForm = () => { |
| 37 | 41 | }, |
| 38 | 42 | ], |
| 39 | 43 | componentProps: { |
| 40 | - max, | |
| 41 | - min, | |
| 44 | + max: max ?? Number.MAX_SAFE_INTEGER, | |
| 45 | + min: min ?? Number.MIN_SAFE_INTEGER, | |
| 42 | 46 | step, |
| 43 | 47 | placeholder: `请输入${functionName}`, |
| 44 | 48 | precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2, | ... | ... |