mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-07-03 01:39:22 +00:00
1
This commit is contained in:
parent
efd622f819
commit
4adc0474e4
@ -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>
|
||||
|
@ -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('日期处理错误', '请重新选择日期');
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user