Skip to content

Commit 7eda541

Browse files
author
breezeli
authored
Merge pull request #2848 from joe511230/v3.2.x_bugfix
fix:ui: 修复长短字符长度校验未按byte校验的问题 Former-commit-id: 4ee1c3b
2 parents 803f2c5 + f4fa4f4 commit 7eda541

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/ui/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"lodash.throttle": "4.1.1",
2424
"md5": "2.2.1",
2525
"moment": "2.22.2",
26+
"utf8-byte-length": "^1.0.4",
2627
"v-click-outside": "1.0.5",
2728
"v-tooltip": "2.0.0-rc.33",
2829
"vee-validate": "2.0.9",

src/ui/src/components/ui/form/form-multiple.vue

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
}
196196
if (['singlechar', 'longchar'].includes(propertyType)) {
197197
rules[propertyType] = true
198+
rules[`${propertyType}Length`] = true
198199
}
199200
if (propertyType === 'int') {
200201
rules['numeric'] = true

src/ui/src/components/ui/form/form.vue

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
}
194194
if (['singlechar', 'longchar'].includes(propertyType)) {
195195
rules[propertyType] = true
196+
rules[`${propertyType}Length`] = true
196197
}
197198
if (propertyType === 'float') {
198199
rules['float'] = true

src/ui/src/setup/validate.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import Vue from 'vue'
22
import { language } from '@/i18n'
33
import veeValidate, {Validator} from 'vee-validate'
4+
import stringLength from 'utf8-byte-length'
45

56
const customRules = {
67
singlechar: {
78
validate: value => {
8-
/* eslint-disable */
9-
return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[\(\)\+\-_,:;@#\."'\\\/\s]){0,256}$/.test(value)
10-
/* eslint-enable */
9+
return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[()+\-_,:;@#."'\\/\s]){0,256}$/.test(value)
10+
}
11+
},
12+
singlecharLength: {
13+
validate: value => {
14+
return stringLength(value) <= 256
1115
}
1216
},
1317
longchar: {
1418
validate: value => {
15-
/* eslint-disable */
16-
return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[\(\)\+\-_,:;@#\."'\\\/\s]){0,2000}$/.test(value)
17-
/* eslint-enable */
19+
return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[()+\-_,:;@#."'\\/\s]){0,2000}$/.test(value)
20+
}
21+
},
22+
longcharLength: {
23+
validate: value => {
24+
return stringLength(value) <= 2000
1825
}
1926
},
2027
associationId: {
@@ -86,7 +93,9 @@ const dictionary = {
8693
messages: {
8794
regex: () => '请输入符合自定义正则的内容',
8895
longchar: () => '请输入正确的长字符内容',
96+
longcharLength: () => '请输入2000个字符以内的内容',
8997
singlechar: () => '请输入正确的短字符内容',
98+
singlecharLength: () => '请输入256个字符以内的内容',
9099
associationId: () => '格式不正确,只能包含下划线,英文小写',
91100
classifyName: () => '请输入正确的内容',
92101
classifyId: () => '请输入正确的内容',
@@ -111,7 +120,9 @@ const dictionary = {
111120
messages: {
112121
regex: () => 'Please enter the correct content that conform custom regex',
113122
longchar: () => 'Please enter the correct content',
123+
longcharLength: () => 'Content length max than 2000',
114124
singlechar: () => 'Please enter the correct content',
125+
singlecharLength: () => 'Content length max than 256',
115126
associationId: () => 'The format is incorrect and can only contain underscores and lowercase English',
116127
classifyName: () => 'Please enter the correct content',
117128
classifyId: () => 'Please enter the correct content',

0 commit comments

Comments
 (0)