diff --git a/src/components/GroupMember.tsx b/src/components/GroupMember.tsx index fb371b7..b41f69e 100644 --- a/src/components/GroupMember.tsx +++ b/src/components/GroupMember.tsx @@ -1,6 +1,6 @@ -import { Card, Table } from "antd"; +import { Button, Card, Divider, Drawer, Flex, Space, Table } from "antd"; import type { BasePlayer } from "../types"; -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import User from "./User"; interface Props { @@ -17,8 +17,13 @@ export const GroupMember: React.FC = props => { const lastChar = baseCode + (idx % 26); return `${code}${String.fromCharCode(lastChar)}`; }, []); + const [open, setOpen] = useState(false); return ( - + setOpen(true)}>查看对战表} + > `${e.id}-${e.name}-${e.score}`} @@ -32,6 +37,72 @@ export const GroupMember: React.FC = props => { { dataIndex: 'score' }, ]} /> + setOpen(false)} + size={'80vh'} + placement="bottom" + > + `(${i + 1}) ${e.name}(${e.score})`) + ?? [] + } + /> + ); +} + +function BattleTable({ nameList }: { + nameList: string[] +}) { + const list = nameList.length % 2 === 0 ? nameList : [...nameList, '-']; + return ( + + {new Array(list.length - 1).fill(0).map((_, i) => { + const [left, right] = getRoundTable(list, i); + console.debug({ left, right }); + return ( + + {left?.map((e, r) => { + return ( +
+ +
{e}
+ VS +
{right?.[r]}
+
+ {r < left.length && } +
+ ); + })} +
+ ); + })} +
+ ); +} + +function getRoundTable(nameList: string[], round: number) { + const list = [...nameList]; + const half = list.length / 2; + if (round > list.length - 1) { + const left = [...list].slice(0, half); + const right = [...list].slice(half); + return [left, right]; + } + const sliceStart = (list.length) - round; + const slice = list.slice(sliceStart); + // console.debug(JSON.stringify({ list })); + list.splice(sliceStart); + const [first, ...others] = list; + const newList = [first, ...slice, ...others].filter(Boolean); + // console.debug(JSON.stringify({ sliceStart, len: list.length, first, others, slice, newList })); + const left = [...newList].slice(0, half); + const right = [...newList].slice(half).reverse(); + return [left, right]; } \ No newline at end of file