diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml
index 7cae4ed..00a8f8c 100644
--- a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml
+++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml
@@ -1,21 +1,21 @@
##本地开发环境
-lj:
- db:
- host: 192.168.59.129
- password: Forely123!
- redis:
- host: 192.168.59.129
- port: 6379
- password: Forely123!
- rabbitmq:
- host: 192.168.59.129
- port: 5672
- username: admin
- password: Forely123!
- minio:
- endpoint: http://192.168.59.129:9000
- accessKey: forely
- secretKey: Forely123!
+#lj:
+# db:
+# host: 192.168.59.129
+# password: Forely123!
+# redis:
+# host: 192.168.59.129
+# port: 6379
+# password: Forely123!
+# rabbitmq:
+# host: 192.168.59.129
+# port: 5672
+# username: admin
+# password: Forely123!
+# minio:
+# endpoint: http://192.168.59.129:9000
+# accessKey: forely
+# secretKey: Forely123!
#lj:
# db:
@@ -33,4 +33,22 @@ lj:
# minio:
# endpoint: http://192.168.125.128:9000
# accessKey: minio_admin
-# secretKey: Minio@1234
\ No newline at end of file
+# secretKey: Minio@1234
+
+lj:
+ db:
+ host: localhost
+ password: 123456
+ redis:
+ host: localhost
+ port: 6379
+ password: 123456
+ rabbitmq:
+ host: localhost
+ port: 5672
+ username: guest
+ password: guest
+ minio:
+ endpoint: http://localhost:9005
+ accessKey: leezt
+ secretKey: lzt264610
diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/db/luojia_channel.sql b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/db/luojia_channel.sql
index f8c0afe..c868a8c 100644
--- a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/db/luojia_channel.sql
+++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/db/luojia_channel.sql
@@ -1,3 +1,4 @@
+USE luojia_channel; -- 指定目标数据库
## 用户表
DROP TABLE IF EXISTS `user`;
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Header.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Header.vue
index 033d092..c0d48b6 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Header.vue
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Header.vue
@@ -92,7 +92,7 @@ const colleges = ref([
]);
// 默认头像
-const defaultAvatar = require("@/assets/default-avatar/boy_4.png");
+const defaultAvatar = require("@/assets/default-avatar/boy_1.png");
// 计算属性
const isLoggedIn = computed(() => userStore.isLoggedIn);
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Login.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Login.vue
index 19e715e..f2bf4bc 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Login.vue
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/Login.vue
@@ -180,17 +180,6 @@ async function sendCode() {
}
-//前端测试登录
-//function Login1() {
-// userStore.login({
-// avatar:require('@/assets/default-avatar/boy_1.png'),
-// userName: '珈人一号',
-// userid:1
-// });
-// emit('LoginSuccess');
-//}
-
-
// 登录
async function login() {
if (!isvalidForm.value) return;
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue
index cb9168b..ef90945 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue
@@ -27,9 +27,9 @@
{{ post.summary }}
- 热度 {{ post.likes }}
+ 浏览量 {{ post.viewCount }}
评论 {{ post.comments }}
- 赞 {{ post.favorites }}
+ 赞 {{ post.likes }}
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js
index b036fd9..e65b5ba 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js
@@ -34,7 +34,7 @@ const routes = [
component: PostDetail
},
{
- path: '/user',
+ path: '/user/:userId',
name: 'UserPage',
component: UserPage,
meta: { requiresAuth: true }
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js
index 49ed6c4..110a493 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js
@@ -2,6 +2,20 @@ import { defineStore } from "pinia";
import request from "@/utils/request";
import { ElMessage } from "element-plus";
+// 递归删除子评论的工具函数
+function removeReply(list, commentId) {
+ for (let i = 0; i < list.length; i++) {
+ if (list[i].id === commentId) {
+ list.splice(i, 1);
+ return true;
+ }
+ if (list[i].replies && list[i].replies.length > 0) {
+ if (removeReply(list[i].replies, commentId)) return true;
+ }
+ }
+ return false;
+}
+
export const usePostDetailStore = defineStore("postDetail", {
state: () => ({
post: null, // 帖子主要信息
@@ -16,67 +30,67 @@ export const usePostDetailStore = defineStore("postDetail", {
commentsFinished: false, // 是否加载完全部评论
}),
actions: {
- // ...existing code...
-async fetchComments() {
- if (this.commentsLoading || this.commentsFinished) return;
- this.commentsLoading = true;
- // 拼接参数到URL
- const params = [
- `lastVal=${this.lastVal}`,
- `offset=${this.offset}`,
- `size=${this.size}`,
- `postId=${this.post.postId}`
- ].join('&');
- const url = `/comment/list?${params}`;
- try {
- const response = await request.get(url);
- if (response.code === 200) {
- // 初始化每条评论的子评论分页状态
- const comments = (response.data.records || []).map(item => ({
- ...item,
- replies: [],
- repliesLastVal: Date.now(),
- repliesOffset: 0,
- repliesSize: 5,
- repliesLoading: false,
- repliesFinished: false,
- }));
- this.comments.push(...comments);
- this.lastVal = response.data.lastVal;
- this.offset = response.data.offset;
- if (comments.length < this.size) {
- this.commentsFinished = true; // 如果评论数少于每页大小,标记为已加载完
+ async fetchComments() {
+ if (this.commentsLoading || this.commentsFinished) return;
+ this.commentsLoading = true;
+ // 拼接参数到URL
+ const params = [
+ `lastVal=${this.lastVal}`,
+ `offset=${this.offset}`,
+ `size=${this.size}`,
+ `postId=${this.post.postId}`
+ ].join('&');
+ const url = `/comment/list?${params}`;
+ try {
+ const response = await request.get(url);
+ if (response.code === 200) {
+ // 初始化每条评论的子评论分页状态
+ const comments = (response.data.records || []).map(item => ({
+ ...item,
+ replies: [],
+ showReplies: false, // 是否显示子评论
+ repliesLastVal: Date.now(),
+ repliesOffset: 0,
+ repliesSize: 5,
+ repliesLoading: false,
+ repliesFinished: false,
+ }));
+ this.comments.push(...comments);
+ this.lastVal = response.data.lastVal;
+ this.offset = response.data.offset;
+ if (comments.length < this.size) {
+ this.commentsFinished = true; // 如果评论数少于每页大小,标记为已加载完
+ }
+ }
+ else {
+ ElMessage({
+ message: '获取评论失败,请稍后重试',
+ type: 'error',
+ duration: 500
+ });
+ }
+ } catch (error) {
+ console.error("获取评论失败:", error);
+ alert(error.response?.message || '获取评论失败,请稍后重试');
+ }finally {
+ this.commentsLoading = false;
}
- }
- else {
- ElMessage({
- message: '获取评论失败,请稍后重试',
- type: 'error',
- duration: 500
- });
- }
- } catch (error) {
- console.error("获取评论失败:", error);
- alert(error.response?.message || '获取评论失败,请稍后重试');
- }finally {
- this.commentsLoading = false;
- }
-},
-// ...existing code...
+ },
// 获取某条评论的子评论
async fetchReplies(parentCommentId, commentObj) {
if (commentObj.repliesLoading || commentObj.repliesFinished) return;
commentObj.repliesLoading = true;
- // 请求子评论数据
- const RequestReplyData = {
- lastVal: commentObj.repliesLastVal,
- offset: commentObj.repliesOffset,
- size: commentObj.repliesSize,
- postId: this.post?.postId,
- parentCommentId: parentCommentId,
- };
+ /// 拼接参数到URL
+ const params = [
+ `lastVal=${commentObj.repliesLastVal}`,
+ `offset=${commentObj.repliesOffset}`,
+ `size=${commentObj.repliesSize}`,
+ `postId=${this.post?.postId}`,
+ `parentCommentId=${parentCommentId}`
+ ].join('&');
+ const url = `/comment/list/reply?${params}`;
try {
- const res = await request.post('/comment/list/reply', RequestReplyData);
+ const res = await request.get(url);
if (res.code === 200) {
const records = (res.data.records || []).map(item => ({
...item,
@@ -106,6 +120,12 @@ async fetchComments() {
async fetchPostDetail(postId) {
this.detailLoading = true;
+ // 先重置评论相关状态,防止串数据
+ this.comments = [];
+ this.lastVal = Date.now();
+ this.offset = 0;
+ this.commentsFinished = false;
+ this.commentsLoading = false;
try {
// 获取帖子详情
const postRes = await request.get('/post/detail', { params: { id: postId } });
@@ -169,15 +189,17 @@ async fetchComments() {
async sendComment(newCommentData) {
if (!newCommentData.content || !this.post?.postId) return;
const RequestData = {
+ id:null,
postId: newCommentData.postId, // 帖子ID
content: newCommentData.content, // 评论内容
parentCommentId: newCommentData.parentCommentId,
};
try {
const res = await request.post('/comment', RequestData);
+ console.log("发送评论返回:", res.data);
if (res.code === 200) {
const commentObj = {
- id: res.data.id,
+ id: res.data,
content: newCommentData.content,
userId: newCommentData.userId,
userName: newCommentData.userName,
@@ -191,6 +213,7 @@ async fetchComments() {
topId: newCommentData.topId,
isLike: 0,
};
+ console.log("发送评论数据:", commentObj.id);
// 新增评论后刷新评论列表或插入到对应位置
if (!newCommentData.parentCommentId) {
// 一级评论,插入到最前面
@@ -201,17 +224,17 @@ async fetchComments() {
commentObj.repliesSize = 5;
commentObj.repliesLoading = false;
commentObj.repliesFinished = false;
- this.comments.unshift(commentObj);
- this.post.commentCount = (this.post.commentCount || 0) + 1; // 更新帖子评论数
+ this.comments.unshift(commentObj);
} else {
// 回复,只插入到一级评论的 replies
- let parent = this.comments.find(c => c.id === newCommentData.parentCommentId);
+ let parent = this.comments.find(c => c.id === newCommentData.topId);
if (parent) {
- parent.replies.unshift(commentObj);
+ parent.replies.push(commentObj);
parent.replyCount = (parent.replyCount || 0) + 1;
}
}
- console.log("评论成功:", res);
+ this.post.commentCount = (this.post.commentCount || 0) + 1; // 更新帖子评论数
+ console.log("评论成功:", commentObj);
}else {
console.error("评论失败:", res);
ElMessage.error(res.message || '评论失败');
@@ -220,5 +243,29 @@ async fetchComments() {
alert(e.response?.message || '发送评论失败,请稍后重试');
}
},
+ // 删除评论或回复
+ async deleteComment(commentId, parentCommentId = null) {
+ try {
+ const res = await request.delete('/comment', { params: { id: commentId} });
+ if (res.code === 200) {
+ // 一级评论
+ if (!parentCommentId) {
+ this.comments = this.comments.filter(c => c.id !== commentId);
+ } else {
+ // 回复评论,递归删除
+ removeReply(this.comments,commentId);
+ }
+ // 更新评论数
+ if (this.post && this.post.commentCount > 0) {
+ this.post.commentCount--;
+ }
+ ElMessage.success('删除成功');
+ } else {
+ ElMessage.error(res.message || '删除失败');
+ }
+ } catch (e) {
+ ElMessage.error(e.response?.message || '删除失败,请稍后重试');
+ }
+ },
},
});
\ No newline at end of file
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postlist.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postlist.js
index fe3835c..1c42d64 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postlist.js
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postlist.js
@@ -52,9 +52,9 @@ export const usePostListStore = defineStore('postList', {
avatar: post.userAvatar || require('@/assets/default-avatar/boy_1.png'),
title: post.title,
summary: post.content ? post.content.slice(0, 40) + (post.content.length > 40 ? '...' : '') : '',
+ viewCount: post.viewCount || 0,
likes: post.likeCount || 0,
comments: post.commentCount || 0,
- favorites: post.favoriteCount || 0,
category: post.category || '全部',
createTime: post.createTime,
userName: post.userName,
@@ -70,6 +70,7 @@ export const usePostListStore = defineStore('postList', {
}
} else {
// 处理错误情况
+
}
} catch (error) {
// 处理异常情况
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue
index 7901987..1f0bbbf 100644
--- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue
+++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue
@@ -2,7 +2,13 @@
-
![头像]()
+
{{ author.userName || '匿名用户' }}
粉丝数:{{ author.followers ?? 0 }}
@@ -18,8 +24,8 @@
{{ postDetailStore.post?.title || '' }}
{{ postDetailStore.post?.content || '' }}
- 热度 {{ postDetailStore.post?.likeCount ?? 0 }}
- 点赞 {{ postDetailStore.post?.favoriteCount ?? 0 }}
+ 浏览量 {{ postDetailStore.post?.viewCount ?? 0 }}
+ 点赞 {{ postDetailStore.post?.likeCount ?? 0 }}
评论 {{ postDetailStore.post?.commentCount ?? 0 }}
@@ -32,7 +38,13 @@
@@ -89,10 +117,12 @@
{{ comment.userName || '匿名用户' }}
{{ comment.content || '' }}
@@ -41,15 +53,26 @@ 赞 {{ comment.likeCount ?? 0 }} ++-
-
+
{{ reply.userName || '匿名用户' }} @@ -60,6 +83,11 @@ {{ reply.createTime ? formatTime(reply.createTime) : '' }} 赞 {{ reply.likeCount ?? 0 }} +