From a54c642f4b2f7743b7fd49d0eb4decfd126ffd63 Mon Sep 17 00:00:00 2001 From: 670788339 <670788339@qq.com> Date: Sun, 2 Nov 2025 10:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Course/courseTag.vue | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index 2a126745..2d15ac5c 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -176,11 +176,22 @@ export default { //按回车键,创建新标签 handleEnterKey(event) { const inputVal = event.target.value?.trim() + if (!inputVal) return; + // 检查是否与已选择的标签重复 + const isDuplicate = this.selectedTags.some(tag => tag.tagName === inputVal); + if (isDuplicate) { + this.$message.warning('该标签已存在,无需重复创建'); + event.target.value = ''; + return; + } if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) { this.createNewTag(event.target.value.trim()) event.target.value = '' } else if (this.selectedTags.length >= this.maxTags) { this.$message.warning('最多只能添加5个标签') + event.target.value = '' + } else { + event.target.value = '' } }, @@ -213,6 +224,18 @@ export default { this.$message.error('标签不能超过8个字') return; } + // 首先检查是否与已选择的标签重复 + const isDuplicate = this.selectedTags.some(tag => tag.tagName === tagName); + if (isDuplicate) { + this.$message.warning('该标签已存在,无需重复创建'); + return; + } + // 标签格式验证:仅支持中文、英文、数字、下划线、中横线 + const tagPattern = /^[\u4e00-\u9fa5a-zA-Z0-9_-]+$/; + if (!tagPattern.test(tagName)) { + this.$message.error('标签名称仅支持中文、英文、数字、下划线(_)和中横线(-),不支持空格、点和特殊字符'); + return; + } // 添加标签数量限制检查 if (this.selectedTags.length >= this.maxTags) { this.$message.warning('最多只能添加5个标签')