This commit is contained in:
670788339
2025-11-04 11:19:32 +08:00
parent 7f587138ff
commit 81b8ef168c

View File

@@ -168,13 +168,8 @@ export default {
},
//按回车键,创建新标签
handleEnterKey(event) {
console.log('开始回车创建 = ' + event.target.value)
async handleEnterKey(event) {
const inputVal = event.target.value?.trim()
console.log('回车创建 inputVal= ' + inputVal)
this.clearInput();
console.log('回车创建中 先清文字 inputVal = ' + inputVal)
if (!inputVal) return;
// 检查是否与已选择的标签重复
const isDuplicate = this.selectedTags.some(tag => tag.tagName === inputVal);
@@ -184,7 +179,7 @@ export default {
return;
}
if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) {
this.createNewTag(inputVal)
await this.createNewTag(inputVal)
this.clearInput();
} else if (this.selectedTags.length >= this.maxTags) {
this.$message.warning('最多只能添加5个标签')
@@ -196,7 +191,6 @@ export default {
// 新增:处理选择变化事件
handleSelectionChange(newValues) {
console.log('handleSelectionChange = ' + newValues)
// 检查数量限制
if (newValues.length > this.maxTags) {
this.$message.warning(`最多只能选择${this.maxTags}个标签`);
@@ -208,21 +202,13 @@ export default {
// 更新前保存当前状态
this.previousTags = [...newValues];
this.$emit('change', this.displayTags);
console.log('-- handleSelectionChange clearInput --- this.$refs.tagSelect = ' + this.$refs.tagSelect )
this.clearInput();
console.log('-- handleSelectionChange clearInput --- input.value = ' + this.$refs.tagSelect.$refs.input )
},
clearInput() {
/*if (this.$refs.tagSelect) {
const input = this.$refs.tagSelect.$refs.input;
if (input) {
input.value = '';
}
}*/
// 方案1通过 ref 直接操作 el-select 的输入框
if (this.$refs.tagSelect) {
const input = this.$refs.tagSelect.$el.querySelector('input');
const input = this.$refs.tagSelect.$refs.input;
if (input) {
input.value = '';
}
@@ -269,9 +255,17 @@ export default {
}
const {result:newTag} = await apiCourseTag.createTag(this.params)
this.$message.success('标签创建成功',newTag);
console.log("----------创建前---------->",this.searchResults)
console.log("----------创建前---------->",this.selectedTags)
this.searchResults.push(newTag)
console.log("----------newTag---------->",this.searchResults)
this.tagMap.set(newTag.id, newTag)
this.selectedTags.push(newTag);
console.log("----------创建后---------->",this.searchResults)
console.log("----------创建后---------->",this.selectedTags)
this.$emit('change', this.displayTags)
} finally {
this.loading = false