标签清除调试

This commit is contained in:
670788339
2025-11-03 12:14:31 +08:00
parent 512144d7d7
commit a901e488b4

View File

@@ -228,7 +228,7 @@ export default {
}
},
//修改:创建新标签
//修改:创建新标签 - 修复显示问题
async createNewTag(tagName) {
// 标签不能超过八个字
if (tagName.length > 8) {
@@ -272,17 +272,30 @@ export default {
}
const {result:newTag} = await apiCourseTag.createTag(this.params)
this.$message.success('标签创建成功',newTag);
this.$message.success('标签创建成功');
// 修改:将新标签添加到选中列表和搜索结果中
this.selectedTagIds.push(newTag.id);
this.searchResults.push(newTag);
this.tagMap.set(newTag.id, newTag);
console.log("----------newTag---------->",this.searchResults)
// 创建完整的标签对象包含id和tagName
const completeTag = {
id: newTag.id,
tagName: newTag.tagName
};
this.searchResults.push(completeTag);
this.tagMap.set(newTag.id, completeTag);
console.log("----------新创建标签---------->", completeTag)
console.log("----------当前选中标签ID---------->", this.selectedTagIds)
console.log("----------标签映射表---------->", this.tagMap)
// 触发change事件传递标签对象数组和ID字符串
this.$emit('change', this.displayTags, this.tagIdsString);
// 清空输入框
this.clearInput();
} finally {
this.loading = false
}
@@ -301,10 +314,16 @@ export default {
const {result:tags} = await apiCourseTag.searchTags({tagName:query,typeId:typeId})
console.log("-- searchTags 查询结果 tags = " + tags )
tags.forEach(item => {
// 确保每个标签对象都有完整的属性
const completeTags = tags.map(tag => ({
id: tag.id,
tagName: tag.tagName
}));
completeTags.forEach(item => {
this.tagMap.set(item.id, item)
})
this.searchResults = tags
this.searchResults = completeTags
// 当搜索结果为空时,提示用户可以按回车键创建标签
if (tags.length === 0 && query.trim()) {
this.$message.info('无此标签,按回车键创建')