diff --git a/src/views/community/trends.vue b/src/views/community/trends.vue index a8fba1f2..0382d938 100644 --- a/src/views/community/trends.vue +++ b/src/views/community/trends.vue @@ -28,7 +28,7 @@ style="display: flex; flex-direction: row; justify-content: center; align-items: center; position: relative;height: 120%;gap:3%;width: 100%;" @mouseover="hoverIndex = index" @mouseleave="hoverIndex = -1" @click="fllowsClick(follow.myfollowid,index)" :class="{'selected': selectedIndex === index}"> - +
{{ follow.username }}
{{follow.newpostnum}}条新动态 @@ -76,7 +76,7 @@
+ style="position:relative; display: flex;flex-direction:column; color: white; font-weight: bold;margin-left: 20px ;gap:51px;margin-top:10px">
1
2
3
@@ -85,16 +85,16 @@
+ style="font-size: 14px; font-weight: 500; margin-left: 20px; display: flex; flex-direction: column; gap: 17px;width: 100%; ">
{{ Hotsearch.username }}:
{{ Hotsearch.content}}
+ style="position: absolute;right:5.8% ;top:20%;fill:red "> @@ -127,7 +127,7 @@
- +
{{ story.username }}
{{ story.content }}
@@ -163,8 +163,8 @@ page: 1, userid: 1, totalPages: 1, - familystoriespage:0, - checkfamilystories:[], + familystoriespage: 0, + checkfamilystories: [], posts: [ { @@ -257,7 +257,7 @@ submitPost(newpost) {//发布帖子后,本地显示帖子 - this.checkPosts.unshift(newpost); + this.checkPosts.unshift(newpost); }, @@ -274,7 +274,7 @@ const filteredPostsList = response.records; - + this.checkPosts.push(...filteredPostsList); this.page = this.page + 1; } catch (error) { @@ -343,7 +343,32 @@ try { const response = await axios.get(`/posts/topfamilystory`); this.familystories.push(...response); - this.checkfamilystories.push(...response.slice(0, 4)); + // 获取每个家庭故事帖子的用户信息(头像和用户名) + const familystoriesWithUserInfo = await Promise.all( + this.familystories.map(async (story) => { + const { userId } = story; // 假设每个帖子有一个 userId 字段 + try { + // 获取每个帖子的用户信息 + const userResponse = await axios.get(`/user/info/${userId}`); + const { photo } = userResponse.data; // 假设 `data` 中包含 `username` 和 `photo` + + // 返回包含用户信息的帖子对象 + return { + ...story, + photo + }; + } catch (error) { + console.error(`获取用户信息失败: ${error.message}`); + return { + ...story, + photo: null + }; // 如果获取用户信息失败,可以设置为 null 或默认值 + } + }) + ); + this.familystories = familystoriesWithUserInfo; + + this.checkfamilystories.push(...this.familystories.slice(0, 4)); } catch (error) { this.$message.error("热门家族故事获取失败"); @@ -384,7 +409,7 @@ }, async toggleCommentsVisibility(index, postid) {//展开评论以及获取评论列表 - + try { const comments = await axios.get(`/comments/postid=${postid}`); @@ -461,13 +486,13 @@ }, refresh() {//热门家族故事刷新换一批按钮 // 点击后触发的刷新动作 - - this.familystoriespage+=4; - if(this.familystoriespage>12){ - this.familystoriespage=0; + + this.familystoriespage += 4; + if (this.familystoriespage > 12) { + this.familystoriespage = 0; } this.checkfamilystories.splice(0, this.checkfamilystories.length); - this.checkfamilystories.push(...this.familystories.slice(this.familystoriespage, this.familystoriespage+4)); + this.checkfamilystories.push(...this.familystories.slice(this.familystoriespage, this.familystoriespage + 4)); this.triggerAnimation(); },