Files
web_hghl_h5/src/components/video/video-card.tsx
T
2026-10-28 17:07:32 +07:00

93 lines
3.3 KiB
TypeScript

import Link from "next/link";
import { CardTags } from "@/components/common/card-tags";
import { DecryptedImage } from "@/components/common/decrypted-image";
import {
EyeIcon,
formatDay,
HL_COVER,
HL_COVER_IMG,
HL_TITLE_LINK,
HlBadge,
} from "@/components/common/media-meta";
import type { ShortDramaItem } from "@/components/short-drama/data";
import { IMG_PLACEHOLDER } from "@/lib/image/decrypt";
export function videoHref(id: string, slug?: string | null) {
return `/video/${(slug?.trim() || id).trim()}`;
}
/** 排行序号:No.01(琥珀色,放在标题前) */
function RankLabel({ rank, className = "" }: { rank?: number; className?: string }) {
if (rank === undefined) return null;
return (
<span className={`mr-1.5 font-bold text-[#FFB020] tabular-nums ${className}`}>No.{String(rank).padStart(2, "0")}</span>
);
}
/** 视频卡元信息:观看数 + 发布日期 */
function VideoMeta({ item, className }: { item: ShortDramaItem; className: string }) {
const day = formatDay(item.date);
return (
<p className={`flex min-w-0 items-center gap-2 text-[#8E8C99] ${className}`}>
{item.heat ? (
<span className="inline-flex shrink-0 items-center gap-1">
<EyeIcon />
{item.heat}
</span>
) : null}
{item.heat && day ? <span aria-hidden="true" className="h-2.5 w-px bg-white/15" /> : null}
{day ? <time dateTime={day}>{day}</time> : null}
</p>
);
}
export function VideoCard({ item, rank }: { item: ShortDramaItem; rank?: number }) {
const href = item.href || videoHref(item.id, item.slug);
return (
<article data-component="hl-video-card" className="group flex w-[324px] flex-col gap-2.5">
<Link href={href} tabIndex={-1} aria-hidden="true" className={`${HL_COVER} aspect-[16/10]`}>
<DecryptedImage src={item.cover} fallback={IMG_PLACEHOLDER} alt={item.title} className={HL_COVER_IMG} />
<HlBadge tone={item.badge} />
</Link>
<h3 className="media-card-title-md line-clamp-2 min-h-[2.5em] font-medium text-[#F4F3F7]">
<RankLabel rank={rank} />
<Link href={href} title={item.title} className={HL_TITLE_LINK}>
{item.title}
</Link>
</h3>
<VideoMeta item={item} className="media-card-desc" />
<CardTags tags={item.tags} kind="video" className="media-card-meta min-w-0 text-[#B49A6A]" />
</article>
);
}
export function H5VideoCard({
item,
rank,
}: {
item: ShortDramaItem;
rank?: number;
/** @deprecated 新卡片不在封面显示集数,保留参数兼容调用方 */
showEpisodes?: boolean;
}) {
const href = item.href || videoHref(item.id, item.slug);
return (
<article data-component="hl-video-card-h5" className="group flex min-w-0 flex-col gap-1.5">
<Link href={href} tabIndex={-1} aria-hidden="true" className={`${HL_COVER} aspect-[16/10]`}>
<DecryptedImage src={item.cover} fallback={IMG_PLACEHOLDER} alt={item.title} className={HL_COVER_IMG} />
<HlBadge tone={item.badge} small />
</Link>
<h3 className="line-clamp-2 min-h-10 text-sm leading-5 font-medium text-[#F4F3F7]">
<RankLabel rank={rank} className="text-xs" />
<Link href={href} title={item.title} className={HL_TITLE_LINK}>
{item.title}
</Link>
</h3>
<VideoMeta item={item} className="text-[11px] leading-4" />
</article>
);
}