From 623fd6cc3d82a405db941317c12a912d52e68077 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 8 Mar 2024 15:40:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=95=B0=E9=87=8F=E4=B8=8D=E8=83=BD=E8=B6=85?= =?UTF-8?q?=E8=BF=8710=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036752 --user=王旭 【用例管理】创建/编辑用例-标签-限制住最多十个 https://www.tapd.cn/55049933/s/1471883 --- .../components/pure/ms-tags-input/index.vue | 24 ++++++++++++++++++- frontend/src/locale/en-US/common.ts | 3 ++- frontend/src/locale/zh-CN/common.ts | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/pure/ms-tags-input/index.vue b/frontend/src/components/pure/ms-tags-input/index.vue index 6c57332e9b..dd867cacd2 100644 --- a/frontend/src/components/pure/ms-tags-input/index.vue +++ b/frontend/src/components/pure/ms-tags-input/index.vue @@ -111,6 +111,23 @@ } ); + function validateTagsCountEnter() { + if (innerModelValue.value.length > 10) { + innerModelValue.value.pop(); + Message.warning(t('common.tagCountMax')); + return false; + } + return true; + } + + function validateTagsCountBlur() { + if (tagsLength.value >= 10) { + Message.warning(t('common.tagCountMax')); + return false; + } + return true; + } + function validateUniqueValue() { if ( props.uniqueValue && @@ -130,6 +147,7 @@ innerInputValue.value && innerInputValue.value.trim() !== '' && validateUniqueValue() && + validateTagsCountBlur() && (innerInputValue.value || '').trim().length <= props.maxLength ) { innerModelValue.value.push(innerInputValue.value.trim()); @@ -139,7 +157,11 @@ } function tagInputEnter() { - if (validateUniqueValue() && (innerInputValue.value || '').trim().length <= props.maxLength) { + if ( + validateTagsCountEnter() && + validateUniqueValue() && + (innerInputValue.value || '').trim().length <= props.maxLength + ) { innerInputValue.value = ''; tagsLength.value += 1; } else { diff --git a/frontend/src/locale/en-US/common.ts b/frontend/src/locale/en-US/common.ts index 33d0bb3352..4cdbe95b7f 100644 --- a/frontend/src/locale/en-US/common.ts +++ b/frontend/src/locale/en-US/common.ts @@ -69,6 +69,7 @@ export default { 'common.resetDefault': 'Reset default', 'common.tagPlaceholder': 'Add tag and press Enter to end', 'common.tagInputMaxLength': 'The tag must not exceed {number} characters', + 'common.tagCountMax': 'The number of labels must not exceed 10', 'common.batchModify': 'Batch Edit', 'common.batchAdd': 'Batch Add', 'common.pleaseSelect': 'please choose', @@ -124,5 +125,5 @@ export default { 'common.stop': 'Stop', 'common.module': 'Module', 'common.yes': 'Yes', - 'common.no': 'No' + 'common.no': 'No', }; diff --git a/frontend/src/locale/zh-CN/common.ts b/frontend/src/locale/zh-CN/common.ts index be87645c4e..4b6d917f50 100644 --- a/frontend/src/locale/zh-CN/common.ts +++ b/frontend/src/locale/zh-CN/common.ts @@ -71,6 +71,7 @@ export default { 'common.resetDefault': '恢复默认', 'common.tagPlaceholder': '添加标签回车结束', 'common.tagInputMaxLength': '标签不得超过 {number} 个字符', + 'common.tagCountMax': '标签个数不得超过 10 个', 'common.batchModify': '批量修改', 'common.batchAdd': '批量添加', 'common.pleaseInput': '请输入', @@ -127,5 +128,5 @@ export default { 'common.stop': '停止', 'common.module': '模块', 'common.yes': '是', - 'common.no': '否' + 'common.no': '否', };