Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/app/ContestSite/ManagerPage/EditTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const EditTimeline: React.FC<ContestProps> = ({ mode, user }) => {
});
const [addContestTime, { error: addContestTimeError }] =
graphql.useAddContestTimeMutation();
const [deleteContestTime, { error: deleteContestTimeError }] =
graphql.useDeleteContestTimeMutation(); // 添加删除事件的 mutation

/* ---------------- useEffect ---------------- */
useEffect(() => {
if (getContestTimesError) {
Expand All @@ -53,6 +56,11 @@ const EditTimeline: React.FC<ContestProps> = ({ mode, user }) => {
message.error("添加事件失败");
}
}, [addContestTimeError]);
useEffect(() => {
if (deleteContestTimeError) {
message.error("删除事件失败");
}
}, [deleteContestTimeError]);
/* ---------------- 业务逻辑函数 ---------------- */
const handleAdd = async () => {
try {
Expand All @@ -75,6 +83,24 @@ const EditTimeline: React.FC<ContestProps> = ({ mode, user }) => {
}
};

const handleDelete = async (event: string) => {
try {
await deleteContestTime({
variables: {
contest_id: Contest_id,
event: event,
},
});
if (deleteContestTimeError)
throw new Error(deleteContestTimeError.message);
message.success("事件删除成功");
refetchContestTimes(); // 刷新事件列表
} catch (e) {
console.log(e);
message.error("删除事件失败");
}
};

const panelStyle: React.CSSProperties = {
marginBottom: 12,
background: token.colorFillAlter,
Expand All @@ -92,9 +118,18 @@ const EditTimeline: React.FC<ContestProps> = ({ mode, user }) => {
{dayjs(item.end).format("YYYY-MM-DD")}
<br />
描述:{item.description}
<br />
<Button
danger
onClick={() => handleDelete(item.event)}
style={{ marginTop: "10px" }}
>
删除事件
</Button>
</>
),
}));

/* ---------------- ⻚⾯组件 ---------------- */
return (
<Layout>
Expand Down
164 changes: 81 additions & 83 deletions src/app/ContestSite/ManagerPage/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Card, Checkbox, message, Space, Typography } from "antd";
import { useUrl } from "../../../api/hooks/url";
import * as graphql from "@/generated/graphql";
import { ContestProps } from "..";
/* ---------------- 不随渲染刷新的常量 ---------------- */
const { Title } = Typography;
/* ---------------- 主页面 ---------------- */
const Setting: React.FC<ContestProps> = (props) => {
//获取比赛ID

// 扩展 Props 类型,增加 isHardware
interface SettingProps extends ContestProps {
isHardware?: boolean;
}

const Setting: React.FC<SettingProps> = (props) => {
const url = useUrl();
const Contest_id = url.query.get("contest");

Expand All @@ -27,29 +29,15 @@ const Setting: React.FC<ContestProps> = (props) => {
useEffect(() => {
if (updateSwitchError) {
message.error("比赛状态更新失败");
console.log(updateSwitchError.message);
}
}, [updateSwitchError]);

useEffect(() => {
if (contestSwitchError) {
message.error("获取比赛状态失败");
console.log(contestSwitchError.message);
}
}, [contestSwitchError]);

return (
<Card
hoverable
style={{
padding: "2vh 1vw",
minHeight: "480px",
}}
>
<Title level={2} style={{ margin: `0 0 36px` }}>
<Card hoverable style={{ height: "100%" }}>
<Typography.Title level={2} style={{ margin: `0 0 24px` }}>
比赛设置
</Title>
<Space direction="vertical" size="large">
</Typography.Title>
<Space direction="vertical">
<Checkbox
checked={contestSwitchData?.contest_by_pk?.team_switch === true}
onChange={async (e) => {
Expand Down Expand Up @@ -82,66 +70,76 @@ const Setting: React.FC<ContestProps> = (props) => {
>
上传代码
</Checkbox>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.arena_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
arena_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
天梯对战
</Checkbox>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.playground_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
playground_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
试玩功能
</Checkbox>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.stream_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
stream_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
直播功能
</Checkbox>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.playback_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
playback_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
回放功能
</Checkbox>

{/* 如果是硬件设计,隐藏以下所有与 WebGL/对战相关的开关 */}
{!props.isHardware && (
<>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.arena_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
arena_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
天梯功能
</Checkbox>
<Checkbox
checked={
contestSwitchData?.contest_by_pk?.playground_switch === true
}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
playground_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
试玩功能
</Checkbox>
<Checkbox
checked={contestSwitchData?.contest_by_pk?.stream_switch === true}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
stream_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
直播功能
</Checkbox>
<Checkbox
checked={
contestSwitchData?.contest_by_pk?.playback_switch === true
}
onChange={async (e) => {
await updateContestSwitch({
variables: {
contest_id: Contest_id,
...contestSwitchData?.contest_by_pk!,
playback_switch: e.target.checked,
},
});
refetchContestSwitch();
}}
>
回放功能
</Checkbox>
</>
)}
</Space>
</Card>
);
Expand Down
Loading