import { View, Text, Image, Video, ScrollView, Input, Button, RichText } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { useState, useEffect } from 'react'; import { getContent, getComments, addComment } from '@/utils/content'; import { isAuthed } from '@/utils/auth'; import './index.scss'; const rw = (s) => (s || '').replace('T', ' ').replace('Z', '').slice(0, 16); /** 资讯详情(微信文章式):标题/作者/阅读 + 正文 + 动作条 + 留言。 */ export default function ContentDetail() { const [item, setItem] = useState(null); const [comments, setComments] = useState([]); const [err, setErr] = useState(''); const [loaded, setLoaded] = useState(false); const [like, setLike] = useState(false); const [fav, setFav] = useState(false); const [draft, setDraft] = useState(''); const [sending, setSending] = useState(false); useEffect(() => { const inst = Taro.getCurrentInstance(); const id = (inst && inst.router && inst.router.params && inst.router.params.id) || ''; if (!id) { setErr('无效内容'); setLoaded(true); return; } getContent(id).then(setItem).catch(() => setErr('加载失败')).finally(() => setLoaded(true)); getComments(id).then(setComments).catch(() => {}); }, []); if (!loaded) return 加载中…; if (err || !item) return {err || '内容不存在'}; const id = item.id; const img = item.cover || (item.video ? item.video_cover : ''); const isSmall = item.card_mode === 'small'; // 小图模式:详情页不显示封面 const images = Array.isArray(item.images) ? item.images : []; const author = item.publisher_name || '云超服'; const views = item.read_count || 0; const copyLink = () => Taro.setClipboardData({ data: `https://opc.pinesound.cn/#/content-detail?id=${id}` }).then(() => Taro.showToast({ title: '链接已复制', icon: 'none' })); const scrollToComment = () => { Taro.pageScrollTo({ selector: '.cd-comments', duration: 300 }); }; const send = async () => { if (!isAuthed()) { Taro.showToast({ title: '请先登录', icon: 'none' }); return; } if (!draft.trim()) return; setSending(true); try { const c = await addComment(id, draft.trim()); if (c) { setComments((m) => [c, ...m]); setDraft(''); Taro.showToast({ title: '已留言', icon: 'success' }); } } catch (e) { Taro.showToast({ title: (e && e.message) || '留言失败', icon: 'none' }); } finally { setSending(false); } }; return ( {/* 封面/视频(小图模式不显示封面) */} {!isSmall && (item.video ?