mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 11:56:44 +08:00
调试
This commit is contained in:
@@ -76,9 +76,20 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['userInfo']),
|
...mapGetters(['userInfo']),
|
||||||
displayTags() {
|
displayTags() {
|
||||||
return this.selectedTags.map(tag =>
|
const tags = this.selectedTags.map(tag => {
|
||||||
typeof tag === 'object' ? tag : this.tagMap.get(tag)
|
if (typeof tag === 'object' && tag.tagName) {
|
||||||
).filter(Boolean)
|
return tag; // 已经是完整对象
|
||||||
|
} else if (typeof tag === 'object' && tag.id) {
|
||||||
|
// 有id但可能缺少tagName,从tagMap获取
|
||||||
|
return this.tagMap.get(tag.id) || tag;
|
||||||
|
} else {
|
||||||
|
// 其他情况,尝试从tagMap获取
|
||||||
|
return this.tagMap.get(tag) || tag;
|
||||||
|
}
|
||||||
|
}).filter(Boolean);
|
||||||
|
|
||||||
|
console.log('displayTags计算结果:', tags);
|
||||||
|
return tags;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -89,14 +100,19 @@ export default {
|
|||||||
// 添加:挂载时初始化标签数据
|
// 添加:挂载时初始化标签数据
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.initialTags && this.initialTags.length > 0) {
|
if (this.initialTags && this.initialTags.length > 0) {
|
||||||
this.selectedTags = this.initialTags;
|
// 验证初始标签数据
|
||||||
this.searchResults = this.initialTags;
|
this.selectedTags = this.initialTags.filter(tag =>
|
||||||
// 将初始标签添加到tagMap中,确保删除功能正常
|
tag && tag.id && tag.tagName
|
||||||
this.initialTags.forEach(tag => {
|
);
|
||||||
|
this.searchResults = this.selectedTags;
|
||||||
|
|
||||||
|
this.selectedTags.forEach(tag => {
|
||||||
if (tag.id) {
|
if (tag.id) {
|
||||||
this.tagMap.set(tag.id, tag);
|
this.tagMap.set(tag.id, tag);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('初始化后的标签数据:', this.selectedTags);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -185,7 +201,7 @@ export default {
|
|||||||
event.target.value = '';
|
event.target.value = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) {
|
if (!isDuplicate && inputVal && this.selectedTags.length < this.maxTags) {
|
||||||
await this.createNewTag(inputVal)
|
await this.createNewTag(inputVal)
|
||||||
this.clearInput();
|
this.clearInput();
|
||||||
} else if (this.selectedTags.length >= this.maxTags) {
|
} else if (this.selectedTags.length >= this.maxTags) {
|
||||||
@@ -265,16 +281,31 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
const {result:newTag} = await apiCourseTag.createTag(this.params)
|
const {result:newTag} = await apiCourseTag.createTag(this.params)
|
||||||
|
console.log('API返回的新标签对象:', newTag);
|
||||||
|
console.log('标签ID:', newTag?.id);
|
||||||
|
console.log('标签名称:', newTag?.tagName);
|
||||||
|
console.log('标签完整结构:', JSON.stringify(newTag));
|
||||||
|
if (!newTag?.id || !newTag?.tagName) {
|
||||||
|
console.error('API返回的标签数据不完整');
|
||||||
|
this.$message.error('标签创建失败:返回数据不完整');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.$message.success('标签创建成功',newTag);
|
this.$message.success('标签创建成功',newTag);
|
||||||
|
|
||||||
|
const tagObject = {
|
||||||
|
id: newTag.id,
|
||||||
|
tagName: newTag.tagName,
|
||||||
|
// 如果有其他必要字段也加上
|
||||||
|
...newTag
|
||||||
|
};
|
||||||
|
|
||||||
this.selectedTags.push(newTag);
|
this.selectedTags.push(newTag);
|
||||||
this.searchResults.push(newTag)
|
this.searchResults.push(newTag)
|
||||||
this.tagMap.set(newTag.id, newTag)
|
this.tagMap.set(newTag.id, newTag)
|
||||||
console.info(' 标签创建成功 id = ' + newTag.id)
|
|
||||||
console.info(' 标签创建成功 tagName = ' + newTag.tagName)
|
console.log('添加后的selectedTags:', this.selectedTags);
|
||||||
console.info(' 标签创建成功 selectedTags = ' + this.selectedTags)
|
console.log('添加后的searchResults:', this.searchResults);
|
||||||
console.info(' 标签创建成功 searchResults = ' + this.searchResults)
|
|
||||||
console.info(' 标签创建成功 tagMap = ' + this.tagMap)
|
|
||||||
this.$emit('change', this.displayTags)
|
this.$emit('change', this.displayTags)
|
||||||
this.doSearch('');
|
this.doSearch('');
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user