import styles from "@components/GameList/styles.module.scss"; import React, {useEffect, useState} from "react"; import GameItem from "@components/GameItem"; import {REQ_STATUS} from "@api/config"; import SmallLoading from "@components/SmallLoading"; import {useThemeProvider} from "@contexts/themeContext"; import GameRoom from "@components/GameRoom"; import {total} from "react-big-calendar/lib/utils/dates"; const i18n =global.i18n; const objInfo={ timer:null } const GameList=({data,status,reqMore,user})=>{ // data={ // type:0,//游戏分类 // page:1, // pageSize:40, // total:42, // totalPage:1, // data:[ // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/f76d3f4a-9712-4bd1-9426-f3ab7069b6a2.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:1006,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/ff0b0511-1f48-43d1-8dd3-294bb6437b4b.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/d33b3fad-b6df-450b-bd85-528a17383043.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/5b3a4099-9462-4d3c-a854-ade78aad0d60.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/f76d3f4a-9712-4bd1-9426-f3ab7069b6a2.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/ff0b0511-1f48-43d1-8dd3-294bb6437b4b.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/d33b3fad-b6df-450b-bd85-528a17383043.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // { // gid:0,//gameid // img:"https://bc.imgix.net/game/image/5b3a4099-9462-4d3c-a854-ade78aad0d60.png?auto=format&dpr=3&w=200",//图片 // link:"",//跳转的链接 // online:100,//游戏人数 // desc:"BC Originals",//描述 // }, // ] // } const {isMobile} = useThemeProvider(); const M_LIST_COL=3; const M_LIST_ROW=1; const [selected,setSelected]=useState(-1); const [roomRow,setRoomRow]=useState({}); const [showPopRoom,setShowPopRoom]=useState(false); const roomHeight=5.2; const rowTop=roomHeight+0.75; const handleReset=(e)=>{ setSelected(-1); setRoomRow({}); } useEffect(()=>{ document.addEventListener("click",handleReset); return ()=>{ document.removeEventListener("click",handleReset); resetTimer(); } },[]) const resetTimer=()=>{ if (objInfo.timer!=null){ clearTimeout(objInfo.timer); objInfo.timer=null; } } const checkSetRoom=(e,item,row,total)=>{ let target=e.target; if (target){ let rect=target.getBoundingClientRect(); let cH = document.documentElement.clientHeight; let cB=rect.bottom; if (cH-cB>80)row=row+1; }else row=row+1; if (row>=total)row=total-1; let roomRowItem={ row:row, data:item } if (roomRow.row===row){ setRoomRow({ hide:true, ...roomRowItem }); resetTimer(); objInfo.timer=setTimeout(()=>{ setRoomRow(roomRowItem); },10) } else setRoomRow(roomRowItem); } const handleSelect=(e,data,row,total)=>{ e.stopPropagation(); if (data.id===selected){ handleReset(); } else { setSelected(data.id); checkSetRoom(e,data,row,total); } } const handlePopSelected=(e,data,row,totall)=>{ e.stopPropagation(); setRoomRow({ row:-1, data:data }); setShowPopRoom(true); } const handlePopClose=()=>{ setRoomRow({}); setShowPopRoom(false); } const renderGameListDesktop=()=>{ let list=data.data; if (list==null)list=[]; return ( <>