This commit is contained in:
SunWuyuan
2025-03-16 09:41:48 +08:00
parent d52be573ef
commit 69c67a7e52
5 changed files with 92 additions and 57 deletions
+16
View File
@@ -0,0 +1,16 @@
export const defaultConfig = {
studentList: [
"Classworks可以管理学生列表",
'你可以点击设置,在其中找到"学生列表"',
"在添加学生处输入学生姓名,点击添加",
"或者点击高级编辑,从Excel表格中复制数据并粘贴进来",
],
};
export const defaultHomework = {
homework: {},
attendance: {
absent: [],
late: [],
},
};
+3 -8
View File
@@ -1,5 +1,6 @@
import { openDB } from 'idb';
import { formatResponse, formatError } from '../dataProvider';
import { defaultConfig, defaultHomework } from '../defaults/defaultData';
const DB_NAME = "HomeworkDB";
const DB_VERSION = 1;
@@ -32,10 +33,7 @@ export const indexedDBProvider = {
if (!data) {
const today = new Date().toISOString().split("T")[0];
if (date === today) {
return formatResponse({
homework: {},
attendance: { absent: [], late: [] },
});
return formatResponse(defaultHomework);
}
return formatError("数据不存在", "NOT_FOUND");
}
@@ -74,10 +72,7 @@ export const indexedDBProvider = {
const config = await db.get("config", storageKey);
if (!config) {
return formatResponse({
studentList: [],
displayOptions: {},
});
return formatResponse(defaultConfig);
}
return formatResponse(JSON.parse(config));
+6 -4
View File
@@ -61,7 +61,7 @@ window.addEventListener("load", initializeStorage);
*/
// 存储所有设置的localStorage键名
const SETTINGS_STORAGE_KEY = "classworks_settings";
const SETTINGS_STORAGE_KEY = "Classworks_settings";
/**
* 所有配置项的定义
@@ -107,9 +107,11 @@ const settingsDefinitions = {
},
"server.classNumber": {
type: "string",
default: "",
validate: (value) => /^[A-Za-z0-9]*$/.test(value),
description: "班级编号(无论使用哪种存储方式都需要设置)",
default: "高三八班",
//validate: (value) => /^[A-Za-z0-9]*$/.test(value),
validate: (value) => /.*/.test(value),
description: "班级编号",
},
"server.provider": {
type: "string",