From 8f7b3db55204c91338cd23da1af7ad2bf7c6cca4 Mon Sep 17 00:00:00 2001 From: Sunwuyuan Date: Sun, 30 Nov 2025 13:06:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=A4=8D=E5=88=B6=E5=88=B0=E4=BB=8A=E5=A4=A9?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E6=B5=AE?= =?UTF-8?q?=E5=8A=A8=E5=B7=A5=E5=85=B7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FloatingToolbar.vue | 224 ++++++++++++++++++----------- src/pages/index.vue | 64 +++++++++ 2 files changed, 207 insertions(+), 81 deletions(-) diff --git a/src/components/FloatingToolbar.vue b/src/components/FloatingToolbar.vue index 0c5a65f..1431ad1 100644 --- a/src/components/FloatingToolbar.vue +++ b/src/components/FloatingToolbar.vue @@ -1,81 +1,96 @@ diff --git a/src/pages/index.vue b/src/pages/index.vue index 7b4166a..d555d5e 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -207,6 +207,7 @@ @@ -433,6 +435,7 @@ export default { download: false, upload: false, students: false, + copyToToday: false, }, debouncedUpload: null, debouncedAttendanceSave: null, @@ -1914,6 +1917,67 @@ export default { this.handleDateSelect(currentDate); }, + async copyHomeworkToToday() { + if (this.loading.copyToToday) return; + + try { + this.loading.copyToToday = true; + + // 1. 保存当前选中日期的作业数据 + const sourceDate = this.state.dateString; + const sourceHomework = JSON.parse(JSON.stringify(this.state.boardData.homework)); + + // 2. 切换到今天并加载今天的数据(主要是为了获取考勤等其他数据) + const today = this.getToday(); + const todayString = this.formatDate(today); + + // 临时切换到今天以加载数据 + this.state.dateString = todayString; + await this.downloadData(); + + // 3. 直接替换今天的作业数据(删除原有作业,使用源日期的作业) + // 深拷贝源日期的作业数据 + const newHomework = {}; + for (const key in sourceHomework) { + if (sourceHomework[key] && sourceHomework[key].content) { + // 如果是自定义卡片,保留完整结构 + if (sourceHomework[key].type === 'custom') { + newHomework[key] = JSON.parse(JSON.stringify(sourceHomework[key])); + } else { + // 普通作业,只复制内容 + newHomework[key] = { + content: sourceHomework[key].content + }; + } + } + } + + // 直接替换作业数据 + this.state.boardData.homework = newHomework; + this.state.synced = false; + + // 4. 保存到今天 + await this.uploadData(); + + // 5. 更新视图状态为今天 + this.state.selectedDate = todayString; + this.state.selectedDateObj = today; + this.state.isToday = true; + + // 6. 更新URL + const url = new URL(window.location); + url.searchParams.delete('date'); + window.history.pushState({}, '', url); + + this.$message.success("复制成功", `已将 ${sourceDate} 的作业内容复制到今天(已替换原有作业)`); + } catch (error) { + console.error("复制作业失败:", error); + this.$message.error("复制失败", error.message || "请重试"); + } finally { + this.loading.copyToToday = false; + } + }, + // 解析预配数据 parsePreconfigData() { try {