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