= ({ canEdit }) => {
transform: 'translateY(-50%)',
display: 'flex',
flexDirection: 'column',
- gap: '2px',
backgroundColor: 'var(--ss-card-bg)',
padding: '8px 4px',
borderRadius: '20px',
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
zIndex: 100,
maxHeight: '80vh',
- overflowY: 'auto',
- border: '1px solid var(--ss-border-color)'
+ border: '1px solid var(--ss-border-color)',
+ cursor: 'pointer',
+ userSelect: 'none'
}}
>
{groupedStudents.map((group) => (
scrollToGroup(group.key)}
style={{
width: '24px',
height: '24px',
@@ -435,12 +478,9 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
fontSize: '11px',
fontWeight: 'bold',
color: 'var(--td-brand-color)',
- cursor: 'pointer',
borderRadius: '50%',
- transition: 'background 0.2s'
+ pointerEvents: 'none' // 让事件由父容器统一处理
}}
- onMouseEnter={(e) => (e.currentTarget.style.backgroundColor = 'var(--td-brand-color-1)')}
- onMouseLeave={(e) => (e.currentTarget.style.backgroundColor = 'transparent')}
>
{group.key}
From 30250811970a0f8d717970c2ada52e95556e49d2 Mon Sep 17 00:00:00 2001
From: Linkon <116425752+Linkon-lcw@users.noreply.github.com>
Date: Sun, 18 Jan 2026 21:35:25 +0800
Subject: [PATCH 6/7] =?UTF-8?q?refactor(Home):=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96=E5=92=8C=E6=8F=90=E4=BA=A4?=
=?UTF-8?q?=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 修改 fetchData 支持静默模式避免重复加载
- 提取提交逻辑到 performSubmit 方法复用
- 简化快捷理由选择的处理流程
---
src/renderer/src/components/Home.tsx | 67 ++++++++++++++++------------
1 file changed, 39 insertions(+), 28 deletions(-)
diff --git a/src/renderer/src/components/Home.tsx b/src/renderer/src/components/Home.tsx
index 0724486..f670209 100644
--- a/src/renderer/src/components/Home.tsx
+++ b/src/renderer/src/components/Home.tsx
@@ -51,9 +51,9 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
window.dispatchEvent(new CustomEvent('ss:data-updated', { detail: { category } }))
}
- const fetchData = useCallback(async () => {
+ const fetchData = useCallback(async (silent = false) => {
if (!(window as any).api) return
- setLoading(true)
+ if (!silent) setLoading(true)
const [stuRes, reaRes] = await Promise.all([
(window as any).api.queryStudents({}),
(window as any).api.queryReasons()
@@ -61,15 +61,20 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
if (stuRes.success) setStudents(stuRes.data)
if (reaRes.success) setReasons(reaRes.data)
- setLoading(false)
+ if (!silent) setLoading(false)
}, [])
useEffect(() => {
fetchData()
const onDataUpdated = (e: any) => {
const category = e?.detail?.category
- if (category === 'students' || category === 'reasons' || category === 'all') {
- fetchData()
+ if (
+ category === 'students' ||
+ category === 'reasons' ||
+ category === 'all' ||
+ category === 'events'
+ ) {
+ fetchData(true)
}
}
window.addEventListener('ss:data-updated', onDataUpdated as any)
@@ -226,14 +231,36 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
setOperationVisible(true)
}
- // 提交积分
- const handleSubmit = async () => {
- if (!(window as any).api || !selectedStudent) return
+ // 核心提交逻辑
+ const performSubmit = async (student: student, delta: number, content: string) => {
+ if (!(window as any).api) return
if (!canEdit) {
MessagePlugin.error('当前为只读权限')
return
}
+ setSubmitLoading(true)
+ const res = await (window as any).api.createEvent({
+ student_name: student.name,
+ reason_content: content,
+ delta: delta
+ })
+
+ if (res.success) {
+ MessagePlugin.success(`已为 ${student.name} ${delta > 0 ? '加' : '扣'}${Math.abs(delta)}分`)
+ setOperationVisible(false)
+ fetchData(true)
+ emitDataUpdated('events')
+ } else {
+ MessagePlugin.error(res.message || '提交失败')
+ }
+ setSubmitLoading(false)
+ }
+
+ // 手动点击确定按钮提交(用于自定义分值)
+ const handleSubmit = async () => {
+ if (!selectedStudent) return
+
const delta = customScore
if (delta === undefined || !Number.isFinite(delta)) {
MessagePlugin.warning('请选择或输入分值')
@@ -241,29 +268,13 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
}
const content = reasonContent || (delta > 0 ? '加分' : delta < 0 ? '扣分' : '积分变更')
-
- setSubmitLoading(true)
- const res = await (window as any).api.createEvent({
- student_name: selectedStudent.name,
- reason_content: content,
- delta: delta
- })
-
- if (res.success) {
- MessagePlugin.success('积分提交成功')
- setOperationVisible(false)
- fetchData()
- emitDataUpdated('events')
- } else {
- MessagePlugin.error(res.message || '提交失败')
- }
- setSubmitLoading(false)
+ await performSubmit(selectedStudent, delta, content)
}
- // 快捷理由选择
+ // 快捷理由选择:点击即提交
const handleReasonSelect = (reason: reason) => {
- setCustomScore(reason.delta)
- setReasonContent(reason.content)
+ if (!selectedStudent) return
+ performSubmit(selectedStudent, reason.delta, reason.content)
}
// 渲染学生卡片
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 7/7] =?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 || '提交失败')