From 9333cd81c3611a899ff4bafc7017aeff256b9d6f Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 19 Jan 2026 22:53:48 -0800 Subject: [PATCH] fix(kline): auto-load more history when data doesn't fill screen - Always assume hasMoreHistory=true on initial load - Auto-trigger loadMoreHistory when klines don't fill drawable area - This ensures sparse data periods load all available history Co-Authored-By: Claude Opus 4.5 --- .claude/settings.local.json | 3 ++- .../providers/trading_providers.dart | 2 +- .../kline_chart/kline_chart_widget.dart | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index f9cf524f..8757e7bf 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -790,7 +790,8 @@ "Bash(ssh -o ProxyJump=ceshi@103.39.231.231 ceshi@192.168.1.111 \"ls -la /home/ceshi/rwadurian/backend/\")", "Bash(ssh -o ProxyJump=ceshi@103.39.231.231 ceshi@192.168.1.111 \"ls -la /home/ceshi/rwadurian/backend/services/\")", "Bash(where:*)", - "Bash(npx md-to-pdf:*)" + "Bash(npx md-to-pdf:*)", + "Bash(ssh -J ceshi@103.39.231.231 ceshi@192.168.1.111 \"curl -s ''http://localhost:3000/api/price/klines?period=1h&limit=5'' | head -500\")" ], "deny": [], "ask": [] diff --git a/frontend/mining-app/lib/presentation/providers/trading_providers.dart b/frontend/mining-app/lib/presentation/providers/trading_providers.dart index 969e7002..95ec782b 100644 --- a/frontend/mining-app/lib/presentation/providers/trading_providers.dart +++ b/frontend/mining-app/lib/presentation/providers/trading_providers.dart @@ -113,7 +113,7 @@ class KlinesNotifier extends StateNotifier { state = state.copyWith( klines: klines, isLoading: false, - hasMoreHistory: klines.length >= 100, // 如果返回100条,可能还有更多 + hasMoreHistory: true, // 默认还有更多历史,直到加载返回空数据 ); _startAutoRefresh(apiPeriod); }, diff --git a/frontend/mining-app/lib/presentation/widgets/kline_chart/kline_chart_widget.dart b/frontend/mining-app/lib/presentation/widgets/kline_chart/kline_chart_widget.dart index 48d4b92f..2272b914 100644 --- a/frontend/mining-app/lib/presentation/widgets/kline_chart/kline_chart_widget.dart +++ b/frontend/mining-app/lib/presentation/widgets/kline_chart/kline_chart_widget.dart @@ -97,6 +97,24 @@ class _KlineChartWidgetState extends State { // 计算滚动位置,让最新K线在屏幕中心 _scrollToCenter(); + + // 如果数据不足以填满屏幕且还有更多历史数据,自动加载更多 + _checkAndLoadMoreIfNeeded(); + } + + /// 检查是否需要自动加载更多历史数据 + void _checkAndLoadMoreIfNeeded() { + if (!widget.hasMoreHistory || widget.isLoadingMore) return; + + const leftPadding = 8.0; + const rightPadding = 50.0; + final drawableWidth = _chartWidth - leftPadding - rightPadding; + final totalKlineWidth = widget.klines.length * _candleWidth; + + // 如果K线总宽度不足以填满可绘制区域,自动加载更多历史 + if (totalKlineWidth < drawableWidth) { + widget.onLoadMoreHistory?.call(); + } } /// 滚动使最新 K 线在屏幕中心显示