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',