import { useEffect, useState } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { NavBar } from 'antd-mobile' import { api } from '../../api/client.js' // 新闻详情: /news/:id // 正文来自 News.content (MCP 返回的完整正文), 旧数据可能无 content, 兜底显示摘要 function fmtDate(s) { if (!s) return '' const d = new Date(s) if (isNaN(d.getTime())) return s const pad = (n) => String(n).padStart(2, '0') return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) } export default function NewsDetail() { const { id } = useParams() const navigate = useNavigate() const [item, setItem] = useState(null) const [err, setErr] = useState('') const [loading, setLoading] = useState(true) useEffect(() => { let cancelled = false setLoading(true) api('/news/' + encodeURIComponent(id)) .then((data) => { if (!cancelled) setItem(data.item) }) .catch((e) => !cancelled && setErr(e.message)) .finally(() => !cancelled && setLoading(false)) return () => { cancelled = true } }, [id]) return (