API支持deal_date参数过滤
This commit is contained in:
parent
73de6a1f85
commit
afa217e1b5
|
|
@ -107,6 +107,7 @@ def get_information_list(
|
|||
info_type: Optional[str] = Query(None, description="类型: seek/deal/publish"),
|
||||
status: str = Query("active", description="状态: active/closed/expired"),
|
||||
user_id: Optional[str] = Query(None, description="用户ID,用于获取该用户的行情"),
|
||||
deal_date: Optional[str] = Query(None, description="成交日期过滤,格式YYYY-MM-DD"),
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=500),
|
||||
current_user: Optional[User] = Depends(get_current_user),
|
||||
|
|
@ -126,6 +127,10 @@ def get_information_list(
|
|||
if user_id:
|
||||
query = query.filter(Information.user_id == user_id)
|
||||
|
||||
# 成交日期过滤
|
||||
if deal_date:
|
||||
query = query.filter(Information.deal_date == deal_date)
|
||||
|
||||
# 按创建时间倒序
|
||||
query = query.order_by(Information.created_at.desc())
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ export default function News() {
|
|||
const [matchedStatus, setMatchedStatus] = useState({}) // 存储各寻号的匹配状态
|
||||
const [showMatchList, setShowMatchList] = useState(false)
|
||||
const [dealVersion, setDealVersion] = useState('龙钞')
|
||||
const [dealDate, setDealDate] = useState('')
|
||||
const [dealDate, setDealDate] = useState(() => {
|
||||
const today = new Date()
|
||||
return `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
|
||||
})
|
||||
const [dealDetailItems, setDealDetailItems] = useState(null) // 弹窗显示的详情列表
|
||||
const [matchCollections, setMatchCollections] = useState([])
|
||||
const [networkMatchCollections, setNetworkMatchCollections] = useState([])
|
||||
|
|
@ -63,7 +66,7 @@ export default function News() {
|
|||
// 获取资讯列表
|
||||
useEffect(() => {
|
||||
fetchInfoList()
|
||||
}, [activeTab])
|
||||
}, [activeTab, dealDate])
|
||||
|
||||
// 自动生成寻号标题
|
||||
useEffect(() => {
|
||||
|
|
@ -74,13 +77,19 @@ export default function News() {
|
|||
const fetchInfoList = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
// 寻配号对所有人公开,无需登录即可查看
|
||||
const token = localStorage.getItem('token')
|
||||
// 根据tab获取不同类型的数据
|
||||
const type = activeTab === 'seek' ? 'seek' : activeTab === 'deal' ? 'deal' : 'yichen'
|
||||
// 始终传递token,以便获取准确的matched_count
|
||||
const headers = token ? { Authorization: `Bearer ${token}` } : {}
|
||||
const res = await fetch(`${API_BASE}/api/information/list?info_type=${type}&page=${currentPage}&page_size=50`, { headers })
|
||||
|
||||
// 构建URL参数
|
||||
let url = `${API_BASE}/api/information/list?info_type=${type}&page=${currentPage}&page_size=50`
|
||||
|
||||
// 如果是成交行情tab,添加日期过滤
|
||||
if (activeTab === 'deal' && dealDate) {
|
||||
url += `&deal_date=${dealDate}`
|
||||
}
|
||||
|
||||
const res = await fetch(url, { headers })
|
||||
// 从响应头获取总页数
|
||||
const total = res.headers.get('X-Total-Pages') || res.headers.get('x-total-pages')
|
||||
if (total) setTotalPages(parseInt(total))
|
||||
|
|
@ -462,7 +471,7 @@ export default function News() {
|
|||
</div>
|
||||
)}
|
||||
<h3 style={{ color: '#fff', marginBottom: '16px' }}>
|
||||
{activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? '成交行情信息' : '一尘看板'}
|
||||
{activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? `成交行情信息 (${dealDate})` : '一尘看板'}
|
||||
{activeTab === 'seek' && (
|
||||
<div style={{ display: 'flex', gap: '8px', marginLeft: 'auto' }}>
|
||||
<button onClick={() => { setViewMode('all'); fetchInfoList(); }} style={{ padding: '6px 12px', background: viewMode==='all'?'#3b82f6':'#1e293b', border: '1px solid #334155', borderRadius: '6px', color: '#fff', fontSize: '12px' }}>全部</button>
|
||||
|
|
@ -471,6 +480,12 @@ export default function News() {
|
|||
<button onClick={() => setShowSeekPublish(!showSeekPublish)} style={{ padding: '6px 12px', background: showSeekPublish ? '#6b7280' : '#10b981', border: 'none', borderRadius: '6px', color: '#fff', fontSize: '12px', cursor: 'pointer' }}>发布寻号</button>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === 'deal' && (
|
||||
<div style={{ display: 'flex', gap: '8px', marginLeft: 'auto' }}>
|
||||
<input type="date" value={dealDate} onChange={e => setDealDate(e.target.value)}
|
||||
style={{ padding: '6px 12px', background: '#1e293b', border: '1px solid #334155', borderRadius: '6px', color: '#fff', fontSize: '12px' }} />
|
||||
</div>
|
||||
)}
|
||||
</h3>
|
||||
|
||||
{/* 一尘看板独立渲染 */}
|
||||
|
|
|
|||
Loading…
Reference in New Issue