|
@@ -4,7 +4,7 @@ import {NavLink} from "react-router-dom";
|
|
|
import symbol from "@assets/symbol-defs.svg";
|
|
import symbol from "@assets/symbol-defs.svg";
|
|
|
import {LazyLoadImage} from "react-lazy-load-image-component";
|
|
import {LazyLoadImage} from "react-lazy-load-image-component";
|
|
|
import {useThemeProvider} from "@contexts/themeContext";
|
|
import {useThemeProvider} from "@contexts/themeContext";
|
|
|
-import GameItem from "@components/GameItem";
|
|
|
|
|
|
|
+import GameItem, {GameImgAspectRatio} from "@components/GameItem";
|
|
|
import SvgIcon from "@components/SvgIcon";
|
|
import SvgIcon from "@components/SvgIcon";
|
|
|
import styled from 'styled-components/macro';
|
|
import styled from 'styled-components/macro';
|
|
|
import GameRoom from "@components/GameRoom";
|
|
import GameRoom from "@components/GameRoom";
|
|
@@ -101,6 +101,8 @@ const GameSmallList=({data,user})=>{
|
|
|
// }
|
|
// }
|
|
|
let list=data.data;
|
|
let list=data.data;
|
|
|
if (list==null)list=[];
|
|
if (list==null)list=[];
|
|
|
|
|
+ const gameListRef = useRef(null);
|
|
|
|
|
+ const [gridInfo,setGridInfo]=useState({});
|
|
|
const handleScroll=()=>{
|
|
const handleScroll=()=>{
|
|
|
const gridList=gridListRef.current;
|
|
const gridList=gridListRef.current;
|
|
|
if (gridList!=null){
|
|
if (gridList!=null){
|
|
@@ -185,6 +187,55 @@ const GameSmallList=({data,user})=>{
|
|
|
setRoomRow({});
|
|
setRoomRow({});
|
|
|
setShowPopRoom(false);
|
|
setShowPopRoom(false);
|
|
|
}
|
|
}
|
|
|
|
|
+ const getDesktopCol=()=>{
|
|
|
|
|
+ if (width>=1264&&width<=1564)return 6;
|
|
|
|
|
+ else if (width>=963&&width<=1263)return 5;
|
|
|
|
|
+ else if (width>=622&&width<=962)return 4;
|
|
|
|
|
+ else if (width<=621)return 3;
|
|
|
|
|
+ return 7;
|
|
|
|
|
+ }
|
|
|
|
|
+ const initGridsInfo=()=>{
|
|
|
|
|
+ let parent=isMobile()?gridListMRef.current:gridListRef.current;
|
|
|
|
|
+ // if (parent!=null){
|
|
|
|
|
+ let totalCol=3;
|
|
|
|
|
+ if (!isMobile())totalCol=getDesktopCol();
|
|
|
|
|
+ let gridBaseRatio=GameImgAspectRatio;
|
|
|
|
|
+ let totalWidth=isMobile()?100*totalCol:160*totalCol;
|
|
|
|
|
+ if (parent!=null)totalWidth=parent.clientWidth;
|
|
|
|
|
+ let rowGap =parent!=null?window.getComputedStyle(parent).getPropertyValue('grid-row-gap'):"0px";
|
|
|
|
|
+ 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 formatMList = (list)=>{
|
|
|
|
|
+ let mList = [];
|
|
|
|
|
+ if (list!=null){
|
|
|
|
|
+ if (list.length<=3)mList.push(list);
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
|
|
+ let row=i%2;
|
|
|
|
|
+ let rowList=mList[row];
|
|
|
|
|
+ if (rowList==null){
|
|
|
|
|
+ rowList=[];
|
|
|
|
|
+ mList[row]=rowList;
|
|
|
|
|
+ }
|
|
|
|
|
+ rowList.push(list[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return mList;
|
|
|
|
|
+ }
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const gridList=gridListRef.current;
|
|
const gridList=gridListRef.current;
|
|
|
if (gridList) {
|
|
if (gridList) {
|
|
@@ -200,6 +251,9 @@ const GameSmallList=({data,user})=>{
|
|
|
resetTimer();
|
|
resetTimer();
|
|
|
}
|
|
}
|
|
|
}, []); // 空数组表示只在组件挂载和卸载时执行
|
|
}, []); // 空数组表示只在组件挂载和卸载时执行
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ initGridsInfo();
|
|
|
|
|
+ },[gridListRef,gridListMRef,width])
|
|
|
const onChagePage=(change=1)=>{
|
|
const onChagePage=(change=1)=>{
|
|
|
const gridList=gridListRef.current;
|
|
const gridList=gridListRef.current;
|
|
|
if (gridList){
|
|
if (gridList){
|
|
@@ -253,8 +307,12 @@ const GameSmallList=({data,user})=>{
|
|
|
<div className={styles.grid_list} ref={gridListRef}>
|
|
<div className={styles.grid_list} ref={gridListRef}>
|
|
|
{
|
|
{
|
|
|
list.map((item, index) => {
|
|
list.map((item, index) => {
|
|
|
|
|
+ let gridNum=item.gridNum!=null?item.gridNum:1;
|
|
|
|
|
+ gridNum=Math.floor(Math.random()*3)+1;
|
|
|
|
|
+ let whStyle=gridInfo[gridNum];
|
|
|
|
|
+ if (whStyle==null)return (<></>);
|
|
|
return (
|
|
return (
|
|
|
- <GameItem key={index} data={item} handleRoom={handlePopSelected}></GameItem>
|
|
|
|
|
|
|
+ <GameItem whStyle={whStyle} key={index} data={item} handleRoom={handlePopSelected}></GameItem>
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -287,29 +345,70 @@ const GameSmallList=({data,user})=>{
|
|
|
else gridStyle.rowGap=`${rowTop}rem`;
|
|
else gridStyle.rowGap=`${rowTop}rem`;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ let rowlist=formatMList(list);
|
|
|
|
|
+ console.log(rowlist);
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
- <div className={`${styles.grid_list_m} ${len<5?styles.grid_list_m_onerow:''}`} ref={gridListMRef} style={gridStyle}>
|
|
|
|
|
- {
|
|
|
|
|
- list.map((item, index) => {
|
|
|
|
|
- let itemStyle={}
|
|
|
|
|
- if (selected!==-1){
|
|
|
|
|
- let row=index%2;
|
|
|
|
|
- if (item.id!==selected){
|
|
|
|
|
- itemStyle.filter="brightness(60%)";
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- itemStyle.transform="scale(1.02)";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return (
|
|
|
|
|
- <GameItem key={index} data={item} handleRoom={(e,data)=>{
|
|
|
|
|
- handleSelect(e,data);
|
|
|
|
|
- }} style={itemStyle}></GameItem>
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ <div className={`${styles.grid_list_m}`} ref={gridListMRef} style={gridStyle}>
|
|
|
|
|
+ <div className={styles.grid_row_con}>
|
|
|
|
|
+ {
|
|
|
|
|
+ rowlist.map((ritem,rindex)=>{
|
|
|
|
|
+ if (ritem==null)return (<></>);
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div key={rindex} className={styles.grid_row}>
|
|
|
|
|
+ {
|
|
|
|
|
+ ritem.map((item,index)=>{
|
|
|
|
|
+ let itemStyle={}
|
|
|
|
|
+ if (selected!==-1){
|
|
|
|
|
+ let row=index%2;
|
|
|
|
|
+ if (item.id!==selected){
|
|
|
|
|
+ itemStyle.filter="brightness(60%)";
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ itemStyle.transform="scale(1.02)";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let gridNum=item.gridNum!=null?item.gridNum:1;
|
|
|
|
|
+ gridNum=Math.floor(Math.random()*3)+1;
|
|
|
|
|
+ let whStyle=gridInfo[gridNum];
|
|
|
|
|
+ if (whStyle==null)return (<></>);
|
|
|
|
|
+ return (
|
|
|
|
|
+ <GameItem whStyle={whStyle} key={index} data={item} handleRoom={(e,data)=>{
|
|
|
|
|
+ handleSelect(e,data);
|
|
|
|
|
+ }} style={itemStyle}></GameItem>
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {/*{*/}
|
|
|
|
|
+ {/* list.map((item, index) => {*/}
|
|
|
|
|
+ {/* let itemStyle={}*/}
|
|
|
|
|
+ {/* if (selected!==-1){*/}
|
|
|
|
|
+ {/* let row=index%2;*/}
|
|
|
|
|
+ {/* if (item.id!==selected){*/}
|
|
|
|
|
+ {/* itemStyle.filter="brightness(60%)";*/}
|
|
|
|
|
+ {/* }*/}
|
|
|
|
|
+ {/* else*/}
|
|
|
|
|
+ {/* {*/}
|
|
|
|
|
+ {/* itemStyle.transform="scale(1.02)";*/}
|
|
|
|
|
+ {/* }*/}
|
|
|
|
|
+ {/* }*/}
|
|
|
|
|
+ {/* let gridNum=item.gridNum!=null?item.gridNum:1;*/}
|
|
|
|
|
+ {/* gridNum=Math.floor(Math.random()*3)+1;*/}
|
|
|
|
|
+ {/* let whStyle=gridInfo[gridNum];*/}
|
|
|
|
|
+ {/* if (whStyle==null)return (<></>);*/}
|
|
|
|
|
+ {/* return (*/}
|
|
|
|
|
+ {/* <GameItem whStyle={whStyle} key={index} data={item} handleRoom={(e,data)=>{*/}
|
|
|
|
|
+ {/* handleSelect(e,data);*/}
|
|
|
|
|
+ {/* }} style={itemStyle}></GameItem>*/}
|
|
|
|
|
+ {/* )*/}
|
|
|
|
|
+ {/* })*/}
|
|
|
|
|
+ {/*}*/}
|
|
|
</div>
|
|
</div>
|
|
|
<StyledRoomCon top={roomTop}>
|
|
<StyledRoomCon top={roomTop}>
|
|
|
{renderRoom()}
|
|
{renderRoom()}
|