mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-09 19:06:43 +08:00
调试
This commit is contained in:
@@ -76,9 +76,20 @@ export default {
|
||||
computed: {
|
||||
...mapGetters(['userInfo']),
|
||||
displayTags() {
|
||||
return this.selectedTags.map(tag =>
|
||||
typeof tag === 'object' ? tag : this.tagMap.get(tag)
|
||||
).filter(Boolean)
|
||||
const tags = this.selectedTags.map(tag => {
|
||||
if (typeof tag === 'object' && tag.tagName) {
|
||||
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() {
|
||||
@@ -89,14 +100,19 @@ export default {
|
||||
// 添加:挂载时初始化标签数据
|
||||
mounted() {
|
||||
if (this.initialTags && this.initialTags.length > 0) {
|
||||
this.selectedTags = this.initialTags;
|
||||
this.searchResults = this.initialTags;
|
||||
// 将初始标签添加到tagMap中,确保删除功能正常
|
||||
this.initialTags.forEach(tag => {
|
||||
// 验证初始标签数据
|
||||
this.selectedTags = this.initialTags.filter(tag =>
|
||||
tag && tag.id && tag.tagName
|
||||
);
|
||||
this.searchResults = this.selectedTags;
|
||||
|
||||
this.selectedTags.forEach(tag => {
|
||||
if (tag.id) {
|
||||
this.tagMap.set(tag.id, tag);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('初始化后的标签数据:', this.selectedTags);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -185,7 +201,7 @@ export default {
|
||||
event.target.value = '';
|
||||
return;
|
||||
}
|
||||
if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) {
|
||||
if (!isDuplicate && inputVal && this.selectedTags.length < this.maxTags) {
|
||||
await this.createNewTag(inputVal)
|
||||
this.clearInput();
|
||||
} else if (this.selectedTags.length >= this.maxTags) {
|
||||
@@ -265,16 +281,31 @@ export default {
|
||||
|
||||
|
||||
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);
|
||||
|
||||
const tagObject = {
|
||||
id: newTag.id,
|
||||
tagName: newTag.tagName,
|
||||
// 如果有其他必要字段也加上
|
||||
...newTag
|
||||
};
|
||||
|
||||
this.selectedTags.push(newTag);
|
||||
this.searchResults.push(newTag)
|
||||
this.tagMap.set(newTag.id, newTag)
|
||||
console.info(' 标签创建成功 id = ' + newTag.id)
|
||||
console.info(' 标签创建成功 tagName = ' + newTag.tagName)
|
||||
console.info(' 标签创建成功 selectedTags = ' + this.selectedTags)
|
||||
console.info(' 标签创建成功 searchResults = ' + this.searchResults)
|
||||
console.info(' 标签创建成功 tagMap = ' + this.tagMap)
|
||||
|
||||
console.log('添加后的selectedTags:', this.selectedTags);
|
||||
console.log('添加后的searchResults:', this.searchResults);
|
||||
|
||||
this.$emit('change', this.displayTags)
|
||||
this.doSearch('');
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user