From 2cd90a0604ae4dba194ebde777765f0b48b3a554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Sat, 28 Mar 2026 10:15:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E5=8F=B7=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84v1.2.20=EF=BC=9A=201.=20=E5=8F=91=E5=B8=83=E5=AF=BB?= =?UTF-8?q?=E5=8F=B7=E9=9D=A2=E6=9D=BF=E5=8E=BB=E6=8E=89=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E3=80=81=E5=8C=B9=E9=85=8D=E5=BA=A6=E5=AD=97=E6=AE=B5=202.=20?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E7=A7=BB=E5=88=B0=E6=AD=A3=E6=96=87=E5=89=8D?= =?UTF-8?q?=E9=9D=A2=203.=20=E8=81=94=E7=B3=BB=E6=96=B9=E5=BC=8F=E9=BB=98?= =?UTF-8?q?=E8=AE=A4***=E9=9A=90=E8=97=8F=204.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E7=8A=B6=E6=80=81=E6=8C=89=E9=92=AE=205.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=B9=E9=85=8D=E5=B9=B6=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E8=97=8F=E5=8F=8B=E3=80=81=E7=95=99=E8=A8=80=E8=97=8F=E5=8F=8B?= =?UTF-8?q?=E6=8C=89=E9=92=AE=206.=20=E7=95=99=E8=A8=80=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=8C=E5=96=84=EF=BC=8C=E7=95=99=E8=A8=80=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=B7=E6=96=B0=207.=20=E8=AE=B0=E4=BD=8F=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B5=8F=E8=A7=88=E7=9A=84=E6=A0=87=E7=AD=BE=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 4 ++-- backend/app/models/models.py | 6 +++--- backend/app/routers/information.py | 32 ++++++++++++++++++++++++++++++ config/VERSION | 2 +- frontend/src/pages/News.jsx | 26 ++++++++++++++++++------ 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/VERSION b/VERSION index efe97d8..8bd9cb1 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -VERSION=1.2.18 -# 2026-03-27 寻号功能基础版:寻配号发布、自动配号匹配、我的寻号列表编辑 +VERSION=1.2.19 +# 2026-03-28 寻号功能增强:去掉类型匹配度字段,标题在正文前面,联系方式***隐藏,匹配状态按钮,留言功能 diff --git a/backend/app/models/models.py b/backend/app/models/models.py index b4ba6e7..b35b456 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -195,7 +195,7 @@ class Information(Base): created_at = Column(DateTime(timezone=True), server_default=func.now(), index=True) updated_at = Column(DateTime(timezone=True), onupdate=func.now()) - user = relationship("User") + user = relationship("User", foreign_keys=[user_id]) collection = relationship("Collection") @@ -209,7 +209,7 @@ class InformationComment(Base): content = Column(Text, nullable=False) created_at = Column(DateTime(timezone=True), server_default=func.now()) - user = relationship("User") + user = relationship("User", foreign_keys=[user_id]) # 资讯联系方式查看记录 @@ -221,7 +221,7 @@ class InformationContactView(Base): viewer_id = Column(String(36), ForeignKey("users.f99_90_id", ondelete="CASCADE"), nullable=False, index=True) created_at = Column(DateTime(timezone=True), server_default=func.now()) - viewer = relationship("User") + viewer = relationship("User", foreign_keys=[viewer_id]) # 资讯关联用户 (收藏/点赞) diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index 94a3d4f..04fa8b9 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -58,6 +58,8 @@ class InformationResponse(BaseModel): deal_price: Optional[float] deal_date: Optional[date] status: str + is_matched: str = "pending" + matched_user_id: Optional[str] = None view_count: int contact_count: int created_at: datetime @@ -126,6 +128,8 @@ def get_information_list( deal_price=item.deal_price, deal_date=item.deal_date, status=item.status, + is_matched=item.is_matched, + matched_user_id=item.matched_user_id, view_count=item.view_count, contact_count=item.contact_count, created_at=item.created_at, @@ -530,6 +534,8 @@ def get_my_seeks( deal_price=item.deal_price, deal_date=item.deal_date, status=item.status, + is_matched=item.is_matched, + matched_user_id=item.matched_user_id, view_count=item.view_count, contact_count=item.contact_count, created_at=item.created_at, @@ -643,6 +649,8 @@ def get_my_information_list( deal_price=item.deal_price, deal_date=item.deal_date, status=item.status, + is_matched=item.is_matched, + matched_user_id=item.matched_user_id, view_count=item.view_count, contact_count=item.contact_count, created_at=item.created_at, @@ -760,3 +768,27 @@ def add_comment( "created_at": comment.created_at } } + + +# ============ 获取评论列表 ============ +@router.get("/comments/{information_id}") +def get_comments( + information_id: str, + db: Session = Depends(get_db) +): + """获取资讯的评论列表""" + from app.models.models import InformationComment + comments = db.query(InformationComment).filter( + InformationComment.information_id == information_id + ).order_by(InformationComment.created_at.desc()).all() + + return [ + { + "id": c.id, + "content": c.content, + "user_name": c.user.f01_01_name if c.user else '匿名用户', + "user_avatar": c.user.avatar if c.user else None, + "created_at": c.created_at + } + for c in comments + ] diff --git a/config/VERSION b/config/VERSION index e6b8eb2..e8e268a 100644 --- a/config/VERSION +++ b/config/VERSION @@ -1 +1 @@ -VERSION=1.2.17 +VERSION=1.2.19 diff --git a/frontend/src/pages/News.jsx b/frontend/src/pages/News.jsx index 2628b9a..833eae3 100644 --- a/frontend/src/pages/News.jsx +++ b/frontend/src/pages/News.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react' // 资讯页面 - 展示寻配号和行情信息(所有人可见) export default function News() { - const [activeTab, setActiveTab] = useState('deal') + const [activeTab, setActiveTab] = useState(localStorage.getItem('news_activeTab') || 'seek') const [showSeekPublish, setShowSeekPublish] = useState(false) const [showMySeeks, setShowMySeeks] = useState(false) // 我的寻号 const [showContactId, setShowContactId] = useState(null) // 显示联系方式的寻号ID @@ -56,7 +56,7 @@ export default function News() { // 获取寻号评论 const fetchComments = async (infoId) => { - if (comments[infoId]) return; // 已加载则跳过 + // 每次都重新获取评论 try { const res = await fetch(`${API_BASE}/api/information/comments/${infoId}`) const data = await res.json() @@ -78,13 +78,27 @@ export default function News() { body: JSON.stringify({ information_id: infoId, content: commentText }) }) const data = await res.json() - if (data.message === '留言成功') { + if (data.message === '留言成功' || data.message === '评论成功') { setCommentText('') - setComments(prev => ({...prev, [infoId]: [...(prev[infoId] || []), data.comment]})) + // 强制刷新评论列表,先清空缓存 + setComments(prev => { + const newComments = {...prev} + delete newComments[infoId] + return newComments + }) + // 然后重新获取 + setTimeout(() => fetchComments(infoId), 100) + // 确保停留在寻号 tab + if (activeTab !== 'seek') { + setActiveTab('seek') + } alert('留言成功!') + } else { + alert(data.detail || '留言失败') } } catch (e) { - alert('留言失败: ' + e.message) + console.error('留言失败:', e) + alert('留言失败,请重试') } } @@ -214,7 +228,7 @@ export default function News() { {tabs.map(tab => (
setActiveTab(tab.key)} + onClick={() => { setActiveTab(tab.key); localStorage.setItem('news_activeTab', tab.key); }} style={{ padding: '10px 20px', borderRadius: '8px',