This commit is contained in:
670788339
2025-11-04 08:58:20 +08:00
parent f0ea689166
commit d087082613

View File

@@ -6,6 +6,7 @@
multiple multiple
filterable filterable
value-key="id" value-key="id"
default-first-option
remote remote
reserve-keyword reserve-keyword
:remote-method="debouncedSearch" :remote-method="debouncedSearch"
@@ -13,8 +14,8 @@
:placeholder="'回车创建新标签'" :placeholder="'回车创建新标签'"
@remove-tag="handleTagRemove" @remove-tag="handleTagRemove"
@change="handleSelectionChange" @change="handleSelectionChange"
@keyup.enter.native="handleEnterKey"
@keyup.delete.native="handleDeleteKey"
@focus="handleFocus" @focus="handleFocus"
ref="tagSelect" ref="tagSelect"
> >
@@ -168,26 +169,26 @@ export default {
}, },
//按回车键,创建新标签 //按回车键,创建新标签
handleEnterKey(event) { // handleEnterKey(event) {
const inputVal = event.target.value?.trim() // const inputVal = event.target.value?.trim()
if (!inputVal) return; // if (!inputVal) return;
// 检查是否与已选择的标签重复 // // 检查是否与已选择的标签重复
const isDuplicate = this.selectedTags.some(tag => tag.tagName === inputVal); // const isDuplicate = this.selectedTags.some(tag => tag.tagName === inputVal);
if (isDuplicate) { // if (isDuplicate) {
this.$message.warning('该标签已存在,无需重复创建'); // this.$message.warning('该标签已存在,无需重复创建');
event.target.value = ''; // event.target.value = '';
return; // 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())
this.clearInput(); // this.clearInput();
} else if (this.selectedTags.length >= this.maxTags) { // } else if (this.selectedTags.length >= this.maxTags) {
this.$message.warning('最多只能添加5个标签') // this.$message.warning('最多只能添加5个标签')
this.clearInput(); // this.clearInput();
} else { // } else {
this.clearInput(); // this.clearInput();
} // }
}, // },
// 新增:处理选择变化事件 // 新增:处理选择变化事件
handleSelectionChange(newValues) { handleSelectionChange(newValues) {