This commit is contained in:
670788339
2025-11-04 12:26:35 +08:00
parent ef868f8165
commit cc7801d42d

View File

@@ -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
}
}
}