mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-12-07 13:03:59 +00:00
fix: 优化数据加载逻辑,避免覆盖已有的本地数据
This commit is contained in:
parent
a7ff0e5714
commit
5c3fa9a0e5
@ -1251,10 +1251,13 @@ export default {
|
||||
if (response.error.code === "NOT_FOUND") {
|
||||
this.state.showNoDataMessage = true;
|
||||
this.state.noDataMessage = response.error.message;
|
||||
this.state.boardData = {
|
||||
homework: {},
|
||||
attendance: { absent: [], late: [], exclude: [] },
|
||||
};
|
||||
// 只有当前没有数据时才设置为空,避免覆盖已有的本地数据
|
||||
if (!this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) {
|
||||
this.state.boardData = {
|
||||
homework: {},
|
||||
attendance: { absent: [], late: [], exclude: [] },
|
||||
};
|
||||
}
|
||||
} else {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
@ -1272,11 +1275,16 @@ export default {
|
||||
this.$message.success("下载成功", "数据已更新");
|
||||
}
|
||||
} catch (error) {
|
||||
this.state.boardData = {
|
||||
homework: {},
|
||||
attendance: { absent: [], late: [], exclude: [] },
|
||||
};
|
||||
// 数据加载失败时不覆盖现有数据,只显示错误信息
|
||||
console.error("数据加载失败:", error);
|
||||
this.$message.error("下载失败", error.message);
|
||||
// 如果当前没有任何数据,才初始化为空数据
|
||||
if (!this.state.boardData || (!this.state.boardData.homework && !this.state.boardData.attendance)) {
|
||||
this.state.boardData = {
|
||||
homework: {},
|
||||
attendance: { absent: [], late: [], exclude: [] },
|
||||
};
|
||||
}
|
||||
} finally {
|
||||
this.loading.download = false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user