'use client'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import PaginatedRow from '@/components/PaginatedRow'; 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, genre, isTv, desc, selfSource, selfId, }: { title: string; actor?: string; director?: string; score?: string; scoreNum?: number; doubanScore?: string; doubanId?: number; area?: string; lang?: string; genre?: string; isTv?: boolean; desc?: string; /** 当前条目所属源与 id,用于相关推荐排除自己 */ selfSource?: string; selfId?: string; }) { const [comments, setComments] = useState([]); const [loading, setLoading] = useState(false); const [dbDetail, setDbDetail] = useState(null); const [related, setRelated] = useState([]); const [relatedLoading, setRelatedLoading] = useState(false); 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(() => {}); return () => { alive = false; }; }, [doubanId]); // 相关推荐:本站片源,按 主演/导演/语言/地区/类型 匹配(不走豆瓣推荐接口) useEffect(() => { if (!title || (!actor && !director)) { setRelated([]); return; } let alive = true; setRelatedLoading(true); const params = new URLSearchParams({ title, actor: actor || '', director: director || '', area: area || '', lang: lang || '', genre: genre || '', doubanId: String(doubanId || ''), selfSource: selfSource || '', selfId: selfId || '', }); if (isTv !== undefined) params.set('isTv', isTv ? '1' : '0'); fetch(`/api/related?${params.toString()}`) .then((r) => r.json()) .then((d) => { if (alive) setRelated(Array.isArray(d?.items) ? d.items : []); }) .catch(() => { if (alive) setRelated([]); }) .finally(() => { if (alive) setRelatedLoading(false); }); return () => { alive = false; }; }, [title, actor, director, area, lang, genre, isTv, doubanId, selfSource, selfId]); 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 || relatedLoading) && (
相关推荐 按主演 / 导演 / 语言 / 地区 / 类型匹配 · 本站片源直达
{relatedLoading && related.length === 0 && (
{[0, 1, 2, 3, 4].map((i) => (
))}
)} {related.length > 0 && ( /* 与首页「最新港剧」同款 PaginatedRow 翻页:左右箭头 hover 显示,每页 10 条 */ {related.map((r: any) => ( {r.poster ? ( {r.title} ) : null}
{r.title}
{[r.year, r.source_name].filter(Boolean).join(' · ')}
{r.reasons?.length > 0 && (
{r.reasons.slice(0, 2).join(' · ')}
)}
))}
)}
)}
); }