Commit 9c792a7a31e7aff746579c324485fafbf9f94f24
Merge branch 'perf/DEFECT-2890' into 'main_dev'
perf: 优化自定义TCP命令长度应为偶数 See merge request yunteng/thingskit-front!1508
Showing
3 changed files
with
8 additions
and
3 deletions
... | ... | @@ -2,10 +2,13 @@ import { ValidatorRule } from 'ant-design-vue/lib/form/interface'; |
2 | 2 | import { i18n } from '/@/locales/setupI18n'; |
3 | 3 | export { default as ThingsModelForm } from './index.vue'; |
4 | 4 | |
5 | -export const validateTCPCustomCommand: ValidatorRule['validator'] = (_rule, value) => { | |
5 | +export const validateTCPCustomCommand: ValidatorRule['validator'] = (_rule, value = '') => { | |
6 | 6 | const reg = /^[\s0-9a-fA-F]+$/; |
7 | - if (reg.test(value)) return Promise.resolve(); | |
8 | - return Promise.reject(i18n.global.t('validator.hex')); | |
7 | + if (!reg.test(value)) return Promise.reject(i18n.global.t('validator.hex')); | |
8 | + | |
9 | + if (value?.length % 2) return Promise.reject(i18n.global.t('validator.hexLength')); | |
10 | + | |
11 | + return Promise.resolve(); | |
9 | 12 | }; |
10 | 13 | |
11 | 14 | export const trimBlankSpace = (string: string) => string.replace(/(?!^)(?=(\w{2})+$)/g, ''); | ... | ... |
... | ... | @@ -7,4 +7,5 @@ export default { |
7 | 7 | passwordRegularization: |
8 | 8 | 'Passwords must contain uppercase and lowercase letters, numbers, and special characters, with a minimum of 8 characters and a maximum of 30 characters', |
9 | 9 | phone: 'Please enter the correct mobile number', |
10 | + hexLength: 'The length of the HEX command must be an even number', | |
10 | 11 | }; | ... | ... |