seperate regular
This commit is contained in:
16
pages/api/html-regular.ts
Normal file
16
pages/api/html-regular.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { htmlRegular } from "@/store";
|
||||
import config from "@/config";
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") {
|
||||
if (req.headers.token !== config.token) {
|
||||
res.status(403).json({ error: "wrong token" });
|
||||
return;
|
||||
}
|
||||
htmlRegular.set(req.body.html);
|
||||
}
|
||||
res.status(200).json({
|
||||
html: htmlRegular.get(),
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,7 @@ const read = promisify(fs.readFile);
|
||||
|
||||
// 索引与工时
|
||||
const indexToHour: Record<string, number> = JSON.parse(
|
||||
fs.readFileSync("./hours.json", "utf8")
|
||||
fs.readFileSync("./data/hours.json", "utf8")
|
||||
).selections;
|
||||
|
||||
export default async function handler(
|
||||
@@ -18,7 +18,7 @@ export default async function handler(
|
||||
// 读入全部json文件
|
||||
// users: {姓名: {坐标: 权重}}
|
||||
const users: Record<string, Record<string, number>> = {};
|
||||
const files = await g("./json/*.json");
|
||||
const files = await g("./data/json/*.json");
|
||||
for (const file of files) {
|
||||
const jsonStr = await read(file, "utf8");
|
||||
const json: {
|
||||
|
||||
39
pages/edit-regular.tsx
Normal file
39
pages/edit-regular.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import React from "react";
|
||||
import { get, post } from "@/common";
|
||||
|
||||
const EditPage = () => {
|
||||
const [token, setToken] = React.useState("");
|
||||
const ref = React.useRef();
|
||||
const upload = async () => {
|
||||
const html = ref.current.innerHTML;
|
||||
await post("/api/html-regular", { html }, { token });
|
||||
alert("Upload success");
|
||||
refresh();
|
||||
};
|
||||
const refresh = async () => {
|
||||
const html = await get("/api/html-regular");
|
||||
ref.current.innerHTML = html.html;
|
||||
};
|
||||
React.useEffect(() => {
|
||||
refresh();
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<input
|
||||
value={token}
|
||||
placeholder={"token"}
|
||||
onChange={(event) => setToken(event.target.value)}
|
||||
/>
|
||||
<button onClick={() => upload()}>Upload</button>
|
||||
<div
|
||||
ref={ref}
|
||||
onInput={(event) => {
|
||||
console.log(event.currentTarget.innerHTML);
|
||||
}}
|
||||
contentEditable="true"
|
||||
></div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default EditPage;
|
||||
@@ -22,6 +22,7 @@ const ReportPage = () => {
|
||||
disableNetwork={true}
|
||||
apiRecordEndPoint="/api/regular"
|
||||
openRecordMode={true}
|
||||
isRegular={true}
|
||||
/>
|
||||
</UserInputWrap>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user