Merge remote-tracking branch 'refs/remotes/origin/master'
Change-Id: I599f5959d217e7cb51cf76233b2409b34d49abca
diff --git a/Merge/back_jwlll/__pycache__/word2vec_helper.cpython-312.pyc b/Merge/back_jwlll/__pycache__/word2vec_helper.cpython-312.pyc
new file mode 100644
index 0000000..2be1048
--- /dev/null
+++ b/Merge/back_jwlll/__pycache__/word2vec_helper.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/__pycache__/config.cpython-312.pyc b/Merge/back_trm/__pycache__/config.cpython-312.pyc
new file mode 100644
index 0000000..72018e2
--- /dev/null
+++ b/Merge/back_trm/__pycache__/config.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..10ec6ee
--- /dev/null
+++ b/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/__pycache__/routes.cpython-312.pyc b/Merge/back_trm/app/__pycache__/routes.cpython-312.pyc
new file mode 100644
index 0000000..5e75b26
--- /dev/null
+++ b/Merge/back_trm/app/__pycache__/routes.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-312.pyc b/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-312.pyc
new file mode 100644
index 0000000..dd9391d
--- /dev/null
+++ b/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/functions/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/app/functions/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..8e3382e
--- /dev/null
+++ b/Merge/back_trm/app/functions/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..fdafc61
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/logs.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/logs.cpython-312.pyc
new file mode 100644
index 0000000..a9846f5
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/logs.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/post.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/post.cpython-312.pyc
new file mode 100644
index 0000000..c7516cc
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/post.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/syscost.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/syscost.cpython-312.pyc
new file mode 100644
index 0000000..bb81dd0
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/syscost.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/topics.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/topics.cpython-312.pyc
new file mode 100644
index 0000000..658c0cd
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/topics.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/users.cpython-312.pyc b/Merge/back_trm/app/models/__pycache__/users.cpython-312.pyc
new file mode 100644
index 0000000..afa2197
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/users.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/logs.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/logs.cpython-312.pyc
new file mode 100644
index 0000000..2f17c9c
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/logs.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/syscost.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/syscost.cpython-312.pyc
new file mode 100644
index 0000000..19df843
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/syscost.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc b/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc
index 1787ef1..729675c 100644
--- a/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc
+++ b/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/utils/__pycache__/Fpost.cpython-312.pyc b/Merge/back_wzy/utils/__pycache__/Fpost.cpython-312.pyc
new file mode 100644
index 0000000..c0d1153
--- /dev/null
+++ b/Merge/back_wzy/utils/__pycache__/Fpost.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/utils/__pycache__/__init__.cpython-312.pyc b/Merge/back_wzy/utils/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..da13bfc
--- /dev/null
+++ b/Merge/back_wzy/utils/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/front/src/api/README.md b/Merge/front/src/api/README.md
new file mode 100644
index 0000000..567d772
--- /dev/null
+++ b/Merge/front/src/api/README.md
@@ -0,0 +1,109 @@
+# API 服务修改说明
+
+## 修改概述
+
+根据要求,仅首页的推荐和搜索功能使用 `back_jwlll` 服务,其他功能使用已有的其他后端服务。
+
+## 服务分工
+
+### JWLLL 服务 (端口 5000)
+**仅用于首页推荐和搜索功能**
+- 搜索内容 (`/search`)
+- 获取用户标签 (`/user_tags`)
+- 标签推荐 (`/recommend_tags`)
+- 协同过滤推荐 (`/user_based_recommend`)
+
+### WZY 服务 (端口 5714)
+**用于帖子相关功能**
+- 帖子详情查看 (`/posts/{id}`)
+- 帖子创建/更新/删除 (`/posts`)
+- 点赞功能 (`/posts/{id}/like`)
+- 评论功能 (`/posts/{id}/comments`)
+
+### LJC 服务 (端口 5715)
+**用于用户相关功能**
+- 用户信息管理 (`/api/user/{id}`)
+- 关注功能 (`/api/follow/{id}`)
+- 收藏功能 (`/api/user/{id}/favorites`)
+
+### TRM 服务 (端口 5713)
+**用于审核相关功能**
+- 帖子审核 (`/areview`)
+- 管理员功能 (`/apostlist`)
+
+## 修改的文件
+
+### 1. `/src/api/search_jwlll.js`
+- **修改内容**: 重构API调用,推荐搜索功能继续使用JWLLL服务,其他功能重定向到相应服务
+- **主要变更**:
+ - 搜索和推荐API仍使用 `http://127.0.0.1:5000`
+ - 帖子详情、点赞、评论、上传功能改用 WZY 服务 `http://10.126.59.25:5714`
+ - 添加数据格式适配逻辑
+
+### 2. `/src/api/posts_api.js` (新增)
+- **作用**: 提供统一的帖子相关API接口
+- **功能**: 整合不同后端服务的帖子和用户功能
+
+## 数据格式适配
+
+### 评论数据适配
+- **WZY服务返回**: `{id, user_id, content, created_at, replies}`
+- **前端期望**: `{id, user_name, content, create_time}`
+- **适配方案**: 在 `getComments` 方法中进行字段映射
+
+### 帖子上传适配
+- **前端数据**: `{title, content, tags, category, type, media_files}`
+- **WZY服务期望**: `{title, content, type, media_urls, status}`
+- **适配方案**: 在 `uploadPost` 方法中进行数据转换
+
+## 影响的组件
+
+### 自动适配的组件
+- `HomeFeed.jsx` - 推荐和搜索功能,继续使用JWLLL服务
+- `PostDetailJWLLL.jsx` - 帖子详情、点赞、评论功能,自动切换到WZY服务
+- `UploadPageJWLLL.jsx` - 帖子上传功能,自动切换到WZY服务
+
+### 使用新API的组件
+如需要,其他组件可以导入 `posts_api.js` 来使用统一的帖子和用户API。
+
+## 注意事项
+
+1. **标签功能限制**: WZY服务暂不完全支持标签功能,上传帖子时标签信息会被忽略
+2. **用户名显示**: 评论中的用户名使用 `用户{user_id}` 格式生成
+3. **服务兼容性**: 确保所有后端服务都正常运行且端口配置正确
+4. **错误处理**: 各服务的错误响应格式可能不同,前端已添加通用错误处理
+
+## 测试建议
+
+### 测试文件
+提供了 `test_api.js` 文件来验证API服务分工是否正确:
+
+```javascript
+import { runAllTests } from './test_api.js'
+
+// 运行所有测试
+runAllTests()
+```
+
+### 手动测试步骤
+1. **首页搜索测试**
+ - 在首页搜索框输入关键词
+ - 验证搜索结果来自 JWLLL 服务
+ - 测试推荐功能是否正常
+
+2. **帖子详情测试**
+ - 点击帖子进入详情页
+ - 验证帖子数据来自 WZY 服务
+ - 测试点赞、评论功能
+
+3. **帖子上传测试**
+ - 使用上传页面发布新帖子
+ - 验证上传请求发送到 WZY 服务
+ - 确认数据格式转换正确
+
+### 服务状态检查
+确保以下服务正常运行:
+- JWLLL 服务: `curl http://127.0.0.1:5000/word2vec_status`
+- WZY 服务: `curl http://10.126.59.25:5714/posts`
+- LJC 服务: `curl http://10.126.59.25:5715/api/current-user`
+- TRM 服务: `curl http://10.126.59.25:5713/health` (如果有)
diff --git a/Merge/front/src/api/posts_api.js b/Merge/front/src/api/posts_api.js
new file mode 100644
index 0000000..a336da0
--- /dev/null
+++ b/Merge/front/src/api/posts_api.js
@@ -0,0 +1,136 @@
+// 帖子相关API接口
+// 整合不同后端服务的帖子功能
+
+// WZY 后端服务 - 帖子CRUD、点赞、评论
+const WZY_BASE_URL = 'http://10.126.59.25:5714'
+// LJC 后端服务 - 用户相关功能
+const LJC_BASE_URL = 'http://10.126.59.25:5715'
+
+// 通用请求函数
+const request = async (url, options = {}) => {
+ try {
+ const response = await fetch(url, {
+ headers: {
+ 'Content-Type': 'application/json',
+ ...options.headers
+ },
+ ...options
+ })
+ return await response.json()
+ } catch (error) {
+ console.error('API请求错误:', error)
+ throw error
+ }
+}
+
+// 帖子相关API
+export const postsAPI = {
+ // ===== 帖子基础功能 - 使用 WZY 服务 =====
+
+ // 获取帖子列表
+ fetchPosts: async (userId = null) => {
+ const url = userId ? `${WZY_BASE_URL}/posts?user_id=${userId}` : `${WZY_BASE_URL}/posts`
+ return await request(url)
+ },
+
+ // 获取帖子详情
+ fetchPost: async (postId) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}`)
+ },
+
+ // 创建帖子
+ createPost: async (postData) => {
+ return await request(`${WZY_BASE_URL}/posts`, {
+ method: 'POST',
+ body: JSON.stringify(postData)
+ })
+ },
+
+ // 更新帖子
+ updatePost: async (postId, postData) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}`, {
+ method: 'PUT',
+ body: JSON.stringify(postData)
+ })
+ },
+
+ // 删除帖子
+ deletePost: async (postId) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}`, {
+ method: 'DELETE'
+ })
+ },
+
+ // ===== 互动功能 - 使用 WZY 服务 =====
+
+ // 点赞帖子
+ likePost: async (postId, userId) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+ method: 'POST',
+ body: JSON.stringify({ user_id: userId })
+ })
+ },
+
+ // 取消点赞
+ unlikePost: async (postId, userId) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+ method: 'DELETE',
+ body: JSON.stringify({ user_id: userId })
+ })
+ },
+
+ // 添加评论
+ addComment: async (postId, userId, content, parentId = null) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/comments`, {
+ method: 'POST',
+ body: JSON.stringify({
+ user_id: userId,
+ content,
+ parent_id: parentId
+ })
+ })
+ },
+
+ // 获取评论列表
+ fetchComments: async (postId) => {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/comments`)
+ },
+
+ // ===== 用户相关功能 - 使用 LJC 服务 =====
+
+ // 获取用户信息
+ getCurrentUser: async () => {
+ return await request(`${LJC_BASE_URL}/api/current-user`)
+ },
+
+ // 获取用户详情
+ getUser: async (userId) => {
+ return await request(`${LJC_BASE_URL}/api/user/${userId}`)
+ },
+
+ // 获取用户帖子
+ getUserPosts: async (userId) => {
+ return await request(`${LJC_BASE_URL}/api/user/${userId}/posts`)
+ },
+
+ // 关注用户
+ followUser: async (followeeId) => {
+ return await request(`${LJC_BASE_URL}/api/follow/${followeeId}`, {
+ method: 'POST'
+ })
+ },
+
+ // 取消关注
+ unfollowUser: async (followeeId) => {
+ return await request(`${LJC_BASE_URL}/api/follow/${followeeId}`, {
+ method: 'DELETE'
+ })
+ },
+
+ // 获取收藏列表
+ getFavorites: async (userId) => {
+ return await request(`${LJC_BASE_URL}/api/user/${userId}/favorites`)
+ }
+}
+
+export default postsAPI
diff --git a/Merge/front/src/api/search_jwlll.js b/Merge/front/src/api/search_jwlll.js
index 7568f1d..085507b 100644
--- a/Merge/front/src/api/search_jwlll.js
+++ b/Merge/front/src/api/search_jwlll.js
@@ -1,7 +1,11 @@
// 搜索推荐算法相关的API接口
-// 对应 JWLLL 后端服务
+// 仅首页推荐和搜索使用 JWLLL 后端服务
+// 其他功能使用对应的后端服务
-const BASE_URL = 'http://10.126.59.25:5717'
+// JWLLL 后端服务 - 仅用于推荐和搜索
+const JWLLL_BASE_URL = 'http://10.126.59.25:5717'
+// WZY 后端服务 - 用于帖子详情、点赞、评论等
+const WZY_BASE_URL = 'http://10.126.59.25:5714'
// 通用请求函数
const request = async (url, options = {}) => {
@@ -20,11 +24,13 @@
}
}
-// 搜索API
+// 搜索推荐API
export const searchAPI = {
+ // ===== 推荐和搜索功能 - 使用 JWLLL 服务 =====
+
// 搜索内容
search: async (keyword, category = undefined) => {
- return await request(`${BASE_URL}/search`, {
+ return await request(`${JWLLL_BASE_URL}/search`, {
method: 'POST',
body: JSON.stringify({ keyword, category })
})
@@ -32,12 +38,12 @@
// 获取用户标签
getUserTags: async (userId) => {
- return await request(`${BASE_URL}/user_tags?user_id=${userId}`)
+ return await request(`${JWLLL_BASE_URL}/user_tags?user_id=${userId}`)
},
// 标签推荐
recommendByTags: async (userId, tags) => {
- return await request(`${BASE_URL}/recommend_tags`, {
+ return await request(`${JWLLL_BASE_URL}/recommend_tags`, {
method: 'POST',
body: JSON.stringify({ user_id: userId, tags })
})
@@ -45,52 +51,73 @@
// 协同过滤推荐
userBasedRecommend: async (userId, topN = 20) => {
- return await request(`${BASE_URL}/user_based_recommend`, {
+ return await request(`${JWLLL_BASE_URL}/user_based_recommend`, {
method: 'POST',
body: JSON.stringify({ user_id: userId, top_n: topN })
})
},
+ // ===== 其他功能 - 使用 WZY 服务 =====
+
// 获取帖子详情
getPostDetail: async (postId) => {
- return await request(`${BASE_URL}/post/${postId}`)
+ return await request(`${WZY_BASE_URL}/posts/${postId}`)
},
-
// 点赞帖子
likePost: async (postId, userId) => {
- return await request(`${BASE_URL}/like`, {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId })
+ body: JSON.stringify({ user_id: userId })
})
},
// 取消点赞
unlikePost: async (postId, userId) => {
- return await request(`${BASE_URL}/unlike`, {
- method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId })
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+ method: 'DELETE',
+ body: JSON.stringify({ user_id: userId })
})
},
// 添加评论
addComment: async (postId, userId, content) => {
- return await request(`${BASE_URL}/comment`, {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/comments`, {
method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId, content })
+ body: JSON.stringify({ user_id: userId, content })
})
- },
-
- // 获取评论
+ }, // 获取评论
getComments: async (postId) => {
- return await request(`${BASE_URL}/comments/${postId}`)
+ const comments = await request(`${WZY_BASE_URL}/posts/${postId}/comments`)
+ // 适配数据格式,WZY服务返回数组,而前端期望 {comments: [...]}
+ // 同时转换字段名以适配前端期望的格式
+ const adaptedComments = Array.isArray(comments) ? comments.map(comment => ({
+ ...comment,
+ user_name: comment.user_name || `用户${comment.user_id}`, // 如果没有用户名,使用用户ID生成
+ create_time: comment.created_at // 将 created_at 映射为 create_time
+ })) : []
+ return { comments: adaptedComments }
},
-
// 上传帖子
uploadPost: async (postData) => {
- return await request(`${BASE_URL}/upload`, {
+ // 转换数据格式以适配 WZY 服务
+ const payload = {
+ user_id: postData.user_id || 1, // 默认用户ID
+ title: postData.title,
+ content: postData.content,
+ type: postData.type || 'text', // 默认为文本类型
+ media_urls: postData.media_files || [],
+ status: 'published' // 直接发布,不需要审核
+ }
+
+ const result = await request(`${WZY_BASE_URL}/posts`, {
method: 'POST',
- body: JSON.stringify(postData)
+ body: JSON.stringify(payload)
})
+
+ // 注意:WZY 服务目前不支持标签功能,tags 会被忽略
+ // 如果需要标签功能,需要额外的API调用或使用支持标签的服务
+
+ return result
}
}
diff --git a/Merge/front/src/components/HomeFeed.jsx b/Merge/front/src/components/HomeFeed.jsx
index e32a2eb..cc37642 100644
--- a/Merge/front/src/components/HomeFeed.jsx
+++ b/Merge/front/src/components/HomeFeed.jsx
@@ -5,6 +5,7 @@
import { ThumbsUp } from 'lucide-react'
import { fetchPosts, fetchPost } from '../api/posts_wzy'
import { searchAPI } from '../api/search_jwlll'
+import { getUserInfo } from '../utils/auth'
import '../style/HomeFeed.css'
const categories = [
@@ -17,11 +18,17 @@
{ label: '协同过滤推荐', value: 'cf' }
]
-const DEFAULT_USER_ID = '3' // 确保数据库有此用户
+const DEFAULT_USER_ID = '3' // 确保数据库有此用户(作为回退值)
const DEFAULT_TAGS = ['美食','影视','穿搭'] // 可根据实际数据库调整
export default function HomeFeed() {
const navigate = useNavigate()
+
+ // 获取当前用户ID,如果未登录则使用默认值
+ const getCurrentUserId = () => {
+ const userInfo = getUserInfo()
+ return userInfo?.id ? String(userInfo.id) : DEFAULT_USER_ID
+ }
const [activeCat, setActiveCat] = useState('推荐')
const [items, setItems] = useState([])
const [loading, setLoading] = useState(true)
@@ -55,13 +62,13 @@
}
setLoading(false)
}, [activeCat])
-
// 标签推荐
const fetchTagRecommend = useCallback(async (tags) => {
setLoading(true)
setError(null)
try {
- const data = await searchAPI.recommendByTags(DEFAULT_USER_ID, tags)
+ const currentUserId = getCurrentUserId()
+ const data = await searchAPI.recommendByTags(currentUserId, tags)
const formattedItems = (data.recommendations || []).map(item => ({
id: item.id,
title: item.title,
@@ -79,13 +86,13 @@
}
setLoading(false)
}, [])
-
// 协同过滤推荐
const fetchCFRecommend = useCallback(async (topN = recCFNum) => {
setLoading(true)
setError(null)
try {
- const data = await searchAPI.userBasedRecommend(DEFAULT_USER_ID, topN)
+ const currentUserId = getCurrentUserId()
+ const data = await searchAPI.userBasedRecommend(currentUserId, topN)
const formattedItems = (data.recommendations || []).map(item => ({
id: item.id,
title: item.title,
@@ -103,14 +110,14 @@
}
setLoading(false)
}, [recCFNum])
-
// 获取用户兴趣标签后再推荐
const fetchUserTagsAndRecommend = useCallback(async () => {
setLoading(true)
setError(null)
let tags = []
try {
- const data = await searchAPI.getUserTags(DEFAULT_USER_ID)
+ const currentUserId = getCurrentUserId()
+ const data = await searchAPI.getUserTags(currentUserId)
tags = Array.isArray(data.tags) && data.tags.length > 0 ? data.tags : DEFAULT_TAGS
} catch {
tags = DEFAULT_TAGS
diff --git a/Merge/front/src/components/PostDetailJWLLL.jsx b/Merge/front/src/components/PostDetailJWLLL.jsx
index 0dc7289..009ba6c 100644
--- a/Merge/front/src/components/PostDetailJWLLL.jsx
+++ b/Merge/front/src/components/PostDetailJWLLL.jsx
@@ -1,7 +1,8 @@
-import React, { useState, useEffect } from 'react'
+import React, { useState, useEffect, useCallback } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { ArrowLeft, ThumbsUp, MessageCircle, Share2, BookmarkPlus, Heart, Eye } from 'lucide-react'
import { searchAPI } from '../api/search_jwlll'
+import { getUserInfo } from '../utils/auth'
import '../style/PostDetail.css'
export default function PostDetail() {
@@ -16,15 +17,13 @@
const [comments, setComments] = useState([])
const [newComment, setNewComment] = useState('')
const [showComments, setShowComments] = useState(false)
+ // 获取当前用户ID
+ const getCurrentUserId = () => {
+ const userInfo = getUserInfo()
+ return userInfo?.id || '3' // 如果未登录或无用户信息,使用默认值3
+ }
- const DEFAULT_USER_ID = '3' // 默认用户ID
-
- useEffect(() => {
- fetchPostDetail()
- fetchComments()
- }, [id])
-
- const fetchPostDetail = async () => {
+ const fetchPostDetail = useCallback(async () => {
setLoading(true)
setError(null)
try {
@@ -37,28 +36,33 @@
} finally {
setLoading(false)
}
- }
+ }, [id])
- const fetchComments = async () => {
+ const fetchComments = useCallback(async () => {
try {
const data = await searchAPI.getComments(id)
setComments(data.comments || [])
} catch (error) {
console.error('获取评论失败:', error)
}
- }
+ }, [id])
+
+ useEffect(() => {
+ fetchPostDetail()
+ fetchComments()
+ }, [fetchPostDetail, fetchComments])
const handleBack = () => {
navigate(-1)
}
-
const handleLike = async () => {
try {
+ const currentUserId = getCurrentUserId()
const newLiked = !liked
if (newLiked) {
- await searchAPI.likePost(id, DEFAULT_USER_ID)
+ await searchAPI.likePost(id, currentUserId)
} else {
- await searchAPI.unlikePost(id, DEFAULT_USER_ID)
+ await searchAPI.unlikePost(id, currentUserId)
}
setLiked(newLiked)
setLikeCount(prev => newLiked ? prev + 1 : prev - 1)
@@ -89,13 +93,13 @@
alert('链接已复制到剪贴板')
}
}
-
const handleAddComment = async (e) => {
e.preventDefault()
if (!newComment.trim()) return
try {
- await searchAPI.addComment(id, DEFAULT_USER_ID, newComment)
+ const currentUserId = getCurrentUserId()
+ await searchAPI.addComment(id, currentUserId, newComment)
setNewComment('')
fetchComments() // 刷新评论列表
} catch (error) {
diff --git a/Merge/front/src/components/UploadPageJWLLL.jsx b/Merge/front/src/components/UploadPageJWLLL.jsx
index 2d9ee7d..475fe2f 100644
--- a/Merge/front/src/components/UploadPageJWLLL.jsx
+++ b/Merge/front/src/components/UploadPageJWLLL.jsx
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import { Image, Video, Send } from 'lucide-react'
import { searchAPI } from '../api/search_jwlll'
+import { getUserInfo } from '../utils/auth'
import '../style/UploadPage.css'
const categories = [
@@ -14,15 +15,18 @@
const [isUploading, setIsUploading] = useState(false)
const [uploadedFiles, setUploadedFiles] = useState([])
const [uploadProgress, setUploadProgress] = useState(0)
-
- // 新增表单字段
+ // 新增表单字段
const [title, setTitle] = useState('')
const [content, setContent] = useState('')
const [tags, setTags] = useState('')
const [category, setCategory] = useState(categories[0])
const [isPublishing, setIsPublishing] = useState(false)
- const DEFAULT_USER_ID = '3' // 默认用户ID
+ // 获取当前用户ID
+ const getCurrentUserId = () => {
+ const userInfo = getUserInfo()
+ return userInfo?.id || 3 // 如果未登录或无用户信息,使用默认值3(注意这里是数字类型)
+ }
const validateFiles = files => {
const imgTypes = ['image/jpeg','image/jpg','image/png','image/webp']
@@ -91,12 +95,11 @@
if (!content.trim()) {
alert('请输入内容')
return
- }
-
- setIsPublishing(true)
+ } setIsPublishing(true)
try {
+ const currentUserId = getCurrentUserId()
const postData = {
- user_id: DEFAULT_USER_ID,
+ user_id: currentUserId,
title: title.trim(),
content: content.trim(),
tags: tags.split(',').map(t => t.trim()).filter(t => t),
diff --git a/Merge/front/src/utils/test_user_id.js b/Merge/front/src/utils/test_user_id.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Merge/front/src/utils/test_user_id.js
diff --git "a/\346\216\245\345\217\243\350\257\264\346\230\216\346\226\207\346\241\243.pdf" "b/\346\216\245\345\217\243\350\257\264\346\230\216\346\226\207\346\241\243.pdf"
new file mode 100644
index 0000000..66ffcb9
--- /dev/null
+++ "b/\346\216\245\345\217\243\350\257\264\346\230\216\346\226\207\346\241\243.pdf"
Binary files differ