mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-10 03:16:42 +08:00
标签调整
This commit is contained in:
@@ -176,11 +176,22 @@ export default {
|
|||||||
//按回车键,创建新标签
|
//按回车键,创建新标签
|
||||||
handleEnterKey(event) {
|
handleEnterKey(event) {
|
||||||
const inputVal = event.target.value?.trim()
|
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) {
|
if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) {
|
||||||
this.createNewTag(event.target.value.trim())
|
this.createNewTag(event.target.value.trim())
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
} else if (this.selectedTags.length >= this.maxTags) {
|
} else if (this.selectedTags.length >= this.maxTags) {
|
||||||
this.$message.warning('最多只能添加5个标签')
|
this.$message.warning('最多只能添加5个标签')
|
||||||
|
event.target.value = ''
|
||||||
|
} else {
|
||||||
|
event.target.value = ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -213,6 +224,18 @@ export default {
|
|||||||
this.$message.error('标签不能超过8个字')
|
this.$message.error('标签不能超过8个字')
|
||||||
return;
|
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) {
|
if (this.selectedTags.length >= this.maxTags) {
|
||||||
this.$message.warning('最多只能添加5个标签')
|
this.$message.warning('最多只能添加5个标签')
|
||||||
|
|||||||
Reference in New Issue
Block a user