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 12:46:29 +08:00
parent 882bf08ad9
commit e46f44bee2
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64

View File

@ -164,7 +164,7 @@
size="large" size="large"
:loading="loading.upload" :loading="loading.upload"
class="ml-2" class="ml-2"
@click="uploadData" @click="manualUpload"
> >
上传 上传
</v-btn> </v-btn>
@ -303,10 +303,10 @@
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn color="grey" variant="text" @click="confirmDialog.show = false"> <v-btn color="grey" variant="text" @click="confirmDialog.reject">
取消 取消
</v-btn> </v-btn>
<v-btn color="primary" @click="confirmSave"> <v-btn color="primary" @click="confirmDialog.resolve">
确认保存 确认保存
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
@ -483,11 +483,16 @@ export default {
return this.state.dateString === today; return this.state.dateString === today;
}, },
canAutoSave() { canAutoSave() {
// //
if (!this.autoSave) return false; return this.autoSave && (!this.blockNonTodayAutoSave || this.isToday);
// },
if (this.blockNonTodayAutoSave && !this.isToday) return false; needConfirmSave() {
return true; //
return !this.isToday && this.confirmNonTodaySave;
},
shouldShowBlockedMessage() {
//
return !this.isToday && this.autoSave && this.blockNonTodayAutoSave;
}, },
refreshBeforeEdit() { refreshBeforeEdit() {
return getSetting("edit.refreshBeforeEdit"); return getSetting("edit.refreshBeforeEdit");
@ -514,7 +519,6 @@ export default {
return !this.isToday && this.confirmNonTodaySave; return !this.isToday && this.confirmNonTodaySave;
}, },
shouldBlockAutoSave() { shouldBlockAutoSave() {
//
return !this.isToday && this.autoSave && this.blockNonTodayAutoSave; return !this.isToday && this.autoSave && this.blockNonTodayAutoSave;
}, },
}, },
@ -534,6 +538,7 @@ export default {
handler() { handler() {
this.throttledReflow(); this.throttledReflow();
}, },
deep: true,
}, },
}, },
@ -630,18 +635,32 @@ export default {
} }
}, },
async handleSave() { async trySave(isAutoSave = false) {
// //
if (this.shouldShowSaveConfirm) { if (isAutoSave && !this.canAutoSave) {
if (this.shouldShowBlockedMessage) {
this.showMessage('需要手动保存', '已禁止自动保存非当天数据', 'warning');
}
return false;
}
//
if (!isAutoSave && this.needConfirmSave) {
try { try {
await this.showConfirmDialog(); await this.showConfirmDialog();
} catch { } catch {
// return false;
return;
} }
} }
await this.uploadData(); //
try {
await this.uploadData();
return true;
} catch (error) {
this.showError('保存失败', error.message || '请重试');
return false;
}
}, },
async handleClose() { async handleClose() {
@ -649,21 +668,16 @@ export default {
const content = this.state.textarea.trim(); const content = this.state.textarea.trim();
if (content) { if (content) {
//
this.state.boardData.homework[this.currentEditSubject] = { this.state.boardData.homework[this.currentEditSubject] = {
name: this.state.availableSubjects.find( name: this.state.availableSubjects.find(s => s.key === this.currentEditSubject)?.name,
(s) => s.key === this.currentEditSubject
)?.name,
content, content,
}; };
this.state.synced = false; this.state.synced = false;
// //
if (this.canAutoSave) { if (this.autoSave) {
// await this.trySave(true);
await this.handleSave();
} else if (this.shouldBlockAutoSave) {
//
this.showMessage('需要手动保存', '已禁止自动保存非当天数据', 'warning');
} }
} else { } else {
delete this.state.boardData.homework[this.currentEditSubject]; delete this.state.boardData.homework[this.currentEditSubject];
@ -690,10 +704,6 @@ export default {
this.state.synced = true; this.state.synced = true;
this.showMessage(response.message || "保存成功"); this.showMessage(response.message || "保存成功");
} catch (error) {
console.error("保存失败:", error);
this.showError("保存失败", error.message || "请重试");
throw error; // 便
} finally { } finally {
this.loading.upload = false; this.loading.upload = false;
} }
@ -736,6 +746,7 @@ export default {
this.showError("刷新数据失败,可能显示的不是最新数据"); this.showError("刷新数据失败,可能显示的不是最新数据");
} }
} }
this.currentEditSubject = subject; this.currentEditSubject = subject;
// //
if (!this.state.boardData.homework[subject]) { if (!this.state.boardData.homework[subject]) {
@ -813,7 +824,6 @@ export default {
this.provider = provider; this.provider = provider;
this.dataKey = provider === "server" ? `${domain}/${classNum}` : classNum; this.dataKey = provider === "server" ? `${domain}/${classNum}` : classNum;
this.state.classNumber = classNum; this.state.classNumber = classNum;
}, },
@ -848,14 +858,12 @@ export default {
// //
if (this.state.dateString !== formattedDate) { if (this.state.dateString !== formattedDate) {
this.state.dateString = formattedDate; this.state.dateString = formattedDate;
// 使 replace push // 使 replace push
this.$router this.$router
.replace({ .replace({
query: { date: formattedDate }, query: { date: formattedDate },
}) })
.catch(() => {}); .catch(() => {});
this.downloadData(); this.downloadData();
} }
} }
@ -1052,8 +1060,14 @@ export default {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.confirmDialog = { this.confirmDialog = {
show: true, show: true,
resolve, resolve: () => {
reject, this.confirmDialog.show = false;
resolve();
},
reject: () => {
this.confirmDialog.show = false;
reject(new Error('用户取消保存'));
}
}; };
}); });
}, },
@ -1071,6 +1085,11 @@ export default {
this.confirmDialog.reject(new Error('用户取消保存')); this.confirmDialog.reject(new Error('用户取消保存'));
} }
}, },
//
async manualUpload() {
return this.trySave(false);
},
}, },
}; };
</script> </script>