diff --git a/src/pages/index.vue b/src/pages/index.vue index 9f4cb37..e189c42 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1283,7 +1283,7 @@ export default { await Promise.all([this.downloadData(), this.loadConfig()]); }, - async downloadData() { + async downloadData(forceClear = false) { if (this.loading.download) return; try { @@ -1296,8 +1296,8 @@ export default { if (response.error.code === "NOT_FOUND") { this.state.showNoDataMessage = true; 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 = { homework: {}, attendance: { absent: [], late: [], exclude: [] }, @@ -1320,11 +1320,11 @@ export default { this.$message.success("下载成功", "数据已更新"); } } catch (error) { - // 数据加载失败时不覆盖现有数据,只显示错误信息 + // 数据加载失败时的处理 console.error("数据加载失败:", error); 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 = { homework: {}, attendance: { absent: [], late: [], exclude: [] }, @@ -1615,8 +1615,8 @@ export default { }) .catch(() => {}); - // Load both data and subjects in parallel - await Promise.all([this.downloadData(), this.loadSubjects()]); + // Load both data and subjects in parallel, force clear data when switching dates + await Promise.all([this.downloadData(true), this.loadSubjects()]); } } catch (error) { console.error("Date processing error:", error);