Showing
1 changed file
with
20 additions
and
26 deletions
| 1 | 1 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
| 2 | 2 | import { findDictItemByCode } from '/@/api/system/dict'; |
| 3 | +import { Rule } from '/@/components/Form'; | |
| 3 | 4 | import { FormSchema } from '/@/components/Table'; |
| 4 | 5 | import { DataTypeEnum } from '/@/enums/objectModelEnum'; |
| 5 | 6 | import { isNullOrUnDef } from '/@/utils/is'; |
| ... | ... | @@ -27,6 +28,23 @@ interface StructFormSchemasParmasType { |
| 27 | 28 | isTcp?: boolean; |
| 28 | 29 | } |
| 29 | 30 | |
| 31 | +//功能名称和标识符 输入框不能包含逗号 | |
| 32 | +const validateExcludeComma = (field: string, errorName: string): Rule[] => { | |
| 33 | + return [ | |
| 34 | + { | |
| 35 | + required: true, | |
| 36 | + trigger: 'blur', | |
| 37 | + validator: () => { | |
| 38 | + const reg = /[,,]+/; | |
| 39 | + if (reg.test(field)) { | |
| 40 | + return Promise.reject(errorName); | |
| 41 | + } | |
| 42 | + return Promise.resolve(); | |
| 43 | + }, | |
| 44 | + }, | |
| 45 | + ]; | |
| 46 | +}; | |
| 47 | + | |
| 30 | 48 | export const formSchemas = ({ |
| 31 | 49 | hasStructForm, |
| 32 | 50 | hiddenAccessMode, |
| ... | ... | @@ -46,19 +64,7 @@ export const formSchemas = ({ |
| 46 | 64 | placeholder: '请输入功能名称', |
| 47 | 65 | }, |
| 48 | 66 | dynamicRules: ({ values }) => { |
| 49 | - return [ | |
| 50 | - { | |
| 51 | - required: true, | |
| 52 | - trigger: 'blur', | |
| 53 | - validator: () => { | |
| 54 | - const reg = /[,,]+/; | |
| 55 | - if (reg.test(values[FormField.FUNCTION_NAME])) { | |
| 56 | - return Promise.reject('功能名称不能包含逗号'); | |
| 57 | - } | |
| 58 | - return Promise.resolve(); | |
| 59 | - }, | |
| 60 | - }, | |
| 61 | - ]; | |
| 67 | + return validateExcludeComma(values[FormField.FUNCTION_NAME], '功能名称不能包含逗号'); | |
| 62 | 68 | }, |
| 63 | 69 | }, |
| 64 | 70 | { |
| ... | ... | @@ -74,19 +80,7 @@ export const formSchemas = ({ |
| 74 | 80 | placeholder: '请输入标识符', |
| 75 | 81 | }, |
| 76 | 82 | dynamicRules: ({ values }) => { |
| 77 | - return [ | |
| 78 | - { | |
| 79 | - required: true, | |
| 80 | - trigger: 'blur', | |
| 81 | - validator: () => { | |
| 82 | - const reg = /[,,]+/; | |
| 83 | - if (reg.test(values[FormField.IDENTIFIER])) { | |
| 84 | - return Promise.reject('标识符不能包含逗号'); | |
| 85 | - } | |
| 86 | - return Promise.resolve(); | |
| 87 | - }, | |
| 88 | - }, | |
| 89 | - ]; | |
| 83 | + return validateExcludeComma(values[FormField.IDENTIFIER], '标识符不能包含逗号'); | |
| 90 | 84 | }, |
| 91 | 85 | }, |
| 92 | 86 | { | ... | ... |