核对到的积分余额同步刷新主界面积分列,发布0.3.6

后端在"导入账号/手动查询/抢购后核对"时都会写入积分基线,但界面一直没有读它:
积分列的 scoreMap 只由"查询积分"按钮填充,所以自动核对完余额后主界面不动,
用户必须再点一次"查询积分"才看到新余额。

- 新增 GetScoreBaselines 绑定:一次性返回各账号最近一次已记录的积分余额
  (Scheduler.ScoreBaselines → ScoreBaselineStore.Snapshot),界面直接读取,
  不必再为每个账号单独发请求
- 前端 useAccounts 新增 syncScoresFromBackend:把后端基线写入 scoreMap 与
  localStorage(与手动查询同一份状态);导入场景下会短暂轮询等待后端异步查询写完
- 抢购状态回到 idle 时自动同步一次(对应抢购结束后的核对结果)
- 导入账号成功后按导入的账号名同步一次
- 新增断言:核对后 ScoreBaselines 返回最新余额
This commit is contained in:
yml2213
2026-10-03 20:06:03 +08:00
parent 5da35ab65e
commit 75eb0e8ce2
10 changed files with 95 additions and 5 deletions
+14
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"time"
@@ -549,6 +550,19 @@ func (s *Scheduler) ScoreBaseline(accountName string) (int, bool, time.Time) {
return s.scoreBaselines.Get(accountName)
}
// ScoreBaselines 返回各账号最新一次已记录的积分余额(字符串形式,供界面展示)。
func (s *Scheduler) ScoreBaselines() map[string]string {
if s.scoreBaselines == nil {
return map[string]string{}
}
snapshot := s.scoreBaselines.Snapshot()
out := make(map[string]string, len(snapshot))
for name, score := range snapshot {
out[name] = strconv.Itoa(score)
}
return out
}
// RecordScoreBaseline 记录账号的最新积分余额(落盘)。
func (s *Scheduler) RecordScoreBaseline(accountName string, score int) {
if s.scoreBaselines != nil {
+4
View File
@@ -1081,6 +1081,10 @@ func TestVerifyRunResultsConfirmsScoreDeduction(t *testing.T) {
if after, ok, _ := scheduler.ScoreBaseline("a"); !ok || after != 800 {
t.Fatalf("核对后应把 800 存回基线, got %d ok=%v", after, ok)
}
// 界面通过 ScoreBaselines 读取,用于刷新积分列(无需再逐账号请求接口)
if got := scheduler.ScoreBaselines()["a"]; got != "800" {
t.Fatalf("ScoreBaselines[a] = %q, want 800", got)
}
}
// TestVerifyRunResultsWithoutBaseline 没有基线时先记录余额,不误报"未扣分"。
+14
View File
@@ -112,6 +112,20 @@ func (s *ScoreBaselineStore) Forget(accountNames []string) {
s.flush(snapshot)
}
// Snapshot 返回全部账号的最新积分余额副本。
func (s *ScoreBaselineStore) Snapshot() map[string]int {
if s == nil {
return nil
}
s.mu.RLock()
defer s.mu.RUnlock()
out := make(map[string]int, len(s.entries))
for name, entry := range s.entries {
out[name] = entry.Score
}
return out
}
// Names 返回已记录基线的账号名(按字典序),便于测试与排查。
func (s *ScoreBaselineStore) Names() []string {
if s == nil {