2026-03-25 10:58:00 +08:00
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
|
|
2026-03-26 15:32:27 +08:00
|
|
|
// 资讯页面 - 展示寻配号和行情信息(所有人可见)
|
2026-03-25 10:58:00 +08:00
|
|
|
export default function News() {
|
2026-03-26 23:06:47 +08:00
|
|
|
const [activeTab, setActiveTab] = useState('deal')
|
2026-03-25 10:58:00 +08:00
|
|
|
const [infoList, setInfoList] = useState([])
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
|
|
|
|
|
const API_BASE = localStorage.getItem('API_BASE') || ''
|
|
|
|
|
|
2026-03-26 15:32:27 +08:00
|
|
|
// 获取资讯列表
|
2026-03-25 10:58:00 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
fetchInfoList()
|
|
|
|
|
}, [activeTab])
|
|
|
|
|
|
|
|
|
|
const fetchInfoList = async () => {
|
|
|
|
|
setLoading(true)
|
|
|
|
|
try {
|
|
|
|
|
const token = localStorage.getItem('token')
|
2026-03-26 15:32:27 +08:00
|
|
|
// 根据tab获取不同类型的数据
|
|
|
|
|
const type = activeTab === 'seek' ? 'seek' : 'deal'
|
|
|
|
|
const res = await fetch(`${API_BASE}/api/information/list?info_type=${type}`, {
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` }
|
2026-03-25 10:58:00 +08:00
|
|
|
})
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
setInfoList(data || [])
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
}
|
|
|
|
|
setLoading(false)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 15:32:27 +08:00
|
|
|
// Tab切换
|
|
|
|
|
const tabs = [
|
|
|
|
|
{ key: 'seek', label: '🔍 寻配号' },
|
|
|
|
|
{ key: 'deal', label: '💰 成交行情' }
|
|
|
|
|
]
|
2026-03-25 10:58:00 +08:00
|
|
|
|
|
|
|
|
const formatDate = (dateStr) => {
|
2026-03-26 15:32:27 +08:00
|
|
|
if (!dateStr) return '-'
|
|
|
|
|
const date = new Date(dateStr)
|
|
|
|
|
return `${date.getMonth() + 1}/${date.getDate()}`
|
2026-03-25 10:58:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-03-26 15:32:27 +08:00
|
|
|
<div style={{ minHeight: '100vh', background: '#0f172a', paddingBottom: '60px' }}>
|
|
|
|
|
{/* Tab导航 */}
|
|
|
|
|
<div style={{ display: 'flex', padding: '12px 16px', background: '#1e293b', gap: '8px', overflowX: 'auto' }}>
|
|
|
|
|
{tabs.map(tab => (
|
2026-03-25 10:58:00 +08:00
|
|
|
<div
|
|
|
|
|
key={tab.key}
|
|
|
|
|
onClick={() => setActiveTab(tab.key)}
|
|
|
|
|
style={{
|
2026-03-26 15:32:27 +08:00
|
|
|
padding: '10px 20px',
|
|
|
|
|
borderRadius: '8px',
|
2026-03-25 10:58:00 +08:00
|
|
|
background: activeTab === tab.key ? '#3b82f6' : 'transparent',
|
|
|
|
|
color: '#fff',
|
|
|
|
|
cursor: 'pointer',
|
2026-03-26 15:32:27 +08:00
|
|
|
whiteSpace: 'nowrap',
|
2026-03-25 10:58:00 +08:00
|
|
|
fontSize: '14px'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-03-26 15:32:27 +08:00
|
|
|
{tab.label}
|
2026-03-25 10:58:00 +08:00
|
|
|
</div>
|
2026-03-26 15:32:27 +08:00
|
|
|
))}
|
|
|
|
|
</div>
|
2026-03-25 10:58:00 +08:00
|
|
|
|
|
|
|
|
{/* 资讯列表 */}
|
2026-03-26 15:32:27 +08:00
|
|
|
<div style={{ padding: '16px' }}>
|
|
|
|
|
<h3 style={{ color: '#fff', marginBottom: '16px' }}>
|
|
|
|
|
{activeTab === 'seek' ? '🔍 寻配号信息' : '💰 成交行情信息'}
|
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
|
|
{loading ? (
|
|
|
|
|
<div style={{ color: '#94a3b8', textAlign: 'center', padding: '40px' }}>加载中...</div>
|
|
|
|
|
) : infoList.length === 0 ? (
|
|
|
|
|
<div style={{ color: '#94a3b8', textAlign: 'center', padding: '40px' }}>
|
|
|
|
|
暂无{activeTab === 'seek' ? '寻配号' : '成交行情'}信息
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
|
|
|
|
|
{infoList.map(item => (
|
|
|
|
|
<div key={item.id} style={{ background: '#1e293b', borderRadius: '12px', padding: '16px' }}>
|
|
|
|
|
<div style={{ color: '#fbbf24', fontSize: '15px', fontWeight: '500', marginBottom: '8px' }}>
|
|
|
|
|
{item.title}
|
2026-03-25 10:58:00 +08:00
|
|
|
</div>
|
2026-03-26 15:32:27 +08:00
|
|
|
<div style={{ color: '#94a3b8', fontSize: '12px', marginBottom: '8px' }}>
|
|
|
|
|
{formatDate(item.created_at)} | {item.info_source || '系统'}
|
2026-03-25 10:58:00 +08:00
|
|
|
</div>
|
|
|
|
|
{item.content && (
|
2026-03-26 15:32:27 +08:00
|
|
|
<div style={{ color: '#e2e8f0', fontSize: '14px', lineHeight: '1.6' }}>
|
|
|
|
|
{item.content}
|
2026-03-25 10:58:00 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-03-26 15:32:27 +08:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-03-25 10:58:00 +08:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|