mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 21:14:21 +08:00
fix(Home): 优化积分更新逻辑避免页面跳动
将积分变动改为本地状态维护,不再全量刷新数据 移除events类别的数据更新触发,防止页面闪烁
This commit is contained in:
@@ -68,12 +68,9 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
fetchData()
|
fetchData()
|
||||||
const onDataUpdated = (e: any) => {
|
const onDataUpdated = (e: any) => {
|
||||||
const category = e?.detail?.category
|
const category = e?.detail?.category
|
||||||
if (
|
// 仅在学生名单、理由列表或全量更新时才重新拉取数据
|
||||||
category === 'students' ||
|
// 积分变动(events)现在由本地状态维护,不再触发全量刷新以防止页面跳动
|
||||||
category === 'reasons' ||
|
if (category === 'students' || category === 'reasons' || category === 'all') {
|
||||||
category === 'all' ||
|
|
||||||
category === 'events'
|
|
||||||
) {
|
|
||||||
fetchData(true)
|
fetchData(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +246,13 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
if (res.success) {
|
if (res.success) {
|
||||||
MessagePlugin.success(`已为 ${student.name} ${delta > 0 ? '加' : '扣'}${Math.abs(delta)}分`)
|
MessagePlugin.success(`已为 ${student.name} ${delta > 0 ? '加' : '扣'}${Math.abs(delta)}分`)
|
||||||
setOperationVisible(false)
|
setOperationVisible(false)
|
||||||
fetchData(true)
|
|
||||||
|
// 【核心改进】本地增量更新分数,避免全量刷新导致的闪烁和滚动重置
|
||||||
|
setStudents((prev) =>
|
||||||
|
prev.map((s) => (s.id === student.id ? { ...s, score: s.score + delta } : s))
|
||||||
|
)
|
||||||
|
|
||||||
|
// 通知其他组件数据已更新(但不在此处重复 fetchData)
|
||||||
emitDataUpdated('events')
|
emitDataUpdated('events')
|
||||||
} else {
|
} else {
|
||||||
MessagePlugin.error(res.message || '提交失败')
|
MessagePlugin.error(res.message || '提交失败')
|
||||||
|
|||||||
Reference in New Issue
Block a user