From cc7801d42db0cbab2634a0155e0b5beee25808d0 Mon Sep 17 00:00:00 2001 From: 670788339 <670788339@qq.com> Date: Tue, 4 Nov 2025 12:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Course/courseTag.vue | 67 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index 508d9765..45bf0692 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -69,7 +69,8 @@ export default { params: {}, tag: {}, // 添加临时存储用于回滚 - previousTags: [] + previousTags: [], + allTags: [] } }, computed: { @@ -116,8 +117,14 @@ export default { sysTypeList: { handler() { // 只有在已选择分类且有焦点时才重新加载 - if (this.sysTypeList.length > 0 && this.$refs.tagSelect && this.$refs.tagSelect.visible) { - this.doSearch(''); + // if (this.sysTypeList.length > 0 && this.$refs.tagSelect && this.$refs.tagSelect.visible) { + // this.doSearch(''); + // } + if (this.sysTypeList.length > 0) { + this.shouldReloadAllTags = true; // 设置重新加载标志 + if (this.$refs.tagSelect && this.$refs.tagSelect.visible) { + this.doSearch(''); // 触发重新加载 + } } }, deep: true @@ -284,32 +291,38 @@ export default { }, // 修改doSearch方法,添加搜索结果为空时的提示 async doSearch(query) { - // 不再在空查询时清空搜索结果 - // if (!query.trim()) { - // this.searchResults = [] - // return - // } - console.log("---- doSearch ------ query = " + query ) - this.loading = true - try { - // 获取 typeId:取 sysTypeList 最后一个有效的值 - const typeId = this.sysTypeList.length > 2 ? this.sysTypeList[2] : - this.sysTypeList.length > 1 ? this.sysTypeList[1] : - this.sysTypeList.length > 0 ? this.sysTypeList[0] : null; - console.log("---- doSearch searchTags ------ query = " + query + " , typeId = " + typeId ) - const {result:tags} = await apiCourseTag.searchTags({tagName:query,typeId:typeId}) - console.log("-- searchTags 查询结果 tags = " + tags ) + // 如果是初始化(query为空且allTags为空)或者分类变更后 + if ((!query && this.allTags.length === 0) || this.shouldReloadAllTags) { + this.loading = true; + try { + const typeId = this.sysTypeList.length > 2 ? this.sysTypeList[2] : + this.sysTypeList.length > 1 ? this.sysTypeList[1] : + this.sysTypeList.length > 0 ? this.sysTypeList[0] : null; - tags.forEach(item => { - this.tagMap.set(item.id, item) - }) - this.searchResults = tags - // 当搜索结果为空时,提示用户可以按回车键创建标签 - if (tags.length === 0) { - this.$message.info('无此标签,按回车键创建') + const { result: tags } = await apiCourseTag.searchTags({ tagName: '', typeId: typeId }); + + tags.forEach(item => { + this.tagMap.set(item.id, item); + }); + + this.allTags = tags; // 保存所有标签 + this.searchResults = tags; // 初始显示所有标签 + + this.shouldReloadAllTags = false; // 重置标志位 + } finally { + this.loading = false; + } + } else { + // 本地过滤 + const filteredTags = this.allTags.filter(tag => + tag.tagName.toLowerCase().includes(query.toLowerCase()) + ); + this.searchResults = filteredTags; + + // 当本地过滤结果为空时提示创建 + if (filteredTags.length === 0 && query) { + this.$message.info('无此标签,按回车键创建'); } - } finally { - this.loading = false } } }