Files
katelyatv/src/components/HkDramaRow.tsx
T
3970260761 2e8ee2eb64
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
fixed70: 最新港剧10个+加载骨架占位(与热门栏目同时出现)
2026-11-07 18:43:24 +08:00

110 lines
3.9 KiB
TypeScript

'use client';
import Link from 'next/link';
import { useEffect, useState } from 'react';
type VodItem = {
vod_id?: string | number;
vod_name?: string;
vod_pic?: string;
vod_remarks?: string;
vod_year?: string;
vod_time?: string;
};
const SHOW_COUNT = 10;
export default function HkDramaRow() {
const [items, setItems] = useState<VodItem[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch('/api/tvbox/all?ac=videolist&t=902&pg=1&by=time')
.then((r) => r.json())
.then((j) => {
const arr = (((j && j.list) as VodItem[]) || []).slice();
arr.sort((a, b) => {
const ya = parseInt(a.vod_year || '', 10) || 0;
const yb = parseInt(b.vod_year || '', 10) || 0;
if (yb !== ya) return yb - ya;
return String(b.vod_time || '').localeCompare(
String(a.vod_time || '')
);
});
setItems(arr.slice(0, SHOW_COUNT));
})
.catch(() => {})
.finally(() => setLoading(false));
}, []);
// 加载失败且无数据时不占位;加载中显示骨架占位,与其它栏目同时出现
if (!loading && !items.length) return null;
return (
<section className='mb-8'>
<div className='mb-4 flex items-center justify-between'>
<h2 className='text-xl font-bold text-gray-800 dark:text-gray-200'>
最新港剧
</h2>
<Link
href='/filter?t=香港剧'
className='flex items-center text-sm text-gray-500 hover:text-purple-700 dark:text-gray-400 dark:hover:text-purple-300 transition-colors'
>
查看更多
</Link>
</div>
<div className='grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4 relative'>
{loading
? // 加载中显示10个占位,与热门电影/剧集同时出现,避免后半拍跳动
Array.from({ length: SHOW_COUNT }).map((_, index) => (
<div key={index} className='w-full'>
<div className='relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-purple-200 animate-pulse dark:bg-purple-800'>
<div className='absolute inset-0 bg-purple-300 dark:bg-purple-700'></div>
</div>
<div className='mt-2 h-4 bg-purple-200 rounded animate-pulse dark:bg-purple-800'></div>
</div>
))
: items.map((v) => {
const key = String(v.vod_id || '');
const sep = key.indexOf(':');
const ks = sep > 0 ? key.slice(0, sep) : '';
const kid = sep > 0 ? key.slice(sep + 1) : key;
const pic = v.vod_pic
? '/api/image-proxy?url=' + encodeURIComponent(v.vod_pic)
: '';
return (
<Link
key={key}
href={`/play?source=${encodeURIComponent(
ks
)}&id=${encodeURIComponent(kid)}&stitle=${encodeURIComponent(
v.vod_name || ''
)}&stype=tv`}
className='group block'
>
<div className='relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-gray-200 dark:bg-gray-800'>
{pic ? (
<img
src={pic}
alt={v.vod_name || ''}
loading='lazy'
className='absolute inset-0 w-full h-full object-cover group-hover:scale-105 transition-transform duration-300'
/>
) : null}
{v.vod_remarks ? (
<span className='absolute bottom-1 right-1 px-1.5 py-0.5 text-xs bg-black/65 text-white rounded'>
{v.vod_remarks}
</span>
) : null}
</div>
<div className='mt-2 text-sm font-medium text-gray-800 dark:text-gray-200 truncate'>
{v.vod_name}
</div>
</Link>
);
})}
</div>
</section>
);
}