社区修改接口和bug

main
QMZ 1 month ago
parent 273f4ff864
commit 61ab1d2c55

@ -51,7 +51,7 @@
<transition name="fade" @before-enter="beforeEnter" @enter="enter" @leave="leave"> <transition name="fade" @before-enter="beforeEnter" @enter="enter" @leave="leave">
<div v-if="isCommentsVisible" class="comments-section"> <div v-if="isCommentsVisible" class="comments-section">
<div v-for="(comment, index) in comments" :key="index" class="comment"> <div v-for="(comment, index) in comments" :key="index" class="comment">
<p><strong>{{ comment.userid}}:</strong> {{ comment.content }}</p> <p><strong>{{ comment.username}}:</strong> {{ comment.content }}</p>
</div> </div>
<!-- 发布评论 --> <!-- 发布评论 -->
@ -128,14 +128,14 @@
if (this.followsbuttonActive == false) { if (this.followsbuttonActive == false) {
try { try {
const response = await axios.post(`http://localhost:8082/loveforest/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`); const response = await axios.post(`/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response.data === "关注成功!") { if (response === "关注成功!") {
this.$message.success(response.data); this.$message.success(response);
this.followsbuttonActive = true; this.followsbuttonActive = true;
} }
else { else {
this.$message.error(response.data); this.$message.error(response);
} }
} catch (error) { } catch (error) {
@ -149,14 +149,14 @@
else { else {
try { try {
const response = await axios.delete(`http://localhost:8082/loveforest/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`); const response = await axios.delete(`/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response.data === "取消关注成功!") { if (response === "取消关注成功!") {
this.$message.success(response.data); this.$message.success(response);
this.followsbuttonActive = false; this.followsbuttonActive = false;
} }
else { else {
this.$message.error(response.data); this.$message.error(response);
} }
} catch (error) { } catch (error) {
@ -180,15 +180,15 @@
async increaseLikeCount() {// async increaseLikeCount() {//
if (!this.isLiked) {// if (!this.isLiked) {//
try { try {
const response = await axios.post(`http://localhost:8082/loveforest/likes/userid=${this.userid}/postid=${this.postid}`); const response = await axios.post(`/likes/userid=${this.userid}/postid=${this.postid}`);
if (response.data === "点赞成功!") { if (response === "点赞成功!") {
this.$message.success(response.data); this.$message.success(response);
this.$emit('updateLikeCount', this.likeCount + 1); this.$emit('updateLikeCount', this.likeCount + 1);
this.isLiked = !this.isLiked; this.isLiked = !this.isLiked;
} }
else { else {
this.$message.error(response.data); this.$message.error(response);
} }
} catch (error) { } catch (error) {
@ -198,8 +198,8 @@
} }
else {// else {//
try { try {
const response = await axios.delete(`http://localhost:8082/loveforest/likes/userid=${this.userid}/postid=${this.postid}`); const response = await axios.delete(`/likes/userid=${this.userid}/postid=${this.postid}`);
if (response.data === "取消点赞成功!") { if (response === "取消点赞成功!") {
this.$message.error("取消点赞成功"); this.$message.error("取消点赞成功");
this.$emit('updateLikeCount', this.likeCount - 1); this.$emit('updateLikeCount', this.likeCount - 1);
@ -207,7 +207,7 @@
} }
else { else {
this.$message.error(response.data); this.$message.error(response);
} }
} catch (error) { } catch (error) {

@ -28,8 +28,8 @@
style="display: flex; flex-direction: row; justify-content: center; align-items: center; position: relative;height: 120%;gap:3%;width: 100%;" 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)" @mouseover="hoverIndex = index" @mouseleave="hoverIndex = -1" @click="fllowsClick(follow.myfollowid,index)"
:class="{'selected': selectedIndex === index}"> :class="{'selected': selectedIndex === index}">
<img class="touxiang" src="../../assets/pictures/touxiang.png" style="left:20%;width: 15%; height: auto;" /> <img class="touxiang" src="follow.photo" style="left:20%;width: 15%; height: auto;" />
<div style="margin-left: 40px; font-weight: bold; font-size: 16px;">{{ follow.myfollowid }}</div> <div style="margin-left: 40px; font-weight: bold; font-size: 16px;">{{ follow.username }}</div>
<el-tag v-if="follow.newpostnum" effect="plain" round style="position: absolute; right:0%"> <el-tag v-if="follow.newpostnum" effect="plain" round style="position: absolute; right:0%">
{{follow.newpostnum}}条新动态 {{follow.newpostnum}}条新动态
</el-tag> </el-tag>
@ -143,7 +143,7 @@
import PostCard from './PostCard.vue'; import PostCard from './PostCard.vue';
import PostForm from './Postform.vue'; import PostForm from './Postform.vue';
import axios from '@/utils/axiosConfig'; import axios from '@/utils/axiosConfig';
import {getUserId} from '@/token/auth' import { getUserId } from '@/token/auth'
export default { export default {
name: 'CommunityIndex', // name: 'CommunityIndex', //
components: { PostCard, PostForm }, components: { PostCard, PostForm },
@ -192,8 +192,8 @@
async loadData() { async loadData() {
try { try {
this.userid= getUserId(); this.userid = getUserId();
// //
await this.fllowlist(); await this.fllowlist();
await this.loadhotpost(); await this.loadhotpost();
@ -209,37 +209,60 @@
}, },
async fllowlist() { async fllowlist() {
const userid = this.userid;//id const userid = this.userid; // ID
axios.get(`http://localhost:8082/loveforest/Myfollows/userid=${userid}`) try {
.then(response => { // follow
const response = await axios.get(`/Myfollows/userid=${userid}`);
this.myfollows.splice(0, this.myfollows.length); // follow
this.myfollows.push(...response.data); this.myfollows.splice(0, this.myfollows.length);
return response.data; // follow
}) const followsWithUserInfo = await Promise.all(
.catch(error => { response.map(async (follow) => {
console.error('Error:', error); const { userid: followUserid } = follow;
}); try {
// follow
const userResponse = await axios.get(`http://localhost:8082/user/info/${followUserid}/editInfo`);
const { username, photo } = userResponse;
// follow
return {
...follow,
username,
photo
};
} catch (userError) {
console.error(`Error fetching user info for follow with userid ${followUserid}:`, userError);
return {
...follow,
username: 'Unknown', //
photo: '' //
};
}
})
);
// follow myfollows
this.myfollows.push(...followsWithUserInfo);
}, } catch (error) {
console.error('Error fetching follow list:', error);
}
submitPost(newpost) {//
this.checkPosts = [newpost, ...this.checkPosts];
}, },
async load() {// async load() {//
if (this.isloading) { if (this.isloading) {
try { try {
const response = await axios.get(`http://localhost:8082/loveforest/posts`, { const response = await axios.get(`/posts`, {
params: { params: {
page: this.page, page: this.page,
size: 5, size: 5,
}, },
}); });
const filteredPostsList = response.data.records; const filteredPostsList = response.records;
this.$message("动态加载中page" + this.page); this.$message("动态加载中page" + this.page);
@ -256,10 +279,10 @@
try { try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/postid=${postid}`); const response = await axios.get(`/posts/postid=${postid}`);
this.isloading = false; this.isloading = false;
this.checkPosts.splice(0, this.checkPosts.length); this.checkPosts.splice(0, this.checkPosts.length);
this.checkPosts.push(response.data); this.checkPosts.push(response);
} catch (error) { } catch (error) {
@ -271,13 +294,13 @@
async loaduserlikes() {//user async loaduserlikes() {//user
const userid = this.userid;//id const userid = this.userid;//id
axios.get(`http://localhost:8082/loveforest/likes/userid=${userid}`) axios.get(`/likes/userid=${userid}`)
.then(response => { .then(response => {
this.userlikelist.splice(0, this.myfollows.length); this.userlikelist.splice(0, this.myfollows.length);
this.userlikelist.push(...response.data); this.userlikelist.push(...response);
return response.data; return response;
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
@ -294,11 +317,12 @@
this.selectedIndex = -1; this.selectedIndex = -1;
}, },
async loadhotpost() {// async loadhotpost() {//
try { try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/topposts`); const response = await axios.get(`/posts/topposts`);
this.HotsearchList.push(...response.data); this.HotsearchList.push(...response);
console.log(response.data); console.log(response);
} catch (error) { } catch (error) {
this.$message.error("热门动态获取失败"); this.$message.error("热门动态获取失败");
@ -309,8 +333,8 @@
async loadhotfamilystory() {// async loadhotfamilystory() {//
try { try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/topfamilystory`); const response = await axios.get(`/posts/topfamilystory`);
this.familystories.push(...response.data); this.familystories.push(...response);
} catch (error) { } catch (error) {
@ -326,12 +350,12 @@
this.selectedIndex = index; // this.selectedIndex = index; //
try { try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/userid=${userid}`); const response = await axios.get(`/posts/userid=${userid}`);
this.isloading = false; this.isloading = false;
this.checkPosts.splice(0, this.checkPosts.length); this.checkPosts.splice(0, this.checkPosts.length);
this.checkPosts.push(...response.data); this.checkPosts.push(...response);
if (response.data.length === 0) { if (response.length === 0) {
this.$message("对方还没有发过动态哦"); this.$message("对方还没有发过动态哦");
} }
@ -350,12 +374,37 @@
updateCommentCount(index, newCommentCount) {// updateCommentCount(index, newCommentCount) {//
this.checkPosts[index].commentcount = newCommentCount; this.checkPosts[index].commentcount = newCommentCount;
}, },
async toggleCommentsVisibility(index, postid) {// async toggleCommentsVisibility(index, postid) {//
this.$message("评论区展开" + index); this.$message("评论区展开" + index);
try { try {
const response = await axios.get(`/comments/postid=${postid}`); const comments = await axios.get(`/comments/postid=${postid}`);
this.checkPosts[index].comments = response;
const commentsWithUsernames = await Promise.all(
comments.map(async (comment) => {
const { userid } = comment;
try {
//
const userResponse = await axios.get(`/user/info/${userid}/editInfo`);
const username = userResponse.username; // response.data.username
//
return {
...comment,
username
};
} catch (userError) {
console.error(`Error fetching username for userid ${userid}:`, userError);
return {
...comment,
username: 'Unknown' //
};
}
})
);
this.checkPosts[index].comments = commentsWithUsernames;
this.checkPosts[index].isCommentsVisible = !this.checkPosts[index].isCommentsVisible; this.checkPosts[index].isCommentsVisible = !this.checkPosts[index].isCommentsVisible;
} catch (error) { } catch (error) {
@ -368,7 +417,7 @@
async addComment(index, commentText, postid) {// async addComment(index, commentText, postid) {//
try { try {
const response = await axios.post('http://localhost:8082/loveforest/comments/addcomments', { const response = await axios.post('/comments/addcomments', {
userid: this.userid, userid: this.userid,
postid: postid, postid: postid,
content: commentText content: commentText
@ -378,20 +427,20 @@
'Accept': 'application/json' 'Accept': 'application/json'
} }
}); });
if (response.startsWith ("评论成功!")) { if (response.startsWith("评论成功!")) {
this.$message.success("评论成功!"); this.$message.success("评论成功!");
const id = response.replace("评论成功!", '').trim(); const id = response.replace("评论成功!", '').trim();
this.checkPosts[index].comments.push({ this.checkPosts[index].comments.push({
username: '用户名',//user username: '用户名',//user
postid: postid, postid: postid,
content: commentText, content: commentText,
commentid:id, commentid: id,
userid:this.userid userid: this.userid
}); });
this.checkPosts[index].commentCount += 1; this.checkPosts[index].commentCount += 1;
} }
else { else {
this.$message.error(response.data); this.$message.error(response);
} }
} catch (error) { } catch (error) {

Loading…
Cancel
Save