import { pickPlayletCardTags, type CardTagItem } from "@/components/common/card-tags"; import type { BadgeTone } from "@/components/home/data"; import { resolveContentBadge } from "@/components/home/section-heading"; import { formatHeat } from "@/components/ranking/data"; import type { PlayletListItem, PlayletListResp, PlayletThemeItem } from "@/lib/api/types"; export const genres = ["全部", "甜宠", "逆袭", "霸总", "重生", "豪门", "古装", "玄幻", "都市"] as const; /** 路由排序段(英文);展示文案见 sortLabels */ export const sorts = ["hot", "latest"] as const; export const sortLabels: Record<(typeof sorts)[number], string> = { hot: "热度优先", latest: "最近更新", }; /** 兼容旧中文路径 → 英文 sort */ export const sortPathAliases: Record = { hot: "hot", latest: "latest", 热度优先: "hot", 最近更新: "latest", }; export const regions = ["全部", "内地", "中国香港", "中国台湾", "韩国", "日本", "欧美"] as const; export type Genre = (typeof genres)[number]; export type Sort = (typeof sorts)[number]; export type Region = (typeof regions)[number]; export type ShortDramaItem = { kind: "drama"; id: string; slug?: string; title: string; subtitle: string; /** 左下角标签,最多 3 个(优先带 id 以便跳转) */ tags: CardTagItem[]; heat: string; episodes: string; badge?: BadgeTone; cover: string; /** 发布时间(接口原值,视频卡展示日期用) */ date?: string; /** 覆盖默认详情/播放链接(如历史继续看到某集) */ href?: string; }; export const PAGE_SIZE = 24; export const TOTAL_PAGES = 11; export function shortDramaSortType(sort: Sort): 1 | 2 { return sort === "latest" ? 2 : 1; } export function mapPlayletListItem(item: PlayletListItem): ShortDramaItem | null { // 信息流广告(type=2)不展示:网页只保留后台 5 个站点广告位 if (item.type === 2) return null; if (!item.id) return null; const tags = pickPlayletCardTags(item); const slug = (item.slug || "").trim(); return { kind: "drama", id: String(item.id), slug: slug || undefined, title: (item.title || "").trim() || "未命名", subtitle: (item.desc || "").trim(), tags, heat: formatHeat(item.heatValue ?? item.countBrowse), episodes: item.totalEpisode ? `${item.totalEpisode}集` : "", badge: resolveContentBadge(item), cover: (item.cover || "").trim(), }; } export type ShortDramaListResult = { items: ShortDramaItem[]; page: number; pageSize: number; totalCount: number; totalPages: number; sort: Sort; themes: PlayletThemeItem[]; themeSlug?: string; }; export function buildShortDramaList( data: PlayletListResp | null | undefined, sort: Sort, fallbackPage = 1, fallbackPageSize = PAGE_SIZE, options?: { themes?: PlayletThemeItem[]; themeSlug?: string }, ): ShortDramaListResult { const page = data?.pageNum || fallbackPage; const pageSize = data?.pageSize || fallbackPageSize; const totalCount = data?.totalCount || 0; const items = (data?.list ?? []) .map(mapPlayletListItem) .filter((item): item is ShortDramaItem => Boolean(item)); return { items, page, pageSize, totalCount, totalPages: Math.max(1, Math.ceil(totalCount / pageSize) || 1), sort, themes: options?.themes ?? [], themeSlug: options?.themeSlug, }; } /** 有 slug 时路径用 slug,否则回退 id */ export function dramaPathKey(id: string | number, slug?: string | null) { return (slug?.trim() || String(id)).trim(); } export function dramaHref(id: string | number, slug?: string | null) { return `/short-drama/${dramaPathKey(id, slug)}`; }