一些微小的贡献

This commit is contained in:
KirinBaka
2025-04-22 15:19:28 +08:00
parent a04f1c22c9
commit bebf2c9640
7 changed files with 26 additions and 13 deletions

View File

@@ -115,7 +115,7 @@ const Timetable = ({
tds.length = 0; tds.length = 0;
const table = target.children[0]; const table = target.children[0];
table.setAttribute("border", "1"); table.setAttribute("border", "0");
// mark cell // mark cell
const conflictsTmp: ConflictsTmp = {}; const conflictsTmp: ConflictsTmp = {};
@@ -266,6 +266,7 @@ const Timetable = ({
<> <>
<h2 style={{ textAlign: "center" }}>Login as {user}</h2> <h2 style={{ textAlign: "center" }}>Login as {user}</h2>
<div <div
align="center"
ref={ref} ref={ref}
contentEditable={editable} contentEditable={editable}
style={{ style={{

BIN
data-init.zip Normal file

Binary file not shown.

View File

@@ -6,7 +6,7 @@
"esbuild": "./node_modules/.bin/esbuild --bundle --tsconfig=entrypoints/tsconfig.json --alias:'@'='./' --outdir=entrypoints --splitting --format=esm entrypoints/index.tsx entrypoints/edit/index.tsx entrypoints/report/index.tsx entrypoints/control/index.tsx --minify", "esbuild": "./node_modules/.bin/esbuild --bundle --tsconfig=entrypoints/tsconfig.json --alias:'@'='./' --outdir=entrypoints --splitting --format=esm entrypoints/index.tsx entrypoints/edit/index.tsx entrypoints/report/index.tsx entrypoints/control/index.tsx --minify",
"dev": "next dev", "dev": "next dev",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start -p 4000",
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {

View File

@@ -4,13 +4,14 @@ import config from "@/config";
export default function handler(req: NextApiRequest, res: NextApiResponse) { export default function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") { if (req.method === "POST") {
if (req.headers.token !== config.token) { if (req.headers.token !== config.token) {
console.log("wrong token", req.headers.token, config.token); console.log("api::config: wrong token", req.headers.token, config.token);
res.status(403).json({ error: "wrong token" }); res.status(403).json({ error: "wrong token" });
return; return;
} }
// update config // update config
config.begin = req.body.begin ?? config.begin; config.begin = req.body.begin ?? config.begin;
config.limit = req.body.limit ?? config.limit; config.limit = req.body.limit ?? config.limit;
console.log("api::config: update config", config);
} }
res.status(200).json(config); res.status(200).json(config);
} }

View File

@@ -5,6 +5,7 @@ import config from "@/config";
export default function handler(req: NextApiRequest, res: NextApiResponse) { export default function handler(req: NextApiRequest, res: NextApiResponse) {
const store = storeProxy.get(); const store = storeProxy.get();
// console.log("api::store.null()", store);
if (req.method === "POST") { if (req.method === "POST") {
if (!config.begin) { if (!config.begin) {
res.status(400).json({ res.status(400).json({
@@ -13,7 +14,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
return; return;
} }
const json = req.body; const json = req.body;
console.log("request", json); console.log("api::request: new request", json);
if (json.checked) { if (json.checked) {
let count = 0; let count = 0;
for (const name in store) { for (const name in store) {
@@ -21,13 +22,13 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
count += 1; count += 1;
if (count >= config.limit) { if (count >= config.limit) {
res.status(403).json({ res.status(403).json({
error: `超过选择数量限制: ${config.limit}`, error: `超过选择数量限制,您至多选 ${config.limit} 个班.`,
}); });
return; return;
} }
} }
} }
// check whether it is alreadly occupied // check whether it is already occupied
if (store[json.name] !== undefined) { if (store[json.name] !== undefined) {
res.status(403).json({ res.status(403).json({
error: `当前位置已被他人占用`, error: `当前位置已被他人占用`,
@@ -46,8 +47,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
delete store[json.name]; delete store[json.name];
} }
} }
console.log("query", req.query); const resp: { occupied: string[], myselect: string[] } = { // try to fix
const resp = {
occupied: [], occupied: [],
myselect: [], myselect: [],
}; };

View File

@@ -9,9 +9,9 @@ export default function Home() {
return ( return (
<> <>
<Head> <Head>
<title>Create Next App</title> <title> </title>
<meta name="description" content="Generated by create next app" /> <meta name="description" content="ITSC抢班系统" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> {/* <meta name="viewport" content="width=device-width, initial-scale=1" /> */}
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>
<main> <main>

View File

@@ -30,7 +30,13 @@ class Store {
await this.save(); await this.save();
} }
public async save() { public async save() {
await write(this.filename, JSON.stringify(this.record), "utf8"); // try first, then catch
try {
console.log("store::index: save record", this.record);
await write(this.filename, JSON.stringify(this.record), "utf8");
} catch {
console.error("store::index: save record error, filename:", this.filename);
}
} }
} }
@@ -52,7 +58,12 @@ class HTML {
public async set(html: string) { public async set(html: string) {
this.html = html; this.html = html;
// store into file // store into file
await write(this.filename, html, "utf8"); // try first, then catch
try {
await write(this.filename, html, "utf8");
} catch {
console.error("store::index: save record error, filename:", this.filename);
}
} }
} }