'use client'; import Link from 'next/link'; import { useEffect, useState } from 'react'; interface DoubanComment { id: string; user: string; avatar: string; rating: number; content: string; time: string; location: string; } // 演员 / 评分 / 全网热评(详情页简介下方) export default function VideoMetaExtra({ title, actor, director, score, scoreNum, doubanScore, doubanId, area, lang, isTv, desc, }: { title: string; actor?: string; director?: string; score?: string; scoreNum?: number; doubanScore?: string; doubanId?: number; area?: string; lang?: string; isTv?: boolean; desc?: string; }) { const [comments, setComments] = useState([]); const [loading, setLoading] = useState(false); const [dbDetail, setDbDetail] = useState(null); const [related, setRelated] = useState([]); useEffect(() => { if (!doubanId) return; let alive = true; setLoading(true); fetch(`/api/douban-comments?id=${encodeURIComponent(String(doubanId))}`) .then((r) => r.json()) .then((d) => { if (alive && d?.code === 1) setComments(d.list || []); }) .catch(() => {}) .finally(() => { if (alive) setLoading(false); }); // 豆瓣详情(评分/演员兜底) fetch(`/api/douban-detail?id=${encodeURIComponent(String(doubanId))}`) .then((r) => r.json()) .then((d) => { if (alive && d?.code === 1) setDbDetail(d); }) .catch(() => {}); // 相关推荐 fetch(`/api/douban-related?id=${encodeURIComponent(String(doubanId))}&type=${isTv ? 'tv' : 'movie'}`) .then((r) => r.json()) .then((d) => { if (alive && d?.code === 1) setRelated(d.list || []); }) .catch(() => {}); return () => { alive = false; }; }, [doubanId]); const actors = (actor || (dbDetail?.actors || []).join(',')) .split(/[,,、\/|]/) .map((s: string) => s.trim()) .filter(Boolean) .slice(0, 20); const scoreNum1 = parseFloat(score || '') || 0; const dbNum = parseFloat(doubanScore || '') || dbDetail?.rating || 0; const showScore = scoreNum1 > 0 ? scoreNum1.toFixed(1) : dbNum > 0 ? dbNum.toFixed(1) : ''; const showDirector = director || (dbDetail?.directors || []).join('、'); const showArea = area || dbDetail?.area || ''; const showLang = lang || dbDetail?.languages || ''; const showDuration = dbDetail?.duration || ''; if (!actors.length && !showDirector && !showScore && !showArea && !loading && !comments.length) return null; return (
{/* 导演 / 地区 / 语言 */} {(showDirector || showArea || showLang || showDuration) && (
{showDirector && ( 导演:{showDirector} )} {showArea && 地区:{showArea}} {showLang && 语言:{showLang}} {showDuration && 片长:{showDuration}}
)} {/* 评分 */} {showScore && (
评分 {showScore} {[1, 2, 3, 4, 5].map((i) => ( ★ ))} {scoreNum && scoreNum > 0 && ({scoreNum}人评)} {doubanId ? ( 豆瓣详情 → ) : null}
)} {(dbDetail?.intro || desc) && (
剧情简介: {dbDetail?.intro || desc}
)} {/* 演员列表 */} {actors.length > 0 && (
演员({actors.length})
{actors.map((a: string) => ( {a} ))}
)} {/* 豆瓣短评 */}
豆瓣短评 {doubanId ? ( 查看全部 → ) : null}
{loading && comments.length === 0 && (
{[0, 1, 2].map((i) => (
))}
)} {!loading && comments.length === 0 && (
暂无豆瓣短评。
)}
{comments.map((c) => (
{c.avatar ? ( {c.user} ) : null} {c.user} {c.rating > 0 && ( {'★'.repeat(c.rating)} )} {c.time.slice(0, 10)}
{c.content}
{c.location ? (
{c.location}
) : null}
))}
{related.length > 0 && ( )}
); }