mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-22 02:24:44 +08:00
Merge pull request #42 from OuOumm/main
refactor(components): 优化卡片组件样式和交互逻辑
This commit is contained in:
@@ -30,23 +30,19 @@ function SearchPageClient() {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
// 视图模式:聚合(agg) 或 全部(all),默认值由环境变量 NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT 决定
|
||||
const [viewMode, setViewMode] = useState<'agg' | 'all'>(() => {
|
||||
const envVal = process.env.NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT;
|
||||
// 默认聚合('agg')。当显式设置为 'false' 或 '0' 时使用 'all'
|
||||
if (envVal === 'false' || envVal === '0') {
|
||||
return 'all';
|
||||
}
|
||||
return 'agg';
|
||||
});
|
||||
const [viewMode, setViewMode] = useState<'agg' | 'all'>(
|
||||
process.env.NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT === 'false' ||
|
||||
process.env.NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT === '0'
|
||||
? 'all'
|
||||
: 'agg'
|
||||
);
|
||||
|
||||
// 聚合后的结果(按标题和年份分组)
|
||||
const aggregatedResults = useMemo(() => {
|
||||
const map = new Map<string, SearchResult[]>();
|
||||
searchResults.forEach((item) => {
|
||||
// 使用 title + year 作为键,若 year 不存在则使用 'unknown'
|
||||
const key = `${item.title}-${item.year || 'unknown'}-${
|
||||
item.episodes.length === 1 ? 'movie' : 'tv'
|
||||
}`;
|
||||
// 使用 title + year + id 作为键,若 year 不存在则使用 'unknown'
|
||||
const key = `${item.title}-${item.year || 'unknown'}-${item.id}`;
|
||||
const arr = map.get(key) || [];
|
||||
arr.push(item);
|
||||
map.set(key, arr);
|
||||
@@ -55,16 +51,9 @@ function SearchPageClient() {
|
||||
}, [searchResults]);
|
||||
|
||||
useEffect(() => {
|
||||
// 自动聚焦搜索框:仅当 URL 中没有搜索参数时
|
||||
if (!searchParams.get('q')) {
|
||||
searchInputRef.current?.focus();
|
||||
}
|
||||
|
||||
// 加载搜索历史
|
||||
(async () => {
|
||||
const history = await getSearchHistory();
|
||||
setSearchHistory(history);
|
||||
})();
|
||||
// 无搜索参数时聚焦搜索框
|
||||
!searchParams.get('q') && searchInputRef.current?.focus();
|
||||
getSearchHistory().then(setSearchHistory);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -172,13 +161,13 @@ function SearchPageClient() {
|
||||
</div>
|
||||
<div
|
||||
key={`search-results-${viewMode}`}
|
||||
className='justify-start grid grid-cols-3 gap-x-2 gap-y-14 sm:gap-y-20 px-0 sm:px-2 sm:grid-cols-[repeat(auto-fill,_minmax(11rem,_1fr))] sm:gap-x-8 sm:px-4'
|
||||
className='justify-start grid grid-cols-3 gap-x-2 gap-y-14 sm:gap-y-20 px-0 sm:px-2 sm:grid-cols-[repeat(auto-fill,_minmax(11rem,_1fr))] sm:gap-x-8'
|
||||
>
|
||||
{viewMode === 'agg'
|
||||
? aggregatedResults.map((group) => {
|
||||
const key = `${group[0].title}-${
|
||||
group[0].year || 'unknown'
|
||||
}`;
|
||||
}-${group[0].id}`;
|
||||
return (
|
||||
<div key={`agg-${key}`} className='w-full'>
|
||||
<AggregateCard
|
||||
|
||||
@@ -52,7 +52,7 @@ function PlayCircleSolid({
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 `VideoCard` 基本一致,删除了集数徽标、来源标签、收藏等功能
|
||||
* 与 `VideoCard` 基本一致,删除了来源标签、收藏等功能
|
||||
* 点击播放按钮 -> 跳到第一个源播放
|
||||
* 点击卡片其他区域 -> 跳到聚合详情页 (/aggregate)
|
||||
*/
|
||||
@@ -161,9 +161,9 @@ const AggregateCard: React.FC<AggregateCardProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 集数矩形展示框 - 不透明,无hover效果 */}
|
||||
{/* 集数矩形展示框 */}
|
||||
{mostFrequentEpisodes && mostFrequentEpisodes > 1 && (
|
||||
<div className='absolute top-2 right-2 min-w-[1.875rem] h-5 sm:h-7 sm:min-w-[2.5rem] bg-green-500 dark:bg-green-600 rounded-md flex items-center justify-center px-2 shadow-md text-[0.55rem] sm:text-xs'>
|
||||
<div className='absolute top-2 right-2 w-7 h-7 sm:w-7 sm:h-7 rounded-full bg-green-500/90 dark:bg-green-600/90 flex items-center justify-center shadow-md text-[0.55rem] sm:text-xs'>
|
||||
<span className='text-white font-bold leading-none'>
|
||||
{mostFrequentEpisodes}
|
||||
</span>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Link as LinkIcon, Search } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
interface DemoCardProps {
|
||||
id: string;
|
||||
@@ -45,6 +45,7 @@ function SearchCircle({
|
||||
}
|
||||
|
||||
const DemoCard = ({ id, title, poster, rate, type }: DemoCardProps) => {
|
||||
const [hover, setHover] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleClick = () => {
|
||||
@@ -57,7 +58,7 @@ const DemoCard = ({ id, title, poster, rate, type }: DemoCardProps) => {
|
||||
onClick={handleClick}
|
||||
>
|
||||
{/* 海报图片区域 */}
|
||||
<div className='relative aspect-[2/3] w-full overflow-hidden rounded-md transition-all duration-400 cubic-bezier(0.4, 0, 0.2, 1)'>
|
||||
<div className='relative aspect-[2/3] w-full overflow-hidden rounded-md group-hover:scale-[1.02] transition-all duration-400 cubic-bezier(0.4, 0, 0.2, 1) safari-fix'>
|
||||
<Image
|
||||
src={poster}
|
||||
alt={title}
|
||||
@@ -77,12 +78,15 @@ const DemoCard = ({ id, title, poster, rate, type }: DemoCardProps) => {
|
||||
)}
|
||||
|
||||
{/* 悬浮层 - 搜索按钮 */}
|
||||
<div
|
||||
style={{ willChange: 'opacity' }}
|
||||
className='absolute inset-0 bg-gradient-to-t from-black/70 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-300 cubic-bezier(0.4, 0, 0.2, 1) flex items-center justify-center'
|
||||
>
|
||||
<div className='transition-all duration-300 cubic-bezier(0.4, 0, 0.2, 1) scale-90 group-hover:scale-110 group-hover:rotate-12'>
|
||||
<SearchCircle className='group-hover:fill-green-500' />
|
||||
<div className='absolute inset-0 bg-gradient-to-t from-black/70 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-300 cubic-bezier(0.4, 0, 0.2, 1) flex items-center justify-center'>
|
||||
<div
|
||||
onMouseEnter={() => setHover(true)}
|
||||
onMouseLeave={() => setHover(false)}
|
||||
className={`transition-all duration-300 cubic-bezier(0.4, 0, 0.2, 1) ${
|
||||
hover ? 'scale-110 rotate-12' : 'scale-90'
|
||||
}`}
|
||||
>
|
||||
<SearchCircle fillColor={hover ? '#22c55e' : 'none'} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -111,12 +111,6 @@ export default function VideoCard({
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// 如果是从收藏夹移除,立即更新UI
|
||||
if (favorited && from === 'favorites') {
|
||||
setIsDeleting(true);
|
||||
onDelete?.();
|
||||
}
|
||||
|
||||
try {
|
||||
const newState = await toggleFavorite(source, id, {
|
||||
title,
|
||||
@@ -237,23 +231,23 @@ export default function VideoCard({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 集数矩形展示框 - 增加条件判断:仅当有多个集数且已播放时显示 */}
|
||||
{/* 继续观看 - 集数矩形展示框 */}
|
||||
{episodes && episodes > 1 && currentEpisode && (
|
||||
<div className='absolute top-2 right-2 min-w-[1.875rem] h-5 sm:h-7 sm:min-w-[2.5rem] bg-green-500/90 dark:bg-green-600/90 rounded-md flex items-center justify-center px-2 shadow-md text-[0.55rem] sm:text-xs'>
|
||||
<span className='text-white font-bold leading-none'>
|
||||
{currentEpisode}
|
||||
<span className='mx-1 text-white/80'>/</span>
|
||||
</span>
|
||||
<span className='mx-1 text-white/80'>/</span>
|
||||
<span className='text-white font-bold leading-none'>
|
||||
{episodes}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 集数圆形展示框 - 无当前集数且总集数大于 1 时展示 */}
|
||||
{episodes && episodes > 1 && !currentEpisode && (
|
||||
<div className='absolute top-2 right-2 w-4 h-4 sm:w-7 sm:h-7 bg-green-500 rounded-full flex items-center justify-center'>
|
||||
<span className='text-white text-[0.5rem] sm:text-xs font-bold'>
|
||||
{/* 搜索非聚合 - 集数圆形展示框 */}
|
||||
{from === 'search' && (
|
||||
<div className='absolute top-2 right-2 w-4 h-4 sm:w-7 sm:h-7 rounded-full bg-green-500/90 dark:bg-green-600/90 flex items-center justify-center shadow-md text-[0.55rem] sm:text-xs'>
|
||||
<span className='text-white font-bold leading-none'>
|
||||
{episodes}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user