Commit d88e0d735bfc37926b4bc90cd1737225ee2c5714

Authored by ww
1 parent a9490791

fix: 修复物模型步长验证逻辑问题

1 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; 1 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
2 import { findDictItemByCode } from '/@/api/system/dict'; 2 import { findDictItemByCode } from '/@/api/system/dict';
3 import { FormSchema } from '/@/components/Table'; 3 import { FormSchema } from '/@/components/Table';
  4 +import { isNullOrUnDef } from '/@/utils/is';
4 import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; 5 import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config';
5 6
6 export enum DataTypeEnum { 7 export enum DataTypeEnum {
@@ -133,11 +134,12 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => { @@ -133,11 +134,12 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => {
133 values[FormField.TYPE] === DataTypeEnum.IS_NUMBER_DOUBLE, 134 values[FormField.TYPE] === DataTypeEnum.IS_NUMBER_DOUBLE,
134 dynamicRules: ({ model }) => { 135 dynamicRules: ({ model }) => {
135 const valueRange = model[FormField.VALUE_RANGE] || {}; 136 const valueRange = model[FormField.VALUE_RANGE] || {};
136 - const { min = 0, max = 0 } = valueRange; 137 + const { min, max } = valueRange;
137 const step = model[FormField.STEP]; 138 const step = model[FormField.STEP];
138 return [ 139 return [
139 { 140 {
140 validator: () => { 141 validator: () => {
  142 + if ([min, max].every(isNullOrUnDef)) return Promise.resolve();
141 if (step > max - min) { 143 if (step > max - min) {
142 return Promise.reject('步长不能大于取值范围的差值'); 144 return Promise.reject('步长不能大于取值范围的差值');
143 } 145 }
@@ -19,7 +19,8 @@ export const useGenDynamicForm = () => { @@ -19,7 +19,8 @@ export const useGenDynamicForm = () => {
19 }: BasicCreateFormParams): FormSchema => { 19 }: BasicCreateFormParams): FormSchema => {
20 const { specs, type } = dataType; 20 const { specs, type } = dataType;
21 const { valueRange, step } = specs! as Partial<Specs>; 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 return { 24 return {
24 field: identifier, 25 field: identifier,
25 label: functionName, 26 label: functionName,
@@ -29,7 +30,10 @@ export const useGenDynamicForm = () => { @@ -29,7 +30,10 @@ export const useGenDynamicForm = () => {
29 type: 'number', 30 type: 'number',
30 trigger: 'change', 31 trigger: 'change',
31 validator: (_rule, value) => { 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 return Promise.reject(`${functionName}取值范围在${min}~${max}之间`); 37 return Promise.reject(`${functionName}取值范围在${min}~${max}之间`);
34 } 38 }
35 return Promise.resolve(value); 39 return Promise.resolve(value);
@@ -37,8 +41,8 @@ export const useGenDynamicForm = () => { @@ -37,8 +41,8 @@ export const useGenDynamicForm = () => {
37 }, 41 },
38 ], 42 ],
39 componentProps: { 43 componentProps: {
40 - max,  
41 - min, 44 + max: max ?? Number.MAX_SAFE_INTEGER,
  45 + min: min ?? Number.MIN_SAFE_INTEGER,
42 step, 46 step,
43 placeholder: `请输入${functionName}`, 47 placeholder: `请输入${functionName}`,
44 precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2, 48 precision: type === DataTypeEnum.IS_NUMBER_INT ? 0 : 2,