From 526e5e0e48ae0d6cda6dd27ed720045aeb6abcda Mon Sep 17 00:00:00 2001 From: 670788339 <670788339@qq.com> Date: Mon, 3 Nov 2025 10:24:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=B8=85=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Course/courseTag.vue | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index aaba9fb0..8981d0a9 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -69,7 +69,8 @@ export default { params: {}, tag: {}, // 添加临时存储用于回滚 - previousTags: [] + previousTags: [], + justCreatedTag: false } }, computed: { @@ -257,10 +258,31 @@ export default { } const {result:newTag} = await apiCourseTag.createTag(this.params) this.$message.success('标签创建成功',newTag); - this.searchResults.push(newTag) - console.log("----------newTag---------->",this.searchResults) + + // 将新标签添加到搜索结果中 + this.searchResults.unshift(newTag); // 使用unshift添加到前面 this.tagMap.set(newTag.id, newTag) - this.$emit('change', this.displayTags) + + this.selectedTags.push(newTag); + this.$emit('change', this.selectedTags) + + this.clearInput(); + // 重新打开下拉框显示新创建的标签 + this.$nextTick(() => { + if (this.$refs.tagSelect) { + // 手动打开下拉框 + this.$refs.tagSelect.focus(); + // 设置一个标记,避免立即关闭 + this.justCreatedTag = true; + setTimeout(() => { + this.justCreatedTag = false; + }, 100); + } + }); + + } catch (error) { + this.$message.error('标签创建失败'); + console.error('创建标签失败:', error); } finally { this.loading = false }