import Link from "next/link"; import { CardTags, cardTagCanLink, pickPlayletCardTags, pickVideoCardTags, } from "@/components/common/card-tags"; import { DecryptedImage } from "@/components/common/decrypted-image"; import { MEDIA_CARD_DESC_MD, MEDIA_CARD_EPISODES, MEDIA_CARD_META_MD, MEDIA_CARD_TITLE, MEDIA_CARD_TITLE_PC, } from "@/components/common/media-card-hover"; import { formatHeat } from "@/components/ranking/data"; import { morePageHref } from "@/components/more/href"; import { dramaHref } from "@/components/short-drama/data"; import { tagPageHref } from "@/components/tag/href"; import { videoHref } from "@/components/video/video-card"; import type { HomeModuleData, PlayletData, VideoInfo } from "@/lib/api/types"; import { IMG_PLACEHOLDER } from "@/lib/image/decrypt"; import { H5SectionHeading } from "./h5-cards"; import { isVideoDataType, unwrapHomeModuleList, videoCoverSrc } from "./home-module-style"; function heatLabel(count?: number | null) { // formatHeat → "95.6万 热度";样式 E 文案为「热度 95.6万」 return formatHeat(count).replace(/^(.+)\s热度$/, "热度 $1"); } /** H5 样式 E:热度只显示数值(如 95.6万) */ function heatValueLabel(count?: number | null) { return formatHeat(count).replace(/\s*热度$/, ""); } const H5_E_RANK_BADGES = [ "/images/rank_num1.png", "/images/rank_num2.png", "/images/rank_num3.png", ] as const; const H5_E_RANK_BADGE_FALLBACK = "/images/rank_num4.png"; function H5StyleERankBadge({ rank, className = "absolute top-0 left-0 z-[1] h-5 w-[22px]", }: { rank: number; className?: string; }) { const bg = H5_E_RANK_BADGES[rank - 1] ?? H5_E_RANK_BADGE_FALLBACK; return ( {rank} ); } function WatchButton({ href }: { href: string }) { return ( 立即观看 ); } /** 样式 E · 视频:竖排大卡(400 × 499,封面横版在上) */ function StyleEVideoCard({ item }: { item: VideoInfo }) { const href = videoHref(String(item.id), item.slug); const tags = pickVideoCardTags(item); const heat = heatLabel(item.watchNum); return (
{item.title || "未命名"}

 

{heat}
); } /** 样式 E · 短剧:横排大卡(553 × 401,竖封面在左) */ function StyleEPlayletCard({ item }: { item: PlayletData }) { const href = dramaHref(item.id, item.slug); const tags = pickPlayletCardTags(item); const heat = heatLabel(item.heatValue ?? item.countBrowse); const episodes = item.totalEpisode ? `${item.totalEpisode}集` : ""; return (
{episodes ? ( {episodes} ) : null}
{item.title || "未命名"}

{item.desc || "\u00A0"}

{heat}
); } function chunkRows(items: T[], size: number): T[][] { const rows: T[][] = []; for (let i = 0; i < items.length; i += size) { rows.push(items.slice(i, i + size)); } return rows; } /** 样式 E:视频竖排 4×2 / 短剧横排 3×2 */ export function HomeModuleStyleE({ module }: { module: HomeModuleData }) { const { videos, playlets } = unwrapHomeModuleList(module.list, module.dataType); const isVideo = isVideoDataType(module.dataType) || (videos.length > 0 && playlets.length === 0); if (isVideo) { const rows = chunkRows(videos.slice(0, 8), 4); return (
{rows.map((row, rowIndex) => (
{row.map((item, i) => ( ))}
))}
); } const rows = chunkRows(playlets.slice(0, 6), 3); return (
{rows.map((row, rowIndex) => (
{row.map((item) => ( ))}
))}
); } /** H5 · 短剧样式 E 横卡(封面左 + 信息右,带排行) */ function H5StyleEPlayletCard({ item, rank }: { item: PlayletData; rank: number }) { const href = dramaHref(item.id, item.slug); // 封面旁极窄,只展示 1 个标签,避免「激…|测试…」 const tags = pickPlayletCardTags(item).slice(0, 1); const themeLabel = (item.themeNames?.[0] || item.tagNames?.[0] || "").trim(); const heat = heatValueLabel(item.heatValue ?? item.countBrowse); const episodes = item.totalEpisode ? `${item.totalEpisode}集` : ""; const showCoins = Number(item.payType) !== 0; return (
{showCoins ? ( ¥ ) : null} {episodes ? ( {episodes} ) : null}
{tags.length ? (

{tags.map((tag, i) => ( {i > 0 ? "|" : null} {cardTagCanLink(tag) ? ( {tag.name} ) : ( tag.name )} ))}

) : (

 

)}

{heat}

{themeLabel ? ( {themeLabel} ) : null} {item.title || "未命名"}

{item.desc || "\u00A0"}

立即观看
); } /** H5 · 短剧样式 E:标题 + 三行两卡热榜 */ export function HomeModuleStyleEH5Playlet({ module }: { module: HomeModuleData }) { const moreHref = morePageHref(module); const title = (module.title || module.label || "推荐").trim(); const { playlets } = unwrapHomeModuleList(module.list, module.dataType); const rows = chunkRows(playlets.slice(0, 6), 2); if (!rows.length) return null; return (
{rows.map((row, rowIndex) => (
{row.map((item, i) => ( ))}
))}
); } /** H5 · 视频样式 E 竖卡(封面在上,信息在下,带排行) */ function H5StyleEVideoCard({ item, rank }: { item: VideoInfo; rank: number }) { const href = videoHref(String(item.id), item.slug); const tags = pickVideoCardTags(item).slice(0, 1); const themeLabel = (item.tagsName?.[0] || "").trim(); const heat = heatValueLabel(item.watchNum); return (
{themeLabel ? ( {themeLabel} ) : null} {item.title || "未命名"}

 

{tags.length ? (

{tags.map((tag, i) => ( {i > 0 ? "|" : null} {cardTagCanLink(tag) ? ( {tag.name} ) : ( tag.name )} ))}

) : (

 

)}

{heat}

立即观看
); } /** H5 · 视频样式 E:标题 + 三行两卡热榜竖版 */ export function HomeModuleStyleEH5Video({ module }: { module: HomeModuleData }) { const moreHref = morePageHref(module); const title = (module.title || module.label || "推荐").trim(); const { videos } = unwrapHomeModuleList(module.list, module.dataType); const rows = chunkRows(videos.slice(0, 6), 2); if (!rows.length) return null; return (
{rows.map((row, rowIndex) => (
{row.map((item, i) => ( ))}
))}
); }