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">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HomeWorkPage</title>
<title>Classworks作业板</title>
</head>
<body>
<div id="app"></div>

View File

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

View File

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