diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index b02dcc98..71e5e628 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -11,11 +11,12 @@ :remote-method="debouncedSearch" :loading="loading" :disabled="sysTypeList.length===0" - :placeholder="sysTypeList.length === 0 ? '请先选择课程分类' : '请输入标签名称'" + :placeholder="'请输入标签名称'" @remove-tag="handleTagRemove" @change="handleSelectionChange" @keyup.enter.native="handleEnterKey" @keyup.delete.native="handleDeleteKey" + @focus="handleFocus" ref="tagSelect" > { if (tag.id) this.tagMap.set(tag.id, tag); }); + }, + // 监听分类变化,重新加载搜索结果 + sysTypeList: { + handler() { + // 只有在已选择分类且有焦点时才重新加载 + if (this.sysTypeList.length > 0 && this.$refs.tagSelect && this.$refs.tagSelect.visible) { + this.doSearch(''); + } + }, + deep: true } }, methods: { + // 新增:处理输入框获得焦点事件 + async handleFocus() { + // 当输入框获得焦点时,加载默认的搜索结果 + if (this.sysTypeList.length > 0) { + await this.doSearch(''); + } + }, // 新增:重置标签状态的方法 resetTagState() { this.selectedTags = []; @@ -202,10 +220,11 @@ export default { }, // 修改doSearch方法,添加搜索结果为空时的提示 async doSearch(query) { - if (!query.trim()) { - this.searchResults = [] - return - } + // 不再在空查询时清空搜索结果 + // if (!query.trim()) { + // this.searchResults = [] + // return + // } this.loading = true try {