mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-07-02 09:19:23 +00:00
1
This commit is contained in:
parent
4870eaefc8
commit
882bf08ad9
@ -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>
|
||||
|
@ -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: {
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user