import React, { useState, useEffect } from 'react' // 资讯页面 - 展示寻配号和行情信息(所有人可见) export default function News() { const [activeTab, setActiveTab] = useState('deal') const [infoList, setInfoList] = useState([]) const [loading, setLoading] = useState(false) const API_BASE = localStorage.getItem('API_BASE') || '' // 获取资讯列表 useEffect(() => { fetchInfoList() }, [activeTab]) const fetchInfoList = async () => { setLoading(true) try { const token = localStorage.getItem('token') // 根据tab获取不同类型的数据 const type = activeTab === 'seek' ? 'seek' : 'deal' const res = await fetch(`${API_BASE}/api/information/list?info_type=${type}`, { headers: { Authorization: `Bearer ${token}` } }) const data = await res.json() setInfoList(data || []) } catch (e) { console.error(e) } setLoading(false) } // Tab切换 const tabs = [ { key: 'seek', label: '🔍 寻配号' }, { key: 'deal', label: '💰 成交行情' } ] const formatDate = (dateStr) => { if (!dateStr) return '-' const date = new Date(dateStr) return `${date.getMonth() + 1}/${date.getDate()}` } return (
{/* Tab导航 */}
{tabs.map(tab => (
setActiveTab(tab.key)} style={{ padding: '10px 20px', borderRadius: '8px', background: activeTab === tab.key ? '#3b82f6' : 'transparent', color: '#fff', cursor: 'pointer', whiteSpace: 'nowrap', fontSize: '14px' }} > {tab.label}
))}
{/* 资讯列表 */}

{activeTab === 'seek' ? '🔍 寻配号信息' : '💰 成交行情信息'}

{loading ? (
加载中...
) : infoList.length === 0 ? (
暂无{activeTab === 'seek' ? '寻配号' : '成交行情'}信息
) : (
{infoList.map(item => (
{item.title}
{formatDate(item.created_at)} | {item.info_source || '系统'}
{item.content && (
{item.content}
)}
))}
)}
) }