feat(stats): #10 第②层 —— 统计页按设备过滤(per-device 本地日曲线)
ci-pangolin / Lint — shellcheck (push) Successful in 8s
ci-pangolin / OpenAPI Sync Check (push) Successful in 19s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Successful in 6s
ci-pangolin / Flutter — analyze + test (push) Failing after 14s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (push) Successful in 6s
ci-pangolin / Codegen Drift — token 生成物未漂移 (push) Successful in 4s
ci-pangolin / Go — build + test (push) Successful in 11s
ci-pangolin / E2E Smoke — L4 进程级端到端 (push) Successful in 14s
ci-pangolin / Go — integration (mysql/redis testcontainers) (push) Failing after 4m8s
ci-pangolin / Golden — 视觉回归 (components + auth) (push) Successful in 15s
ci-pangolin / Lint — shellcheck (push) Successful in 8s
ci-pangolin / OpenAPI Sync Check (push) Successful in 19s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Successful in 6s
ci-pangolin / Flutter — analyze + test (push) Failing after 14s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (push) Successful in 6s
ci-pangolin / Codegen Drift — token 生成物未漂移 (push) Successful in 4s
ci-pangolin / Go — build + test (push) Successful in 11s
ci-pangolin / E2E Smoke — L4 进程级端到端 (push) Successful in 14s
ci-pangolin / Go — integration (mysql/redis testcontainers) (push) Failing after 4m8s
ci-pangolin / Golden — 视觉回归 (components + auth) (push) Successful in 15s
镜像账户级时区曲线到「按设备」: - migration 000018 `usage_device_hourly`(每设备 UTC 小时桶,稀疏)。 - ReportUsage deviceID>0 时加 AccumulateDeviceHourly;NodeStore 接口+impl+mock。 - usage.Store.DeviceHourlyRange(JOIN devices 校验归属+解析 uuid→id);UsageCurve 增 deviceUUID 形参:空=账户级,非空=该设备本地日曲线(分桶逻辑复用)。 - /v1/usage?device=<uuid>;客户端 account_api.usage(device)、usageProvider key 改 记录 (days,device)、stats_page 接 statsDeviceProvider → 选设备即重取该设备曲线。 测试:per-device 曲线隔离+归属校验(A的设备不进B)、UsageCurve(deviceUUID)、 migration v18、客户端 widget(选设备→/v1/usage 带 device=)。全量 go/flutter 绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,10 @@ class StatsPage extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final c = context.pangolin;
|
||||
final t = ref.watch(appTextProvider);
|
||||
final usageAsync = ref.watch(usageProvider(30));
|
||||
// 选中设备(#10②):null=全部=账户级;否则只算该设备的本地日曲线。
|
||||
final selDevice = ref.watch(statsDeviceProvider);
|
||||
final usageKey = (days: 30, device: selDevice);
|
||||
final usageAsync = ref.watch(usageProvider(usageKey));
|
||||
final usage = usageAsync.valueOrNull ?? const <UsagePoint>[];
|
||||
// 先拉数据再渲染(不闪默认 0):auth 还在读 token,或已登录但 usage 还在拉 → 整页转圈。
|
||||
// (auth 加载期 isLoggedIn=false → usage 会同步返回空,故必须并上 auth.isLoading。)
|
||||
@@ -62,7 +65,7 @@ class StatsPage extends ConsumerWidget {
|
||||
color: c.accent,
|
||||
backgroundColor: c.surface,
|
||||
onRefresh: () async {
|
||||
ref.invalidate(usageProvider(30));
|
||||
ref.invalidate(usageProvider(usageKey));
|
||||
ref.invalidate(deviceUsageProvider(30));
|
||||
await ref.read(meProvider.notifier).refresh();
|
||||
},
|
||||
|
||||
@@ -67,9 +67,10 @@ class AccountApi {
|
||||
/// GET /v1/usage?days=N&tz_offset=M — 最近 N 天用量(默认 7,后端范围 [1,90])。
|
||||
/// 带本机时区偏移(分钟,如 UTC+8=480),服务端按「本地日」聚合 → 「今天」与本地日历一致
|
||||
/// (修「29 号却显示 28 号数据」的时区 bug)。
|
||||
Future<List<UsagePoint>> usage({int days = 7}) async {
|
||||
Future<List<UsagePoint>> usage({int days = 7, String? device}) async {
|
||||
final tz = DateTime.now().timeZoneOffset.inMinutes;
|
||||
final body = await _c.getJson('/v1/usage?days=$days&tz_offset=$tz');
|
||||
final dev = (device != null && device.isNotEmpty) ? '&device=$device' : '';
|
||||
final body = await _c.getJson('/v1/usage?days=$days&tz_offset=$tz$dev');
|
||||
final raw = (body['points'] as List<dynamic>?) ?? const [];
|
||||
return raw.map((e) => UsagePoint.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
|
||||
@@ -58,9 +58,12 @@ final plansProvider = FutureProvider<List<Plan>>((ref) async {
|
||||
/// 最近 N 天用量(GET /v1/usage?days=N)。未登录返回空。
|
||||
/// autoDispose:离开统计页即销毁,重进自动重取(配合下拉刷新/连接态变化 invalidate),
|
||||
/// 根治「本月流量取一次就冻住」。后端每 60s 才更新,无需更勤刷新。
|
||||
final usageProvider = FutureProvider.autoDispose.family<List<UsagePoint>, int>((ref, days) async {
|
||||
/// 用量曲线 key:days + 可选设备 uuid(null = 全部/账户级)。
|
||||
typedef UsageKey = ({int days, String? device});
|
||||
|
||||
final usageProvider = FutureProvider.autoDispose.family<List<UsagePoint>, UsageKey>((ref, key) async {
|
||||
if (!ref.watch(authProvider).isLoggedIn) return const [];
|
||||
return ref.read(accountApiProvider).usage(days: days);
|
||||
return ref.read(accountApiProvider).usage(days: key.days, device: key.device);
|
||||
});
|
||||
|
||||
/// 最近 N 天按设备用量(GET /v1/usage/devices?days=N)。统计页设备下拉/明细用。
|
||||
|
||||
Reference in New Issue
Block a user