+ style="font-size: 14px; font-weight: 500; margin-left: 20px; display: flex; flex-direction: column; gap: 17px;width: 100%; ">
{{ Hotsearch.username }}:
{{ Hotsearch.content}}
@@ -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();
},