1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-07-03 01:39:22 +00:00
This commit is contained in:
SunWuyuan 2025-03-15 21:37:14 +08:00
parent efd622f819
commit 4adc0474e4
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64
3 changed files with 73 additions and 28 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="icon" href="/favicon.ico"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HomeWorkPage</title> <title>Classworks作业板</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -28,7 +28,9 @@
<v-date-picker <v-date-picker
v-model="state.selectedDate" v-model="state.selectedDate"
:model-value="state.selectedDate"
color="primary" color="primary"
width="300"
@update:model-value="handleDateSelect" @update:model-value="handleDateSelect"
/> />
</v-menu> </v-menu>
@ -370,7 +372,7 @@ export default {
snackbarText: "", snackbarText: "",
fontSize: getSetting("font.size"), fontSize: getSetting("font.size"),
datePickerDialog: false, datePickerDialog: false,
selectedDate: null, selectedDate: new Date().toISOString().split("T")[0], //
refreshInterval: null, refreshInterval: null,
subjectOrder: [ subjectOrder: [
"语文", "语文",
@ -606,7 +608,9 @@ export default {
const dateFromUrl = urlParams.get("date"); const dateFromUrl = urlParams.get("date");
const today = new Date().toISOString().split("T")[0]; const today = new Date().toISOString().split("T")[0];
//
this.state.dateString = dateFromUrl || today; this.state.dateString = dateFromUrl || today;
this.state.selectedDate = this.state.dateString; //
this.state.isToday = this.state.dateString === today; this.state.isToday = this.state.dateString === today;
await Promise.all([this.downloadData(), this.loadConfig()]); await Promise.all([this.downloadData(), this.loadConfig()]);
@ -697,22 +701,26 @@ export default {
if (!this.currentEditSubject) return; if (!this.currentEditSubject) return;
const content = this.state.textarea.trim(); const content = this.state.textarea.trim();
const originalContent = this.state.boardData.homework[this.currentEditSubject]?.content || '';
// ()
if (content !== originalContent.trim()) {
if (content) { if (content) {
//
this.state.boardData.homework[this.currentEditSubject] = { this.state.boardData.homework[this.currentEditSubject] = {
name: this.state.availableSubjects.find( name: this.state.availableSubjects.find(
(s) => s.key === this.currentEditSubject (s) => s.key === this.currentEditSubject
)?.name, )?.name,
content, content,
}; };
} else {
delete this.state.boardData.homework[this.currentEditSubject];
}
this.state.synced = false; this.state.synced = false;
// //
if (this.autoSave) { if (this.autoSave) {
await this.trySave(true); await this.trySave(true);
} }
} else {
delete this.state.boardData.homework[this.currentEditSubject];
} }
this.state.dialogVisible = false; this.state.dialogVisible = false;
@ -883,8 +891,16 @@ export default {
}, },
handleDateSelect(newDate) { handleDateSelect(newDate) {
if (newDate) { if (!newDate) return;
const date = new Date(newDate);
try {
//
const date = typeof newDate === 'string' ? new Date(newDate) : newDate;
if (!(date instanceof Date) || isNaN(date.getTime())) {
console.error('Invalid date:', newDate);
return;
}
const year = date.getFullYear(); const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0"); const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0");
@ -893,6 +909,7 @@ export default {
// //
if (this.state.dateString !== formattedDate) { if (this.state.dateString !== formattedDate) {
this.state.dateString = formattedDate; this.state.dateString = formattedDate;
this.state.selectedDate = formattedDate;
// 使 replace push // 使 replace push
this.$router this.$router
.replace({ .replace({
@ -901,6 +918,9 @@ export default {
.catch(() => {}); .catch(() => {});
this.downloadData(); this.downloadData();
} }
} catch (error) {
console.error('Date processing error:', error);
this.$message.error('日期处理错误', '请重新选择日期');
} }
}, },

View File

@ -14,27 +14,40 @@ async function requestNotificationPermission() {
return false; return false;
} }
} }
// 请求持久性存储权限
/**
* 请求持久性存储权限
* @returns {Promise<boolean>} 是否成功启用持久性存储
*/
async function requestPersistentStorage() { async function requestPersistentStorage() {
if (navigator.storage && navigator.storage.persist) { if (!getSetting("storage.persistentStorage")) {
const isPersisted = await navigator.storage.persist(); return false;
if (isPersisted) {
console.log("持久性存储已启用");
} else {
console.warn("持久性存储请求被拒绝");
} }
} else {
console.warn("浏览器不支持持久性存储"); try {
if (navigator.storage?.persist) {
return await navigator.storage.persist();
}
return false;
} catch (error) {
console.warn("请求持久性存储失败:", error);
return false;
} }
} }
// 在页面加载时请求通知权限和持久性存储 /**
window.addEventListener("load", async () => { * 初始化存储权限
*/
async function initializeStorage() {
const notificationGranted = await requestNotificationPermission(); const notificationGranted = await requestNotificationPermission();
if (notificationGranted) { if (notificationGranted && getSetting("storage.persistOnLoad")) {
await requestPersistentStorage(); const persisted = await requestPersistentStorage();
console.log(`持久性存储状态: ${persisted ? "已启用" : "未启用"}`);
} }
}); }
// 在页面加载时初始化
window.addEventListener("load", initializeStorage);
/** /**
* 配置项定义 * 配置项定义
@ -55,6 +68,18 @@ const SETTINGS_STORAGE_KEY = "classworks_settings";
* @type {Object.<string, SettingDefinition>} * @type {Object.<string, SettingDefinition>}
*/ */
const settingsDefinitions = { const settingsDefinitions = {
// 存储设置
"storage.persistentStorage": {
type: "boolean",
default: true,
description: "是否启用持久性存储",
},
"storage.persistOnLoad": {
type: "boolean",
default: true,
description: "是否在页面加载时自动请求持久性存储",
},
// 显示设置 // 显示设置
"display.emptySubjectDisplay": { "display.emptySubjectDisplay": {
type: "string", type: "string",