|
|
@@ -1,24 +1,15 @@
|
|
|
import styles from "@components/GameList/styles.module.scss";
|
|
|
import React, {useEffect, useRef, useState} from "react";
|
|
|
-import GameItem from "@components/GameItem";
|
|
|
+import GameItem, {GameImgAspectRatio, GameItemImgAspectRatio} 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";
|
|
|
-import styled from 'styled-components/macro';
|
|
|
import {useWindowSize} from "react-use";
|
|
|
const i18n =global.i18n;
|
|
|
const objInfo={
|
|
|
timer:null
|
|
|
}
|
|
|
-const StyledListRow=styled.div`
|
|
|
- ${(props) => {
|
|
|
- return `
|
|
|
- grid-template-columns: none !important;
|
|
|
- `
|
|
|
- }}
|
|
|
-`
|
|
|
const GameList=({data,status,reqMore,user})=>{
|
|
|
// data={
|
|
|
// type:0,//游戏分类
|
|
|
@@ -85,7 +76,7 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
// },
|
|
|
// ]
|
|
|
// }
|
|
|
- const {isMobile} = useThemeProvider();
|
|
|
+ const {isMobile,fontScale} = useThemeProvider();
|
|
|
const M_LIST_COL=3;
|
|
|
const M_LIST_ROW=1;
|
|
|
const [selected,setSelected]=useState(-1);
|
|
|
@@ -108,8 +99,30 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
}
|
|
|
},[])
|
|
|
useEffect(()=>{
|
|
|
-
|
|
|
+ initGridsInfo();
|
|
|
},[gameListRef,width])
|
|
|
+ const initGridsInfo=()=>{
|
|
|
+ let parent=gameListRef.current;
|
|
|
+ if (parent!=null){
|
|
|
+ let totalCol=3;
|
|
|
+ if (!isMobile())totalCol=7;
|
|
|
+ let gridBaseRatio=GameImgAspectRatio;
|
|
|
+ let totalWidth=parent.clientWidth;
|
|
|
+ let rowGap = window.getComputedStyle(parent).getPropertyValue('grid-row-gap');
|
|
|
+ let gap=Number(rowGap.replace("px",""));
|
|
|
+ if (gap===0||isNaN(gap))gap=0.75*16*fontScale;
|
|
|
+ let gridsData={};
|
|
|
+ for (let i=1;i<=6;i++){
|
|
|
+ let gridNum=i;
|
|
|
+ let gridWidth=(totalWidth-(totalCol-1)*gap)/totalCol;
|
|
|
+ let itemWidth=gridWidth*gridNum+(gridNum-1)*gap;
|
|
|
+ let width=itemWidth+"px";
|
|
|
+ let aspectRatio=gridBaseRatio*(itemWidth/gridWidth);
|
|
|
+ gridsData[i]={width,aspectRatio};
|
|
|
+ }
|
|
|
+ setGridInfo(gridsData);
|
|
|
+ }
|
|
|
+ }
|
|
|
const resetTimer=()=>{
|
|
|
if (objInfo.timer!=null){
|
|
|
clearTimeout(objInfo.timer);
|
|
|
@@ -164,35 +177,19 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
setRoomRow({});
|
|
|
setShowPopRoom(false);
|
|
|
}
|
|
|
- const getGridItemStyle=(parent,totalCol,gridNum)=>{
|
|
|
- const gridBaseRatio=384/516;
|
|
|
- let width="0px";
|
|
|
- let aspectRatio=gridBaseRatio;
|
|
|
- if (parent!=null){
|
|
|
- let totalWidth=parent.clientWidth;
|
|
|
- let rowGap = window.getComputedStyle(parent).getPropertyValue('grid-row-gap');
|
|
|
- let gap=Number(rowGap.replace("px",""));
|
|
|
- let gridWidth=(totalWidth-(totalCol-1)*gap)/totalCol;
|
|
|
- let gridNum=gridNum!=null?gridNum:1;
|
|
|
- let itemWidth=gridWidth*gridNum+(gridNum-1)*gap;
|
|
|
- width=itemWidth+"px";
|
|
|
- aspectRatio=gridBaseRatio*(itemWidth/gridWidth);
|
|
|
- }
|
|
|
- return {
|
|
|
- width,
|
|
|
- aspectRatio
|
|
|
- }
|
|
|
- }
|
|
|
const renderGameListDesktop=()=>{
|
|
|
let list=data.data;
|
|
|
if (list==null)list=[];
|
|
|
return (
|
|
|
<>
|
|
|
- <div id={"gameList"} className={styles.game_list}>
|
|
|
+ <div ref={gameListRef} id={"gameList"} className={styles.game_list}>
|
|
|
{
|
|
|
list.map((item, index) => {
|
|
|
+ let gridNum=item.gridNum!=null?item.gridNum:1;
|
|
|
+ // gridNum=Math.floor(Math.random()*3)+1;
|
|
|
+ let whStyle=gridInfo[gridNum];
|
|
|
return (
|
|
|
- <GameItem key={index} data={item} handleRoom={handlePopSelected}></GameItem>
|
|
|
+ <GameItem key={index} data={item} handleRoom={handlePopSelected} whStyle={whStyle}></GameItem>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
@@ -211,9 +208,7 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
let count=0;
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
let item = list[i];
|
|
|
- let gridNum=1;
|
|
|
- gridNum=Math.floor(Math.random()*M_LIST_COL)+1;
|
|
|
- gridNum=(count%M_LIST_COL+gridNum)>M_LIST_COL?1:gridNum;
|
|
|
+ let gridNum=item.gridNum!=null?item.gridNum:1;
|
|
|
let row=Math.floor(count/M_LIST_COL);
|
|
|
let rowData=mList[row];
|
|
|
if (rowData==null)rowData=[];
|
|
|
@@ -243,7 +238,7 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
list=formatMList(list);
|
|
|
let len=list.length;
|
|
|
return (
|
|
|
- <div id={"gameList"} className={styles.game_list_mobile}>
|
|
|
+ <div ref={gameListRef} id={"gameList"} className={styles.game_list_mobile}>
|
|
|
{
|
|
|
list.map((rowArr,row)=>{
|
|
|
let rowStyle={};
|
|
|
@@ -273,10 +268,13 @@ const GameList=({data,status,reqMore,user})=>{
|
|
|
itemStyle.transform="scale(1.05)";
|
|
|
}
|
|
|
}
|
|
|
+ let gridNum=item.gridNum!=null?item.gridNum:1;
|
|
|
+ gridNum=Math.floor(Math.random()*3)+1;
|
|
|
+ let whStyle=gridInfo[gridNum];
|
|
|
return (
|
|
|
<GameItem key={col} data={item} handleRoom={(e,data)=>{
|
|
|
handleSelect(e,data,row,len)
|
|
|
- }} row={row} style={itemStyle}></GameItem>
|
|
|
+ }} row={row} whStyle={whStyle} style={itemStyle}></GameItem>
|
|
|
)
|
|
|
})
|
|
|
}
|