From 8aaf537f84c861ed918822e1b1e2394980d9248e Mon Sep 17 00:00:00 2001 From: SunWuyuan Date: Sun, 9 Mar 2025 15:36:01 +0800 Subject: [PATCH] 1 --- src/components/settings/StudentListCard.vue | 62 +++++-- src/pages/index.vue | 192 +++++++------------- 2 files changed, 108 insertions(+), 146 deletions(-) diff --git a/src/components/settings/StudentListCard.vue b/src/components/settings/StudentListCard.vue index 53ffe03..54e2fe7 100644 --- a/src/components/settings/StudentListCard.vue +++ b/src/components/settings/StudentListCard.vue @@ -246,27 +246,42 @@ export default { index: -1, name: '' }, - savedState: null // 初始为 null,用于判断是否已初始化 + savedState: { // 初始化为当前值而不是 null + list: [], + text: '' + } } }, created() { - // 使用 modelValue 初始化保存状态 - this.savedState = { - list: [...this.modelValue.list], - text: this.modelValue.text - } + // 移除这里的初始化,改为在 mounted 中处理 + }, + + mounted() { + // 使用 nextTick 确保在 DOM 更新后初始化 + this.$nextTick(() => { + this.savedState = { + list: [...this.modelValue.list], + text: this.modelValue.text + } + }) }, watch: { originalList: { handler(newList) { - // 仅在首次加载时更新保存状态 - if (!this.savedState || this.savedState.list.length === 0) { - this.savedState = { + // 只在初始加载和空列表时更新 + if (this.modelValue.list.length === 0) { + const newState = { list: [...newList], text: newList.join('\n') - } + }; + // 同步更新两个状态 + this.savedState = { ...newState }; + this.updateModelValue({ + ...this.modelValue, + ...newState + }); } }, immediate: true @@ -285,14 +300,13 @@ export default { } }, hasChanges() { - if (!this.savedState) return false; - const currentState = JSON.stringify({ list: this.modelValue.list, text: this.modelValue.text }); const savedState = JSON.stringify(this.savedState); - return currentState !== savedState; + // 检查 savedState 是否为初始状态 + return this.savedState.list.length > 0 && currentState !== savedState; } }, @@ -329,6 +343,14 @@ export default { }); }, + // 更新保存状态 + updateSavedState() { + this.savedState = { + list: [...this.modelValue.list], + text: this.modelValue.text + }; + }, + // 学生管理方法 addStudent() { const name = this.newStudentName.trim(); @@ -401,12 +423,12 @@ export default { // 保存和加载处理 async handleSave() { - await this.$emit('save'); - // 保存时更新状态 - this.savedState = { - list: [...this.modelValue.list], - text: this.modelValue.text - }; + try { + await this.$emit('save'); + this.updateSavedState(); + } catch (error) { + console.error('保存失败:', error); + } }, handleTextInput(value) { @@ -417,7 +439,7 @@ export default { this.updateModelValue({ text: value, - list: list + list }); } } diff --git a/src/pages/index.vue b/src/pages/index.vue index 069330f..e9c50bd 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -21,16 +21,9 @@ variant="text" @click="zoom('up')" /> - + - +
- + -
+
- + {{ item.name }} @@ -102,26 +82,19 @@
-
+
- - mdi-plus - -
- 点击添加作业 -
+ mdi-plus +
点击添加作业
@@ -157,20 +123,26 @@ @click="setAttendanceArea()" >

出勤

-

应到: {{ state.studentList.length }}人

-

实到: {{ state.studentList.length - state.selectedSet.size }}人

+

应到: {{ state.studentList.length - state.excludeSet.size }}人

+

+ 实到: + {{ + state.studentList.length - + state.selectedSet.size - + state.lateSet.size - + state.excludeSet.size + }}人 +

请假: {{ state.selectedSet.size }}人

-

+

{{ `${index + 1}. ${state.studentList[i]}` }}

迟到: {{ state.lateSet.size }}人

-

+

+ {{ `${index + 1}. ${state.studentList[i]}` }} +

+

不参与: {{ state.excludeSet.size }}人

+

{{ `${index + 1}. ${state.studentList[i]}` }}

@@ -186,14 +158,9 @@ > 上传 - - 同步完成 - + 同步完成 - - - 设置学生出勤状态 - - - 全勤 - - - - - - - {{ `${i + 1}. ${name}` }} - - - - - - - - - - + {{ state.snackbarText }} - + - - 编辑出勤状态 - + 编辑出勤状态 @@ -346,6 +261,12 @@ size="small" @click="setLate(index)" /> + @@ -354,12 +275,7 @@ - - 保存 - + 保存 @@ -389,6 +305,7 @@ export default { studentList: [], selectedSet: new Set(), lateSet: new Set(), + excludeSet: new Set(), // 新增不参与集合 dialogVisible: false, dialogTitle: "", textarea: "", @@ -630,6 +547,7 @@ export default { this.state.homeworkData = {}; this.state.selectedSet = new Set(); this.state.lateSet = new Set(); + this.state.excludeSet = new Set(); // 添加不参与状态 } else { throw new Error(response.error.message); } @@ -639,6 +557,7 @@ export default { this.state.homeworkData = homework; this.state.selectedSet = new Set(attendance.absent || []); this.state.lateSet = new Set(attendance.late || []); + this.state.excludeSet = new Set(attendance.exclude || []); // 添加不参与状态 this.state.synced = true; this.state.showNoDataMessage = false; this.showMessage("下载成功", "数据已更新"); @@ -663,6 +582,7 @@ export default { attendance: { absent: Array.from(this.state.selectedSet), late: Array.from(this.state.lateSet), + exclude: Array.from(this.state.excludeSet), // 添加不参与状态 }, }, this.state.dateString @@ -766,7 +686,7 @@ export default { }, setAttendanceArea() { - this.state.attendDialogVisible = true; + this.state.attendanceDialog = true; }, toggleStudentStatus(index) { @@ -775,6 +695,9 @@ export default { this.state.lateSet.add(index); } else if (this.state.lateSet.has(index)) { this.state.lateSet.delete(index); + this.state.excludeSet.add(index); + } else if (this.state.excludeSet.has(index)) { + this.state.excludeSet.delete(index); } else { this.state.selectedSet.add(index); } @@ -787,6 +710,7 @@ export default { cleanstudentslist() { this.state.selectedSet.clear(); this.state.lateSet.clear(); + this.state.excludeSet.clear(); this.state.synced = false; if (this.autoSave) { this.uploadData(); @@ -932,6 +856,7 @@ export default { setAllPresent() { this.state.selectedSet.clear(); this.state.lateSet.clear(); + this.state.excludeSet.clear(); }, setAllAbsent() { @@ -948,7 +873,9 @@ export default { isPresent(index) { return ( - !this.state.selectedSet.has(index) && !this.state.lateSet.has(index) + !this.state.selectedSet.has(index) && + !this.state.lateSet.has(index) && + !this.state.excludeSet.has(index) ); }, @@ -960,19 +887,32 @@ export default { return this.state.lateSet.has(index); }, + isExclude(index) { + return this.state.excludeSet.has(index); + }, + setPresent(index) { this.state.selectedSet.delete(index); this.state.lateSet.delete(index); + this.state.excludeSet.delete(index); }, setAbsent(index) { this.state.selectedSet.add(index); this.state.lateSet.delete(index); + this.state.excludeSet.delete(index); }, setLate(index) { this.state.lateSet.add(index); this.state.selectedSet.delete(index); + this.state.excludeSet.delete(index); + }, + + setExclude(index) { + this.state.excludeSet.add(index); + this.state.selectedSet.delete(index); + this.state.lateSet.delete(index); }, async saveAttendance() {