fix: 修复个人中心不显示新发表的评论问题
问题描述: - 用户在事件中心发表评论后,打开个人中心看不到新评论 - 个人中心"我的评论"区域始终为空或显示旧数据 根本原因: - 项目存在两套独立的评论系统: 1. 旧系统(EventComment 表)- 个人中心查询此表 2. 新系统(Post 表)- 事件中心写入此表 - 创建评论时写入 Post 表,但个人中心查询 EventComment 表 - 两个表完全独立,数据不同步 修复方案(统一到 Post 系统): 1. 后端新增 API:GET /api/account/events/posts - 查询 Post 表中当前用户的所有评论 - 返回格式完全兼容旧 EventComment.to_dict() - 新增 event_title 字段(改进点,旧 API 没有) 2. 前端修改 API 调用:Center.js - 将 /api/account/events/comments 改为 /api/account/events/posts - 无需修改数据渲染逻辑(格式兼容) 修改文件: - app.py (第 4144-4187 行) - 新增 get_my_event_posts API - 查询 Post 表(user_id 过滤 + 按时间倒序) - JOIN 查询关联的 Event(获取 event_title) - 返回兼容格式:author(字符串), likes, created_at, event_title - src/views/Dashboard/Center.js (第 105 行) - 修改 API 调用路径 - 修改前:GET /api/account/events/comments - 修改后:GET /api/account/events/posts 数据兼容性: - author 字段:字符串类型(与旧 EventComment 一致) - likes 字段:映射自 likes_count - created_at 字段:ISO 8601 格式 - 新增:event_title 字段(个人中心可显示评论关联的事件) 修复效果: - 用户在事件中心发表评论 → 立即在个人中心看到新评论 ✅ - 评论显示完整信息:内容、时间、关联事件标题 ✅ - 前端无需修改渲染逻辑(完全兼容) ✅ 🤖 Generated with Claude Code
This commit is contained in:
@@ -102,7 +102,7 @@ export default function CenterDashboard() {
|
||||
const [w, e, c] = await Promise.all([
|
||||
fetch(base + `/api/account/watchlist?_=${ts}`, { credentials: 'include', cache: 'no-store', headers: { 'Cache-Control': 'no-cache' } }),
|
||||
fetch(base + `/api/account/events/following?_=${ts}`, { credentials: 'include', cache: 'no-store', headers: { 'Cache-Control': 'no-cache' } }),
|
||||
fetch(base + `/api/account/events/comments?_=${ts}`, { credentials: 'include', cache: 'no-store', headers: { 'Cache-Control': 'no-cache' } }),
|
||||
fetch(base + `/api/account/events/posts?_=${ts}`, { credentials: 'include', cache: 'no-store', headers: { 'Cache-Control': 'no-cache' } }),
|
||||
]);
|
||||
const jw = await w.json();
|
||||
const je = await e.json();
|
||||
|
||||
Reference in New Issue
Block a user