Initial commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
谢宇宁
2026-10-26 17:51:31 +07:00
co-authored by Claude Opus 5.5
commit 61d0a11dfa
371 changed files with 35836 additions and 0 deletions
+161
View File
@@ -0,0 +1,161 @@
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<string, (typeof sorts)[number]> = {
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;
/** 覆盖默认详情/播放链接(如历史继续看到某集) */
href?: string;
}
| {
kind: "ad";
id: string;
title: string;
subtitle: string;
cover: 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 {
if (item.type === 2) {
return {
kind: "ad",
id: `ad-${item.advertiseId || item.id || item.link || "unknown"}`,
title: (item.title || "").trim() || "广告",
subtitle: "",
cover: (item.cover || "").trim(),
href: (item.link || "").trim() || undefined,
};
}
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,
};
}
/** @deprecated 本地 mock,供「更多」等未接接口页面临时使用 */
const adSlots = new Set([4, 9, 14, 18, 23]);
const freshSlots = new Set([3, 11, 21]);
export function getShortDramas(genre: Genre, sort: Sort, page: number, region: Region = "全部"): ShortDramaItem[] {
const seed = `${genres.indexOf(genre)}-${sorts.indexOf(sort)}-${regions.indexOf(region)}-${page}`;
return Array.from({ length: PAGE_SIZE }, (_, index): ShortDramaItem => {
const id = `short-${seed}-${index}`;
const cover = "";
if (adSlots.has(index)) {
return { kind: "ad", id, title: "广告文案", subtitle: "我是副标题", cover };
}
return {
kind: "drama",
id,
title: "有恩必报",
subtitle: "权谋交锋爱意藏在局中",
tags: [{ name: genre === "全部" ? "标签" : genre }],
heat: "25.8万 热度",
episodes: "30集",
badge: freshSlots.has(index) ? "fresh" : "original",
cover,
};
});
}
/** 有 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)}`;
}