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">
|
<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>
|
||||||
|
@ -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();
|
||||||
if (content) {
|
const originalContent = this.state.boardData.homework[this.currentEditSubject]?.content || '';
|
||||||
// 更新内容
|
|
||||||
this.state.boardData.homework[this.currentEditSubject] = {
|
// 如果内容发生变化(包括清空),就视为修改
|
||||||
name: this.state.availableSubjects.find(
|
if (content !== originalContent.trim()) {
|
||||||
(s) => s.key === this.currentEditSubject
|
if (content) {
|
||||||
)?.name,
|
this.state.boardData.homework[this.currentEditSubject] = {
|
||||||
content,
|
name: this.state.availableSubjects.find(
|
||||||
};
|
(s) => s.key === this.currentEditSubject
|
||||||
|
)?.name,
|
||||||
|
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('日期处理错误', '请重新选择日期');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -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 {
|
try {
|
||||||
console.warn("持久性存储请求被拒绝");
|
if (navigator.storage?.persist) {
|
||||||
|
return await navigator.storage.persist();
|
||||||
}
|
}
|
||||||
} else {
|
return false;
|
||||||
console.warn("浏览器不支持持久性存储");
|
} 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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user