From 8c2377c5b5fa817c5eb09cd75f6baf450a555ff5 Mon Sep 17 00:00:00 2001 From: Linkon <116425752+Linkon-lcw@users.noreply.github.com> Date: Sun, 18 Jan 2026 21:38:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(Home):=20=E4=BC=98=E5=8C=96=E7=A7=AF?= =?UTF-8?q?=E5=88=86=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=B7=B3=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将积分变动改为本地状态维护,不再全量刷新数据 移除events类别的数据更新触发,防止页面闪烁 --- src/renderer/src/components/Home.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/components/Home.tsx b/src/renderer/src/components/Home.tsx index f670209..efd1ef6 100644 --- a/src/renderer/src/components/Home.tsx +++ b/src/renderer/src/components/Home.tsx @@ -68,12 +68,9 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { fetchData() const onDataUpdated = (e: any) => { const category = e?.detail?.category - if ( - category === 'students' || - category === 'reasons' || - category === 'all' || - category === 'events' - ) { + // 仅在学生名单、理由列表或全量更新时才重新拉取数据 + // 积分变动(events)现在由本地状态维护,不再触发全量刷新以防止页面跳动 + if (category === 'students' || category === 'reasons' || category === 'all') { fetchData(true) } } @@ -249,7 +246,13 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { if (res.success) { MessagePlugin.success(`已为 ${student.name} ${delta > 0 ? '加' : '扣'}${Math.abs(delta)}分`) setOperationVisible(false) - fetchData(true) + + // 【核心改进】本地增量更新分数,避免全量刷新导致的闪烁和滚动重置 + setStudents((prev) => + prev.map((s) => (s.id === student.id ? { ...s, score: s.score + delta } : s)) + ) + + // 通知其他组件数据已更新(但不在此处重复 fetchData) emitDataUpdated('events') } else { MessagePlugin.error(res.message || '提交失败')