/* eslint-disable @next/next/no-img-element */ import { AdSlot } from '@/components/GoogleAdsense' import { deepClone } from '@/lib/utils' import { useState } from 'react' /** * 游戏列表 * @returns */ export const GameListIndexCombine = ({ games }) => { const gamesClone = deepClone(games) gamesClone?.sort((a, b) => { const orderA = a.order || 999 const orderB = b.order || 999 return orderA - orderB }) // 构造一个List const components = [] // 根据序号随机大小;或根据game.recommend 决定 const recommend = true let index = 0 // 无限循环 if (recommend) { // 4合一卡组 let groupItems = [] while (gamesClone?.length > 0) { index++ // 广告位 if (index % 9 === 0) { components.push() continue } // 试图将4合一卡组塞满 while (gamesClone?.length > 0 && groupItems.length < 4) { const item = gamesClone.shift() if (item.recommend) { components.push() break } else { groupItems.push(item) } } if (groupItems.length === 4 || (gamesClone.length === 0 && groupItems.length > 4)) { components.push() groupItems = [] } else { while (groupItems.length > 0) { const item = groupItems.shift() components.push() } } } } else { while (gamesClone?.length > 0) { index++ if (index % 6 === 0) { components.push() } else if (index % 2 === 0 && gamesClone?.length >= 4) { // 如果是偶数,则从游戏列表中退出4个组成大卡牌 const groupItems = [] for (let i = 1; i <= 4; i++) { groupItems.push(gamesClone.shift()) } components.push() } else { const item = gamesClone.shift() components.push() } } } return (
{components?.map((ItemComponent, index) => { return ItemComponent })}
) } /** * 一个广告游戏大卡 * @returns */ const GameAd = () => { return (
) } /** * 4卡组成一个大卡 * @param {*} param0 * @returns */ const GameItemGroup = ({ items }) => { return (
{items.map((item, index) => ( ))}
) } /** * 游戏=单卡 * @param {*} param0 * @returns */ const GameItem = ({ item, isLargeCard }) => { const { id, title, img, video } = item const [showType, setShowType] = useState('img') // img or video return ( { setShowType('video') }} onMouseOut={() => { setShowType('img') }} title={title} className={`card-single ${ isLargeCard ? 'h-[20rem]' : 'h-full' } w-full relative shadow rounded-md overflow-hidden flex justify-center items-center group hover:border-purple-400`}>
{title}
{showType === 'video' && ( )} {title}
) }