社区修改接口和bug

main
QMZ 1 month ago
parent 273f4ff864
commit 61ab1d2c55

@ -51,7 +51,7 @@
<transition name="fade" @before-enter="beforeEnter" @enter="enter" @leave="leave">
<div v-if="isCommentsVisible" class="comments-section">
<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>
<!-- 发布评论 -->
@ -128,14 +128,14 @@
if (this.followsbuttonActive == false) {
try {
const response = await axios.post(`http://localhost:8082/loveforest/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response.data === "关注成功!") {
const response = await axios.post(`/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response === "关注成功!") {
this.$message.success(response.data);
this.$message.success(response);
this.followsbuttonActive = true;
}
else {
this.$message.error(response.data);
this.$message.error(response);
}
} catch (error) {
@ -149,14 +149,14 @@
else {
try {
const response = await axios.delete(`http://localhost:8082/loveforest/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response.data === "取消关注成功!") {
this.$message.success(response.data);
const response = await axios.delete(`/Myfollows/userid=${useride}/myfollowid=${this.postuserid}`);
if (response === "取消关注成功!") {
this.$message.success(response);
this.followsbuttonActive = false;
}
else {
this.$message.error(response.data);
this.$message.error(response);
}
} catch (error) {
@ -180,15 +180,15 @@
async increaseLikeCount() {//
if (!this.isLiked) {//
try {
const response = await axios.post(`http://localhost:8082/loveforest/likes/userid=${this.userid}/postid=${this.postid}`);
if (response.data === "点赞成功!") {
this.$message.success(response.data);
const response = await axios.post(`/likes/userid=${this.userid}/postid=${this.postid}`);
if (response === "点赞成功!") {
this.$message.success(response);
this.$emit('updateLikeCount', this.likeCount + 1);
this.isLiked = !this.isLiked;
}
else {
this.$message.error(response.data);
this.$message.error(response);
}
} catch (error) {
@ -198,8 +198,8 @@
}
else {//
try {
const response = await axios.delete(`http://localhost:8082/loveforest/likes/userid=${this.userid}/postid=${this.postid}`);
if (response.data === "取消点赞成功!") {
const response = await axios.delete(`/likes/userid=${this.userid}/postid=${this.postid}`);
if (response === "取消点赞成功!") {
this.$message.error("取消点赞成功");
this.$emit('updateLikeCount', this.likeCount - 1);
@ -207,7 +207,7 @@
}
else {
this.$message.error(response.data);
this.$message.error(response);
}
} 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%;"
@mouseover="hoverIndex = index" @mouseleave="hoverIndex = -1" @click="fllowsClick(follow.myfollowid,index)"
:class="{'selected': selectedIndex === index}">
<img class="touxiang" src="../../assets/pictures/touxiang.png" style="left:20%;width: 15%; height: auto;" />
<div style="margin-left: 40px; font-weight: bold; font-size: 16px;">{{ follow.myfollowid }}</div>
<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.username }}</div>
<el-tag v-if="follow.newpostnum" effect="plain" round style="position: absolute; right:0%">
{{follow.newpostnum}}条新动态
</el-tag>
@ -143,7 +143,7 @@
import PostCard from './PostCard.vue';
import PostForm from './Postform.vue';
import axios from '@/utils/axiosConfig';
import {getUserId} from '@/token/auth'
import { getUserId } from '@/token/auth'
export default {
name: 'CommunityIndex', //
components: { PostCard, PostForm },
@ -192,8 +192,8 @@
async loadData() {
try {
this.userid= getUserId();
this.userid = getUserId();
//
await this.fllowlist();
await this.loadhotpost();
@ -209,37 +209,60 @@
},
async fllowlist() {
const userid = this.userid;//id
axios.get(`http://localhost:8082/loveforest/Myfollows/userid=${userid}`)
.then(response => {
this.myfollows.splice(0, this.myfollows.length);
this.myfollows.push(...response.data);
return response.data;
})
.catch(error => {
console.error('Error:', error);
});
const userid = this.userid; // ID
try {
// follow
const response = await axios.get(`/Myfollows/userid=${userid}`);
// follow
this.myfollows.splice(0, this.myfollows.length);
// follow
const followsWithUserInfo = await Promise.all(
response.map(async (follow) => {
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() {//
if (this.isloading) {
try {
const response = await axios.get(`http://localhost:8082/loveforest/posts`, {
const response = await axios.get(`/posts`, {
params: {
page: this.page,
size: 5,
},
});
const filteredPostsList = response.data.records;
const filteredPostsList = response.records;
this.$message("动态加载中page" + this.page);
@ -256,10 +279,10 @@
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.checkPosts.splice(0, this.checkPosts.length);
this.checkPosts.push(response.data);
this.checkPosts.push(response);
} catch (error) {
@ -271,13 +294,13 @@
async loaduserlikes() {//user
const userid = this.userid;//id
axios.get(`http://localhost:8082/loveforest/likes/userid=${userid}`)
axios.get(`/likes/userid=${userid}`)
.then(response => {
this.userlikelist.splice(0, this.myfollows.length);
this.userlikelist.push(...response.data);
this.userlikelist.push(...response);
return response.data;
return response;
})
.catch(error => {
console.error('Error:', error);
@ -294,11 +317,12 @@
this.selectedIndex = -1;
},
async loadhotpost() {//
try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/topposts`);
this.HotsearchList.push(...response.data);
console.log(response.data);
const response = await axios.get(`/posts/topposts`);
this.HotsearchList.push(...response);
console.log(response);
} catch (error) {
this.$message.error("热门动态获取失败");
@ -309,8 +333,8 @@
async loadhotfamilystory() {//
try {
const response = await axios.get(`http://localhost:8082/loveforest/posts/topfamilystory`);
this.familystories.push(...response.data);
const response = await axios.get(`/posts/topfamilystory`);
this.familystories.push(...response);
} catch (error) {
@ -326,12 +350,12 @@
this.selectedIndex = index; //
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.checkPosts.splice(0, this.checkPosts.length);
this.checkPosts.push(...response.data);
if (response.data.length === 0) {
this.checkPosts.push(...response);
if (response.length === 0) {
this.$message("对方还没有发过动态哦");
}
@ -350,12 +374,37 @@
updateCommentCount(index, newCommentCount) {//
this.checkPosts[index].commentcount = newCommentCount;
},
async toggleCommentsVisibility(index, postid) {//
this.$message("评论区展开" + index);
try {
const response = await axios.get(`/comments/postid=${postid}`);
this.checkPosts[index].comments = response;
const comments = await axios.get(`/comments/postid=${postid}`);
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;
} catch (error) {
@ -368,7 +417,7 @@
async addComment(index, commentText, postid) {//
try {
const response = await axios.post('http://localhost:8082/loveforest/comments/addcomments', {
const response = await axios.post('/comments/addcomments', {
userid: this.userid,
postid: postid,
content: commentText
@ -378,20 +427,20 @@
'Accept': 'application/json'
}
});
if (response.startsWith ("评论成功!")) {
if (response.startsWith("评论成功!")) {
this.$message.success("评论成功!");
const id = response.replace("评论成功!", '').trim();
this.checkPosts[index].comments.push({
username: '用户名',//user
postid: postid,
content: commentText,
commentid:id,
userid:this.userid
commentid: id,
userid: this.userid
});
this.checkPosts[index].commentCount += 1;
}
else {
this.$message.error(response.data);
this.$message.error(response);
}
} catch (error) {

Loading…
Cancel
Save