1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-12-07 21:13:11 +00:00

feat: 修改下载数据逻辑,支持强制清空数据以避免覆盖现有数据

This commit is contained in:
Sunwuyuan 2025-11-09 16:15:45 +08:00
parent 49ea5f1b2f
commit 0af2c4cc63
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64

View File

@ -1283,7 +1283,7 @@ export default {
await Promise.all([this.downloadData(), this.loadConfig()]); await Promise.all([this.downloadData(), this.loadConfig()]);
}, },
async downloadData() { async downloadData(forceClear = false) {
if (this.loading.download) return; if (this.loading.download) return;
try { try {
@ -1296,8 +1296,8 @@ export default {
if (response.error.code === "NOT_FOUND") { if (response.error.code === "NOT_FOUND") {
this.state.showNoDataMessage = true; this.state.showNoDataMessage = true;
this.state.noDataMessage = response.error.message; this.state.noDataMessage = response.error.message;
// //
if (!this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) { if (forceClear || !this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) {
this.state.boardData = { this.state.boardData = {
homework: {}, homework: {},
attendance: { absent: [], late: [], exclude: [] }, attendance: { absent: [], late: [], exclude: [] },
@ -1320,11 +1320,11 @@ export default {
this.$message.success("下载成功", "数据已更新"); this.$message.success("下载成功", "数据已更新");
} }
} catch (error) { } catch (error) {
// //
console.error("数据加载失败:", error); console.error("数据加载失败:", error);
this.$message.error("下载失败", error.message); this.$message.error("下载失败", error.message);
// //
if (!this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) { if (forceClear || !this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) {
this.state.boardData = { this.state.boardData = {
homework: {}, homework: {},
attendance: { absent: [], late: [], exclude: [] }, attendance: { absent: [], late: [], exclude: [] },
@ -1615,8 +1615,8 @@ export default {
}) })
.catch(() => {}); .catch(() => {});
// Load both data and subjects in parallel // Load both data and subjects in parallel, force clear data when switching dates
await Promise.all([this.downloadData(), this.loadSubjects()]); await Promise.all([this.downloadData(true), this.loadSubjects()]);
} }
} catch (error) { } catch (error) {
console.error("Date processing error:", error); console.error("Date processing error:", error);