feat: prefix and anti multi-check

This commit is contained in:
KirinBaka
2025-04-22 15:34:22 +08:00
parent bebf2c9640
commit ffc89fd069
10 changed files with 46 additions and 28 deletions

View File

@@ -22,25 +22,35 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
count += 1;
if (count >= config.limit) {
res.status(403).json({
error: `超过选择数量限制,您至多选 ${config.limit} 个班.`,
error: `超过选择数量限制,您至多选 ${config.limit} 个班`,
});
return;
}
}
}
// check whether it is already occupied
if (store[json.name] !== undefined) {
// check whether the user repeatly select
if (store[json.name] === json.user) {
console.log("api::request: repeat select", json);
res.status(403).json({
error: `当前位置已被他人占用`,
error: `您已经选择了这个班次,请勿重复选择`,
});
return;
}
// check whether it is already occupied
else if (store[json.name] !== undefined) {
console.log("api::request: occupied", json);
res.status(403).json({
error: `当前位置已被他人占用,请选择其他班次`,
});
return;
}
store[json.name] = json.user;
} else {
// console.log(store, json);
// check whether the request name match the taken name
if (store[json.name] !== json.user) {
res.status(403).json({
error: `失败:您未选择到当前位置`,
error: `您已经取消了这个班次,请勿重复点击复选框`,
})
return;
}

View File

@@ -10,8 +10,8 @@ export default function Home() {
<>
<Head>
<title> </title>
<meta name="description" content="ITSC抢班系统" />
{/* <meta name="viewport" content="width=device-width, initial-scale=1" /> */}
<meta name="description" content="ITSC 学 生 助 理 抢 班 系 统" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>

View File

@@ -1,14 +1,13 @@
import React from "react";
import Head from "next/head";
import { get, post } from "@/common";
const ReportPage = () => {
const ref = React.useRef();
const getReport = async () => {
const resp = await fetch("/api/html").then((resp) => resp.json());
const resp = await get("/api/html");
ref.current.innerHTML = resp.html;
const json: Record<string, string> = await fetch("/api/tool").then((resp) =>
resp.json()
);
const json: Record<string, string> = await get("/api/tool");
const table = ref.current.children[0];
const tbody = table.children[table.children.length - 1];
for (const tr_index in tbody.children) {

View File

@@ -1,14 +1,13 @@
import React from "react";
import Head from "next/head";
import { get, post } from "@/common";
const ReportPage = () => {
const ref = React.useRef();
const getReport = async () => {
const resp = await fetch("/api/html").then((resp) => resp.json());
const resp = await get("/api/html");
ref.current.innerHTML = resp.html;
const json: Record<string, string> = await fetch("/api/admin").then(
(resp) => resp.json()
);
const json: Record<string, string> = await get("/api/admin");
const table = ref.current.children[0];
const tbody = table.children[table.children.length - 1];
for (const tr_index in tbody.children) {

View File

@@ -7,7 +7,7 @@ export default function Home() {
const [begin, setBegin] = React.useState(false);
React.useEffect(() => {
setUser(localStorage.getItem("user") || "");
setUser(localStorage.getItem("username") || "");
}, []);
return (
@@ -34,7 +34,7 @@ export default function Home() {
}
setUser(user.trim());
setBegin(true);
localStorage.setItem("user", user);
localStorage.setItem("username", user);
}}
>
Login