From 28824501dc013a5f61e6e6dfd068154ad6fbafb0 Mon Sep 17 00:00:00 2001 From: lxh2875931338 Date: Mon, 6 Jul 2026 18:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B8=E5=BA=94=E7=9A=84=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/battery_health_page.dart | 47 ++++++++++++++++++++---------- pubspec.yaml | 2 +- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/pages/battery_health_page.dart b/lib/pages/battery_health_page.dart index 405fff4..139eb9d 100644 --- a/lib/pages/battery_health_page.dart +++ b/lib/pages/battery_health_page.dart @@ -352,6 +352,10 @@ class _BatteryHealthPageState extends State _currentCap = recent.first['capacity'].toDouble(); _maxVolt = recent.first['volt_max'] ?? 0; _minVolt = recent.first['volt_min'] ?? 0; + // 🟢 数据库目前不存温度,后续升级可扩展,暂时保留为 0 + _maxTemp = 0; + _minTemp = 0; + _cycleCount = 0; _hasData = true; }); await _updateTrendChart(); @@ -378,20 +382,7 @@ class _BatteryHealthPageState extends State return; } - // 使用 CapacityExtractor 提取容量 - final cap = CapacityExtractor.extractCapacity(lines); - if (cap == null) { - dev.log( - '🔵 未找到容量数据(learned_cap 或 remaining_cap)', - name: 'BatteryHealth', - ); - setState(() => _hasData = false); - _chargeAnimationController.reset(); - _updateChargeState(); - return; - } - - // 提取最后一条有效数据用于显示 + // 🟢 提取所有有效行(包含 tbat=) final validLines = lines.where((line) => line.contains('tbat=')).toList(); if (validLines.isEmpty) { dev.log('🔵 无有效数据行', name: 'BatteryHealth'); @@ -401,6 +392,8 @@ class _BatteryHealthPageState extends State return; } + // 🟢 1.4.7 核心改动:字段提取与容量提取解耦 + // 无论 cap 是否为 null,都提取常规字段 final lastLine = validLines.last; final cycle = _extractCycle(lastLine); final temp = _extractTemp(lastLine); @@ -409,12 +402,34 @@ class _BatteryHealthPageState extends State final (maxVolt, minVolt) = _extractVoltExtremes(validLines); dev.log( - '🔵 解析结果: cap=$cap, cycle=$cycle, temp=$temp, volt=$volt', + '🔵 字段提取: cycle=$cycle, temp=$temp, volt=$volt', name: 'BatteryHealth', ); + // 🟢 容量提取(可能为 null) + final cap = CapacityExtractor.extractCapacity(lines); + int? finalCap; + + if (cap != null) { + // ✅ 今日有充满记录,直接使用 + finalCap = cap; + dev.log('🔵 从日志提取容量: $cap', name: 'BatteryHealth'); + } else { + // ⚠️ 今日无充满记录,尝试从数据库复制前一天容量 + dev.log('🔵 今日无充满记录,尝试复制前一天容量', name: 'BatteryHealth'); + final recent = await _dbService.queryRecentData(1); + if (recent.isNotEmpty) { + finalCap = recent.first['capacity'] as int; + dev.log('🔵 复制前一天容量: $finalCap', name: 'BatteryHealth'); + } else { + finalCap = null; + dev.log('🔵 无历史数据可复制', name: 'BatteryHealth'); + } + } + + // 🟢 一次性 setState 更新所有字段 setState(() { - _currentCap = cap.toDouble(); + _currentCap = (finalCap ?? _currentCap).toDouble(); _cycleCount = cycle; _batteryTemp = temp; _batteryVolt = volt; diff --git a/pubspec.yaml b/pubspec.yaml index 89c1812..b2ecfb1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.4.5 +version: 1.4.7 environment: sdk: ^3.9.2