@@ -0,0 +1,225 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState, type ReactNode } from "react";
|
||||
|
||||
import { BackButton } from "@/components/common/back-button";
|
||||
import { AdBanners, AdIcons } from "@/components/common/ads";
|
||||
import { H5CommentsTab, useComments, type CommentTarget } from "@/components/common/comments";
|
||||
import { XgPlayer } from "@/components/player/xg-player";
|
||||
import type { ShortDramaItem } from "@/components/short-drama/data";
|
||||
import { tagPageHref } from "@/components/tag/href";
|
||||
import { H5VideoCard } from "@/components/video/video-card";
|
||||
|
||||
import { formatCount, formatWatchNum, type VideoDetail } from "./data";
|
||||
|
||||
type Tab = "intro" | "comments";
|
||||
|
||||
type StatsProps = {
|
||||
liked: boolean;
|
||||
/** 接口 likeNum:点赞数 */
|
||||
likeNum?: number;
|
||||
collected: boolean;
|
||||
/** 接口 countCollect:收藏数 */
|
||||
countCollect?: number;
|
||||
onLike: () => void;
|
||||
onCollect: () => void;
|
||||
onShare: () => void;
|
||||
};
|
||||
|
||||
function H5VideoPlayer({
|
||||
detail,
|
||||
src,
|
||||
onPlaySuccess,
|
||||
}: {
|
||||
detail: VideoDetail;
|
||||
src: string;
|
||||
onPlaySuccess?: () => void;
|
||||
}) {
|
||||
// 上下文由 VideoPlayPage 统一设置;此处仅绑定播放器行为
|
||||
return (
|
||||
<div className="sticky top-0 z-20 aspect-video w-full overflow-hidden bg-black">
|
||||
<XgPlayer
|
||||
src={src}
|
||||
poster={detail.coverImg || ""}
|
||||
onPlaySuccess={onPlaySuccess}
|
||||
analyticsKind="video"
|
||||
clickToPlay
|
||||
className="absolute inset-0"
|
||||
options={{ ignores: ["cssfullscreen"], fullscreen: { rotateFullscreen: true } }}
|
||||
/>
|
||||
<BackButton fallback="/video/hot" className="absolute top-3 left-4 z-10" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function IntroTab({
|
||||
detail,
|
||||
related,
|
||||
liked,
|
||||
likeNum,
|
||||
collected,
|
||||
countCollect,
|
||||
onLike,
|
||||
onCollect,
|
||||
onShare,
|
||||
adGrid,
|
||||
bannerAds,
|
||||
}: StatsProps & {
|
||||
detail: VideoDetail;
|
||||
related: ShortDramaItem[];
|
||||
adGrid?: ReactNode;
|
||||
bannerAds?: ReactNode;
|
||||
}) {
|
||||
const tags = (detail.tags ?? []).filter((tag) =>
|
||||
Boolean(tag.name?.trim() || tag.slug?.trim() || tag.id),
|
||||
);
|
||||
const likeCount = likeNum ?? detail.likeNum;
|
||||
const collectCount = countCollect ?? detail.countCollect;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-[18px] bg-[#010406] px-4 py-3">
|
||||
<h1 className="line-clamp-2 text-sm leading-5 font-medium text-white/80">{detail.title}</h1>
|
||||
{detail.desc?.trim() ? (
|
||||
<p className="text-xs leading-[18px] text-white/80">{detail.desc}</p>
|
||||
) : null}
|
||||
|
||||
{tags.length ? (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((tag) => {
|
||||
const name = (tag.tagName || tag.name || "").trim() || tag.slug?.trim() || "";
|
||||
if (!name) return null;
|
||||
const canLink = Boolean(tag.slug?.trim() || tag.id != null);
|
||||
return canLink ? (
|
||||
<Link
|
||||
key={tag.slug || tag.id || name}
|
||||
href={tagPageHref({ slug: tag.slug, id: tag.id }, "video")}
|
||||
className="rounded-[3px] bg-white/10 px-1.5 py-0.5 text-xs leading-[18px] text-white/90 hover:text-[#F12B9E]"
|
||||
>
|
||||
#{name}
|
||||
</Link>
|
||||
) : (
|
||||
<span
|
||||
key={name}
|
||||
className="rounded-[3px] bg-white/10 px-1.5 py-0.5 text-xs leading-[18px] text-white/90"
|
||||
>
|
||||
#{name}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center justify-between text-xs leading-[18px]">
|
||||
<span className="text-[#BDBDBD]">{formatWatchNum(detail.watchNum)}</span>
|
||||
<div className="flex items-center gap-3 text-[#BDBDBD]">
|
||||
<button type="button" aria-pressed={liked} onClick={onLike} className="cursor-pointer flex items-center gap-0.5">
|
||||
<svg viewBox="0 0 16 16" className="size-4" aria-hidden="true">
|
||||
<path
|
||||
d="M8 14c-.2 0-.4-.07-.56-.2C5.3 12 2 9.7 2 6.6 2 4.6 3.4 3 5.2 3c1.1 0 2.1.6 2.8 1.5C8.7 3.6 9.7 3 10.8 3 12.6 3 14 4.6 14 6.6c0 3.1-3.3 5.4-5.44 7.2-.16.13-.36.2-.56.2Z"
|
||||
fill={liked ? "#F52C56" : "none"}
|
||||
stroke="#F52C56"
|
||||
strokeWidth="1.4"
|
||||
/>
|
||||
</svg>
|
||||
{formatCount(likeCount)}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={collected}
|
||||
onClick={onCollect}
|
||||
className="cursor-pointer flex items-center gap-0.5"
|
||||
>
|
||||
<svg viewBox="0 0 16 16" className="size-4" aria-hidden="true">
|
||||
<path
|
||||
d="m8 2 1.8 3.7 4 .6-2.9 2.8.7 4L8 11.2l-3.6 1.9.7-4-2.9-2.8 4-.6L8 2Z"
|
||||
fill={collected ? "#FFC53D" : "none"}
|
||||
stroke="#FFC53D"
|
||||
strokeWidth="1.4"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{formatCount(collectCount)}
|
||||
</button>
|
||||
<button type="button" onClick={onShare} className="cursor-pointer flex items-center gap-0.5">
|
||||
<img src="/images/share_h5.svg" alt="" className="size-4" />
|
||||
分享
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* icon 广告 → 热门推荐 → banner 广告 */}
|
||||
{adGrid ?? <AdIcons variant="h5" />}
|
||||
|
||||
{related.length ? (
|
||||
<section className="flex flex-col items-center gap-3">
|
||||
<h2 className="w-full text-lg leading-6 font-semibold text-white">热门推荐</h2>
|
||||
<div className="grid w-full grid-cols-2 gap-x-[7px] gap-y-3">
|
||||
{related.map((item) => (
|
||||
<H5VideoCard key={item.id} item={item} showEpisodes={false} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{bannerAds ?? <AdBanners variant="h5" />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function H5VideoPlay({
|
||||
detail,
|
||||
src,
|
||||
related = [],
|
||||
commentTarget,
|
||||
onPlaySuccess,
|
||||
adGrid,
|
||||
bannerAds,
|
||||
...stats
|
||||
}: StatsProps & {
|
||||
detail: VideoDetail;
|
||||
src: string;
|
||||
related?: ShortDramaItem[];
|
||||
commentTarget: CommentTarget | null;
|
||||
onPlaySuccess?: () => void;
|
||||
adGrid?: ReactNode;
|
||||
bannerAds?: ReactNode;
|
||||
}) {
|
||||
const [tab, setTab] = useState<Tab>("intro");
|
||||
const comments = useComments({ target: commentTarget, initialSort: "最新" });
|
||||
|
||||
const tabs: { key: Tab; label: string }[] = [
|
||||
{ key: "intro", label: "简介" },
|
||||
{ key: "comments", label: `评论(${comments.total})` },
|
||||
];
|
||||
|
||||
return (
|
||||
<div data-component="video-h5-play" className="flex flex-col bg-[#010406] lg:hidden">
|
||||
<H5VideoPlayer detail={detail} src={src} onPlaySuccess={onPlaySuccess} />
|
||||
<div role="tablist" className="flex gap-3 px-4 pt-[18px]">
|
||||
{tabs.map((item) => (
|
||||
<button
|
||||
key={item.key}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={tab === item.key}
|
||||
onClick={() => setTab(item.key)}
|
||||
className={`cursor-pointer text-base leading-[22px] ${tab === item.key ? "font-medium text-white" : "text-[#8D8E8F]"}`}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{tab === "intro" ? (
|
||||
<IntroTab detail={detail} related={related} adGrid={adGrid} bannerAds={bannerAds} {...stats} />
|
||||
) : (
|
||||
<H5CommentsTab
|
||||
state={comments}
|
||||
footerExtra={
|
||||
bannerAds ? <div className="px-4 py-3">{bannerAds}</div> : <AdBanners variant="h5" className="px-4 py-3" />
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user