1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-07-02 09:19:23 +00:00
This commit is contained in:
SunWuyuan 2025-03-15 11:21:26 +08:00
parent 4870eaefc8
commit 882bf08ad9
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64
3 changed files with 161 additions and 24 deletions

View File

@ -291,6 +291,27 @@
</v-dialog>
<message-log ref="messageLog" />
<!-- 添加确认对话框 -->
<v-dialog v-model="confirmDialog.show" max-width="400">
<v-card>
<v-card-title class="text-h6">
确认保存
</v-card-title>
<v-card-text>
您正在修改 {{ state.dateString }} 的数据确定要保存吗
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn color="grey" variant="text" @click="confirmDialog.show = false">
取消
</v-btn>
<v-btn color="primary" @click="confirmSave">
确认保存
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
@ -377,6 +398,11 @@ export default {
key: "",
value: [],
},
confirmDialog: {
show: false,
resolve: null,
reject: null,
},
};
},
@ -449,6 +475,20 @@ export default {
autoSave() {
return getSetting("edit.autoSave");
},
blockNonTodayAutoSave() {
return getSetting("edit.blockNonTodayAutoSave");
},
isToday() {
const today = new Date().toISOString().split("T")[0];
return this.state.dateString === today;
},
canAutoSave() {
//
if (!this.autoSave) return false;
//
if (this.blockNonTodayAutoSave && !this.isToday) return false;
return true;
},
refreshBeforeEdit() {
return getSetting("edit.refreshBeforeEdit");
},
@ -467,6 +507,16 @@ export default {
showRandomButton() {
return getSetting("display.showRandomButton");
},
confirmNonTodaySave() {
return getSetting("edit.confirmNonTodaySave");
},
shouldShowSaveConfirm() {
return !this.isToday && this.confirmNonTodaySave;
},
shouldBlockAutoSave() {
//
return !this.isToday && this.autoSave && this.blockNonTodayAutoSave;
},
},
watch: {
@ -580,6 +630,48 @@ export default {
}
},
async handleSave() {
//
if (this.shouldShowSaveConfirm) {
try {
await this.showConfirmDialog();
} catch {
//
return;
}
}
await this.uploadData();
},
async handleClose() {
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,
};
this.state.synced = false;
//
if (this.canAutoSave) {
//
await this.handleSave();
} else if (this.shouldBlockAutoSave) {
//
this.showMessage('需要手动保存', '已禁止自动保存非当天数据', 'warning');
}
} else {
delete this.state.boardData.homework[this.currentEditSubject];
}
this.state.dialogVisible = false;
},
async uploadData() {
if (this.loading.upload) return;
@ -601,6 +693,7 @@ export default {
} catch (error) {
console.error("保存失败:", error);
this.showError("保存失败", error.message || "请重试");
throw error; // 便
} finally {
this.loading.upload = false;
}
@ -624,28 +717,6 @@ export default {
}
},
handleClose() {
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,
};
this.state.synced = false;
if (this.autoSave) {
//
this.uploadData();
}
} else {
delete this.state.boardData.homework[this.currentEditSubject];
}
this.state.dialogVisible = false;
},
showSyncMessage() {
this.state.snackbar = true;
this.state.snackbarText = "数据已完成与服务器同步";
@ -707,7 +778,7 @@ export default {
this.state.boardData.attendance.absent.push(student);
}
this.state.synced = false;
if (this.autoSave) {
if (this.canAutoSave) {
this.uploadData();
}
},
@ -717,7 +788,7 @@ export default {
this.state.boardData.attendance.late = [];
this.state.boardData.attendance.exclude = [];
this.state.synced = false;
if (this.autoSave) {
if (this.canAutoSave) {
this.uploadData();
}
},
@ -976,6 +1047,30 @@ export default {
card.style.setProperty('--y', `${y}%`);
}
},
showConfirmDialog() {
return new Promise((resolve, reject) => {
this.confirmDialog = {
show: true,
resolve,
reject,
};
});
},
confirmSave() {
this.confirmDialog.show = false;
if (this.confirmDialog.resolve) {
this.confirmDialog.resolve(true);
}
},
cancelSave() {
this.confirmDialog.show = false;
if (this.confirmDialog.reject) {
this.confirmDialog.reject(new Error('用户取消保存'));
}
},
},
};
</script>

View File

@ -70,9 +70,39 @@
</template>
</v-list-item>
<v-divider v-if="settings.edit.autoSave" class="my-2" />
<v-list-item v-if="settings.edit.autoSave">
<template #prepend>
<v-icon icon="mdi-calendar-lock" class="mr-3" />
</template>
<v-list-item-title>禁止自动保存非当天数据</v-list-item-title>
<v-list-item-subtitle>仅允许自动保存当天的数据避免误修改历史记录</v-list-item-subtitle>
<template #append>
<v-switch
v-model="settings.edit.blockNonTodayAutoSave"
density="comfortable"
hide-details
/>
</template>
</v-list-item>
<v-divider class="my-2" />
<v-list-item>
<template #prepend>
<v-icon icon="mdi-calendar-alert" class="mr-3" />
</template>
<v-list-item-title>确认保存历史数据</v-list-item-title>
<v-list-item-subtitle>保存非当天数据时显示确认对话框</v-list-item-subtitle>
<template #append>
<v-switch
v-model="settings.edit.confirmNonTodaySave"
density="comfortable"
hide-details
/>
</template>
</v-list-item> <v-divider class="my-2" /><v-list-item>
<template #prepend>
<v-icon icon="mdi-refresh" class="mr-3" />
</template>
@ -342,6 +372,8 @@ export default {
},
edit: {
autoSave: getSetting('edit.autoSave'),
blockNonTodayAutoSave: getSetting('edit.blockNonTodayAutoSave'),
confirmNonTodaySave: getSetting('edit.confirmNonTodaySave'),
refreshBeforeEdit: getSetting('edit.refreshBeforeEdit'),
},
display: {

View File

@ -83,11 +83,21 @@ const settingsDefinitions = {
default: true,
description: "是否启用自动保存",
},
"edit.blockNonTodayAutoSave": { // 添加新选项
type: "boolean",
default: true,
description: "禁止自动保存非当天数据",
},
"edit.refreshBeforeEdit": {
type: "boolean",
default: true,
description: "编辑前是否自动刷新",
},
"edit.confirmNonTodaySave": { // 添加新选项
type: "boolean",
default: true,
description: "保存非当天数据时显示确认对话框,禁用则允许直接保存",
},
// 开发者选项
"developer.enabled": {