From 5536fc06e18537f7a21875026ccf840d7aa047cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=93=E7=85=9C?= <2210102150@qq.com> Date: Sun, 28 Sep 2025 11:07:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=AE=A1=E7=90=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=97=A0=E6=95=B0=E6=8D=AE=E4=B9=9F=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=9B=9E=E8=BD=A6=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Course/courseTag.vue | 68 +++++++++++++++++++---------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index b1dd32a6..421c42ea 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -15,6 +15,8 @@ @remove-tag="handleTagRemove" @change="handleSelectionChange" @keyup.enter.native="handleEnterKey" + @keyup.delete.native="handleDeleteKey" + ref="tagSelect" > { - this.tagMap.set(item.id, item) - }) - this.searchResults = tags - // 当搜索结果为空时,提示用户可以按回车键创建标签 - if (tags.length === 0) { - this.$message.info('无此标签,按回车键创建') - } - } finally { - this.loading = false - } - }, handleTagRemove(tagId) { this.selectedTags = this.selectedTags.filter(id => id !== tagId) this.$emit('change', this.displayTags) + // 清空输入框内容 + if (this.$refs.tagSelect) { + const input = this.$refs.tagSelect.$refs.input + if (input) { + input.value = '' + } + } }, removeTag(tagId) { this.handleTagRemove(tagId) }, + // 新增:处理删除键事件 + handleDeleteKey(event) { + // 如果输入框内容为空,不执行任何搜索 + if (!event.target.value.trim()) { + this.searchResults = [] + } + }, + //按回车键,创建新标签 handleEnterKey(event) { const inputVal = event.target.value?.trim() @@ -155,6 +150,13 @@ export default { // 新增:处理选择变化事件 handleSelectionChange() { this.$emit('change', this.displayTags) + // 选择标签后清空输入框 + if (this.$refs.tagSelect) { + const input = this.$refs.tagSelect.$refs.input + if (input) { + input.value = '' + } + } }, //创建新标签 async createNewTag(tagName) { @@ -187,6 +189,28 @@ export default { this.loading = false } }, + // 修改doSearch方法,添加搜索结果为空时的提示 + async doSearch(query) { + if (!query.trim()) { + this.searchResults = [] + return + } + + this.loading = true + try { + const {result:tags} = await apiCourseTag.searchTags({tagName:query}) + tags.forEach(item => { + this.tagMap.set(item.id, item) + }) + this.searchResults = tags + // 当搜索结果为空时,提示用户可以按回车键创建标签 + if (tags.length === 0) { + this.$message.info('无此标签,按回车键创建') + } + } finally { + this.loading = false + } + } } }