Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
- 新增 src/app/anime + src/app/api/anime: 多源并行抓取、地区归一化、title+year去重、update_time降序、pg分页 - 新增 src/app/api/browse + src/lib/vodcat.ts: kind/cat|area/pg 统一第三方分类浏览接口 - douban 电影/剧集/综艺 选择器改走 /api/browse, 分类全量切第三方分类语义 - PageLayout/MobileBottomNav 增加 动漫 导航入口(源码实现) - 修复 /anime reset=true 时 base 置空导致新数据被丢弃(接口200页面空) - 版本 NEXT_PUBLIC_SITE_VERSION=fixed96; README/CHANGELOG 更新
187 lines
5.9 KiB
TypeScript
187 lines
5.9 KiB
TypeScript
/* eslint-disable react-hooks/exhaustive-deps */
|
|
'use client';
|
|
|
|
import { useSearchParams } from 'next/navigation';
|
|
import { Suspense, useCallback, useEffect, useRef, useState } from 'react';
|
|
|
|
import PageLayout from '@/components/PageLayout';
|
|
import VideoCard from '@/components/VideoCard';
|
|
|
|
// ---------- /anime 动漫频道(数据来自第三方采集站全量动漫分类) ----------
|
|
// 后端:src/app/api/anime/route.ts -> { list:[...], next_pg, has_more }
|
|
|
|
type Item = {
|
|
id: string;
|
|
title: string;
|
|
poster: string;
|
|
episodes: number;
|
|
source: string;
|
|
source_name: string;
|
|
year: string;
|
|
area: string;
|
|
type_name: string;
|
|
douban_id?: number | string;
|
|
};
|
|
|
|
const REGION_OPTS = [
|
|
{ label: '全部', value: '' },
|
|
{ label: '国产', value: '国产' },
|
|
{ label: '日韩', value: '日韩' },
|
|
{ label: '欧美', value: '欧美' },
|
|
{ label: '港台', value: '港台' },
|
|
{ label: '海外', value: '海外' },
|
|
];
|
|
|
|
function AnimeClient() {
|
|
const searchParams = useSearchParams();
|
|
const [region, setRegion] = useState(() => searchParams.get('region') || '');
|
|
const [items, setItems] = useState<Item[]>([]);
|
|
const [refreshing, setRefreshing] = useState(false);
|
|
const [nextPg, setNextPg] = useState(1);
|
|
const [hasMore, setHasMore] = useState(true);
|
|
const [err, setErr] = useState('');
|
|
const reqId = useRef(0);
|
|
|
|
const load = useCallback(
|
|
async (pg: number, reset: boolean) => {
|
|
const id = ++reqId.current;
|
|
if (reset) {
|
|
setRefreshing(true);
|
|
setErr('');
|
|
}
|
|
try {
|
|
const q = new URLSearchParams({ pg: String(pg) });
|
|
if (region) q.set('region', region);
|
|
const r = await fetch('/api/anime?' + q.toString());
|
|
const j = await r.json();
|
|
if (id !== reqId.current) return;
|
|
if (j?.error) {
|
|
setErr(j.error);
|
|
return;
|
|
}
|
|
const arr: Item[] = Array.isArray(j?.list) ? j.list : [];
|
|
setItems((prev) => {
|
|
const base = reset ? [...arr] : [...prev, ...arr];
|
|
const seen = new Set<string>();
|
|
return base.filter((x) => {
|
|
const k = x.title + '|' + x.year;
|
|
if (seen.has(k)) return false;
|
|
seen.add(k);
|
|
return true;
|
|
});
|
|
});
|
|
setNextPg(j?.next_pg || pg + 1);
|
|
setHasMore(!!j?.has_more && arr.length > 0);
|
|
} catch {
|
|
if (id === reqId.current) setErr('加载失败,请稍后重试');
|
|
} finally {
|
|
if (id === reqId.current) setRefreshing(false);
|
|
}
|
|
},
|
|
[region]
|
|
);
|
|
|
|
useEffect(() => {
|
|
setItems([]);
|
|
setNextPg(1);
|
|
setHasMore(true);
|
|
load(1, true);
|
|
}, [region]);
|
|
|
|
const goPage = (pg: number) => {
|
|
if (pg < 1) return;
|
|
setItems([]);
|
|
setNextPg(pg);
|
|
load(pg, true);
|
|
};
|
|
|
|
return (
|
|
<PageLayout activePath='/anime'>
|
|
<div className='px-4 sm:px-8 lg:px-12 py-4 sm:py-8'>
|
|
<h1 className='text-xl font-bold text-gray-800 dark:text-gray-200 mb-1'>动漫</h1>
|
|
<p className='text-xs text-gray-500 dark:text-gray-400 mb-4'>
|
|
聚合各资源站全部动漫内容(国产 / 日韩 / 欧美 / 港台)
|
|
</p>
|
|
|
|
<div className='flex flex-col sm:flex-row sm:items-center gap-2 mb-6'>
|
|
<span className='text-xs sm:text-sm font-medium text-gray-600 dark:text-gray-400 min-w-[48px]'>
|
|
地区
|
|
</span>
|
|
<div className='flex flex-wrap gap-2'>
|
|
{REGION_OPTS.map((o) => {
|
|
const on = region === o.value;
|
|
return (
|
|
<button
|
|
key={o.value || 'all'}
|
|
onClick={() => setRegion(o.value)}
|
|
className={
|
|
'px-3 py-1.5 text-xs sm:text-sm font-medium rounded-full transition-all duration-200 whitespace-nowrap ' +
|
|
(on
|
|
? 'bg-purple-500 text-white shadow-sm'
|
|
: 'bg-gray-200/60 text-gray-700 hover:bg-gray-300/60 dark:bg-gray-700/60 dark:text-gray-300 dark:hover:bg-gray-600/60')
|
|
}
|
|
>
|
|
{o.label}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
{err ? <div className='text-sm text-red-500 mb-4'>{err}</div> : null}
|
|
{refreshing && items.length === 0 ? (
|
|
<div className='text-sm text-gray-500 dark:text-gray-400'>加载中…</div>
|
|
) : items.length === 0 ? (
|
|
<div className='text-sm text-gray-500 dark:text-gray-400'>
|
|
暂无动漫内容,试试切换地区
|
|
</div>
|
|
) : (
|
|
<div className='grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4'>
|
|
{items.map((v) => (
|
|
<VideoCard
|
|
key={v.source + ':' + v.id}
|
|
id={v.id}
|
|
source={v.source}
|
|
source_name={v.source_name}
|
|
title={v.title}
|
|
poster={v.poster}
|
|
episodes={v.episodes}
|
|
year={v.year}
|
|
douban_id={v.douban_id ? String(v.douban_id) : ''}
|
|
from='search'
|
|
type={v.episodes > 1 ? 'tv' : 'movie'}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<div className='py-6 flex items-center justify-center gap-3 text-sm'>
|
|
<button
|
|
onClick={() => goPage(nextPg - 2)}
|
|
disabled={nextPg <= 2}
|
|
className='px-3 py-1.5 rounded bg-gray-200/60 dark:bg-gray-700/60 disabled:opacity-40'
|
|
>
|
|
上一页
|
|
</button>
|
|
<span className='text-gray-500 dark:text-gray-400'>第 {Math.max(1, nextPg - 1)} 页</span>
|
|
<button
|
|
onClick={() => goPage(nextPg)}
|
|
disabled={!hasMore}
|
|
className='px-3 py-1.5 rounded bg-gray-200/60 dark:bg-gray-700/60 disabled:opacity-40'
|
|
>
|
|
下一页
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</PageLayout>
|
|
);
|
|
}
|
|
|
|
export default function AnimePage() {
|
|
return (
|
|
<Suspense>
|
|
<AnimeClient />
|
|
</Suspense>
|
|
);
|
|
}
|