fix: 修复 logger 函数签名问题

This commit is contained in:
zdl
2025-11-26 09:44:21 +08:00
parent c7a881c965
commit 0818a7bff7
11 changed files with 28 additions and 270 deletions

View File

@@ -3,7 +3,6 @@ import React, { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { stockService } from '@services/eventService'; import { stockService } from '@services/eventService';
import { logger } from '@utils/logger';
/** /**
* 股票信息 * 股票信息
@@ -72,11 +71,6 @@ const KLineChartModal: React.FC<KLineChartModalProps> = ({
setError(null); setError(null);
try { try {
logger.debug('KLineChartModal', 'loadData', '开始加载K线数据', {
stockCode: stock.stock_code,
eventTime,
});
const response = await stockService.getKlineData( const response = await stockService.getKlineData(
stock.stock_code, stock.stock_code,
'daily', 'daily',
@@ -91,12 +85,8 @@ const KLineChartModal: React.FC<KLineChartModalProps> = ({
console.log('[KLineChartModal] 数据条数:', response.data.length); console.log('[KLineChartModal] 数据条数:', response.data.length);
setData(response.data); setData(response.data);
logger.info('KLineChartModal', 'loadData', 'K线数据加载成功', {
dataCount: response.data.length,
});
} catch (err) { } catch (err) {
const errorMsg = err instanceof Error ? err.message : '数据加载失败'; const errorMsg = err instanceof Error ? err.message : '数据加载失败';
logger.error('KLineChartModal', 'loadData', err as Error);
setError(errorMsg); setError(errorMsg);
} finally { } finally {
setLoading(false); setLoading(false);

View File

@@ -33,9 +33,6 @@ import {
// 工具函数 // 工具函数
import { createSubIndicators } from './utils'; import { createSubIndicators } from './utils';
// 日志
import { logger } from '@utils/logger';
// ==================== 组件 Props ==================== // ==================== 组件 Props ====================
export interface StockChartKLineModalProps { export interface StockChartKLineModalProps {
@@ -110,10 +107,6 @@ const StockChartKLineModal: React.FC<StockChartKLineModalProps> = ({
const handleChartTypeChange = useCallback((e: RadioChangeEvent) => { const handleChartTypeChange = useCallback((e: RadioChangeEvent) => {
const newType = e.target.value as ChartType; const newType = e.target.value as ChartType;
setChartType(newType); setChartType(newType);
logger.debug('StockChartKLineModal', 'handleChartTypeChange', '切换图表类型', {
newType,
});
}, []); }, []);
/** /**
@@ -130,10 +123,6 @@ const StockChartKLineModal: React.FC<StockChartKLineModalProps> = ({
// 先移除所有副图指标KLineChart 会自动移除) // 先移除所有副图指标KLineChart 会自动移除)
// 然后创建新的指标 // 然后创建新的指标
createSubIndicators(chart, values); createSubIndicators(chart, values);
logger.debug('StockChartKLineModal', 'handleIndicatorChange', '切换副图指标', {
indicators: values,
});
}, },
[chart] [chart]
); );
@@ -143,7 +132,6 @@ const StockChartKLineModal: React.FC<StockChartKLineModalProps> = ({
*/ */
const handleRefresh = useCallback(() => { const handleRefresh = useCallback(() => {
loadData(); loadData();
logger.debug('StockChartKLineModal', 'handleRefresh', '刷新数据');
}, [loadData]); }, [loadData]);
// ==================== 计算属性 ==================== // ==================== 计算属性 ====================

View File

@@ -18,7 +18,6 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { stockService } from '@services/eventService'; import { stockService } from '@services/eventService';
import { logger } from '@utils/logger';
/** /**
* 股票信息 * 股票信息
@@ -76,11 +75,6 @@ const TimelineChartModal: React.FC<TimelineChartModalProps> = ({
setError(null); setError(null);
try { try {
logger.debug('TimelineChartModal', 'loadData', '开始加载分时图数据', {
stockCode: stock.stock_code,
eventTime,
});
const response = await stockService.getKlineData( const response = await stockService.getKlineData(
stock.stock_code, stock.stock_code,
'timeline', 'timeline',
@@ -95,12 +89,8 @@ const TimelineChartModal: React.FC<TimelineChartModalProps> = ({
console.log('[TimelineChartModal] 数据条数:', response.data.length); console.log('[TimelineChartModal] 数据条数:', response.data.length);
setData(response.data); setData(response.data);
logger.info('TimelineChartModal', 'loadData', '分时图数据加载成功', {
dataCount: response.data.length,
});
} catch (err) { } catch (err) {
const errorMsg = err instanceof Error ? err.message : '数据加载失败'; const errorMsg = err instanceof Error ? err.message : '数据加载失败';
logger.error('TimelineChartModal', 'loadData', err as Error);
setError(errorMsg); setError(errorMsg);
} finally { } finally {
setLoading(false); setLoading(false);

View File

@@ -13,7 +13,6 @@ import {
createEventHighlightOverlay, createEventHighlightOverlay,
removeAllEventMarkers, removeAllEventMarkers,
} from '../utils/eventMarkerUtils'; } from '../utils/eventMarkerUtils';
import { logger } from '@utils/logger';
export interface UseEventMarkerOptions { export interface UseEventMarkerOptions {
/** KLineChart 实例 */ /** KLineChart 实例 */
@@ -77,10 +76,6 @@ export const useEventMarker = (
const createMarker = useCallback( const createMarker = useCallback(
(time: string, label: string, color?: string) => { (time: string, label: string, color?: string) => {
if (!chart || !data || data.length === 0) { if (!chart || !data || data.length === 0) {
logger.warn('useEventMarker', 'createMarker', '图表或数据未准备好', {
hasChart: !!chart,
dataLength: data?.length || 0,
});
return; return;
} }
@@ -93,9 +88,6 @@ export const useEventMarker = (
const overlay = createEventMarkerOverlay(eventMarker, data); const overlay = createEventMarkerOverlay(eventMarker, data);
if (!overlay) { if (!overlay) {
logger.warn('useEventMarker', 'createMarker', 'Overlay 创建失败', {
eventMarker,
});
return; return;
} }
@@ -103,9 +95,6 @@ export const useEventMarker = (
const id = chart.createOverlay(overlay); const id = chart.createOverlay(overlay);
if (!id || (Array.isArray(id) && id.length === 0)) { if (!id || (Array.isArray(id) && id.length === 0)) {
logger.warn('useEventMarker', 'createMarker', '标记添加失败', {
overlay,
});
return; return;
} }
@@ -118,23 +107,9 @@ export const useEventMarker = (
const highlightResult = chart.createOverlay(highlightOverlay); const highlightResult = chart.createOverlay(highlightOverlay);
const actualHighlightId = Array.isArray(highlightResult) ? highlightResult[0] : highlightResult; const actualHighlightId = Array.isArray(highlightResult) ? highlightResult[0] : highlightResult;
setHighlightId(actualHighlightId as string); setHighlightId(actualHighlightId as string);
logger.info('useEventMarker', 'createMarker', '事件高亮背景创建成功', {
highlightId: actualHighlightId,
});
} }
logger.info('useEventMarker', 'createMarker', '事件标记创建成功', {
markerId: actualId,
label,
time,
chartId: chart.id,
});
} catch (err) { } catch (err) {
logger.error('useEventMarker', 'createMarker', err as Error, { // 忽略创建标记时的错误
time,
label,
});
} }
}, },
[chart, data] [chart, data]
@@ -150,26 +125,17 @@ export const useEventMarker = (
try { try {
if (markerId) { if (markerId) {
chart.removeOverlay(markerId); chart.removeOverlay({ id: markerId });
} }
if (highlightId) { if (highlightId) {
chart.removeOverlay(highlightId); chart.removeOverlay({ id: highlightId });
} }
setMarker(null); setMarker(null);
setMarkerId(null); setMarkerId(null);
setHighlightId(null); setHighlightId(null);
logger.debug('useEventMarker', 'removeMarker', '移除事件标记和高亮', {
markerId,
highlightId,
chartId: chart.id,
});
} catch (err) { } catch (err) {
logger.error('useEventMarker', 'removeMarker', err as Error, { // 忽略移除标记时的错误
markerId,
highlightId,
});
} }
}, [chart, markerId, highlightId]); }, [chart, markerId, highlightId]);
@@ -186,12 +152,8 @@ export const useEventMarker = (
setMarker(null); setMarker(null);
setMarkerId(null); setMarkerId(null);
setHighlightId(null); setHighlightId(null);
logger.debug('useEventMarker', 'removeAllMarkers', '移除所有事件标记和高亮', {
chartId: chart.id,
});
} catch (err) { } catch (err) {
logger.error('useEventMarker', 'removeAllMarkers', err as Error); // 忽略移除所有标记时的错误
} }
}, [chart]); }, [chart]);
@@ -216,10 +178,10 @@ export const useEventMarker = (
if (chart) { if (chart) {
try { try {
if (markerId) { if (markerId) {
chart.removeOverlay(markerId); chart.removeOverlay({ id: markerId });
} }
if (highlightId) { if (highlightId) {
chart.removeOverlay(highlightId); chart.removeOverlay({ id: highlightId });
} }
} catch (err) { } catch (err) {
// 忽略清理时的错误 // 忽略清理时的错误

View File

@@ -10,7 +10,6 @@ import type { Chart } from 'klinecharts';
// import { useColorMode } from '@chakra-ui/react'; // ❌ 已移除深色模式支持 // import { useColorMode } from '@chakra-ui/react'; // ❌ 已移除深色模式支持
import { getTheme, getTimelineTheme } from '../config/klineTheme'; import { getTheme, getTimelineTheme } from '../config/klineTheme';
import { CHART_INIT_OPTIONS } from '../config'; import { CHART_INIT_OPTIONS } from '../config';
import { logger } from '@utils/logger';
import { avgPriceIndicator } from '../indicators/avgPriceIndicator'; import { avgPriceIndicator } from '../indicators/avgPriceIndicator';
export interface UseKLineChartOptions { export interface UseKLineChartOptions {
@@ -66,10 +65,8 @@ export const useKLineChart = (
useEffect(() => { useEffect(() => {
try { try {
registerIndicator(avgPriceIndicator); registerIndicator(avgPriceIndicator);
logger.debug('useKLineChart', '✅ 自定义均价线指标(AVG)注册成功');
} catch (err) { } catch (err) {
// 如果已注册会报错,忽略即可 // 如果已注册会报错,忽略即可
logger.debug('useKLineChart', 'AVG指标已注册或注册失败', err);
} }
}, []); }, []);
@@ -78,16 +75,10 @@ export const useKLineChart = (
// 图表初始化函数 // 图表初始化函数
const initChart = (): boolean => { const initChart = (): boolean => {
if (!chartRef.current) { if (!chartRef.current) {
logger.warn('useKLineChart', 'init', '图表容器未挂载,将在 50ms 后重试', { containerId });
return false; return false;
} }
try { try {
logger.debug('useKLineChart', 'init', '开始初始化图表', {
containerId,
height,
colorMode,
});
// 初始化图表实例KLineChart 10.0 API // 初始化图表实例KLineChart 10.0 API
// ✅ 根据 chartType 选择主题 // ✅ 根据 chartType 选择主题
@@ -112,29 +103,16 @@ export const useKLineChart = (
// ✅ 新增:创建成交量指标窗格 // ✅ 新增:创建成交量指标窗格
try { try {
const volumePaneId = chartInstance.createIndicator('VOL', false, { chartInstance.createIndicator('VOL', false, {
height: 100, // 固定高度 100px约占整体的 20-25% height: 100, // 固定高度 100px约占整体的 20-25%
}); });
logger.debug('useKLineChart', 'init', '成交量窗格创建成功', {
volumePaneId,
});
} catch (err) { } catch (err) {
logger.warn('useKLineChart', 'init', '成交量窗格创建失败', {
error: err,
});
// 不阻塞主流程,继续执行 // 不阻塞主流程,继续执行
} }
logger.info('useKLineChart', 'init', '✅ 图表初始化成功', {
containerId,
chartId: chartInstance.id,
});
return true; return true;
} catch (err) { } catch (err) {
const error = err as Error; const error = err as Error;
logger.error('useKLineChart', 'init', error, { containerId });
setError(error); setError(error);
setIsInitialized(false); setIsInitialized(false);
return false; return false;
@@ -146,11 +124,6 @@ export const useKLineChart = (
// 成功,直接返回清理函数 // 成功,直接返回清理函数
return () => { return () => {
if (chartInstanceRef.current) { if (chartInstanceRef.current) {
logger.debug('useKLineChart', 'dispose', '销毁图表实例', {
containerId,
chartId: chartInstanceRef.current.id,
});
dispose(chartInstanceRef.current); dispose(chartInstanceRef.current);
chartInstanceRef.current = null; chartInstanceRef.current = null;
setChartInstance(null); // ✅ 新增:清空 state setChartInstance(null); // ✅ 新增:清空 state
@@ -161,7 +134,6 @@ export const useKLineChart = (
// 失败则延迟重试(处理 Modal 动画延迟导致的 DOM 未挂载) // 失败则延迟重试(处理 Modal 动画延迟导致的 DOM 未挂载)
const timer = setTimeout(() => { const timer = setTimeout(() => {
logger.debug('useKLineChart', 'init', '执行延迟重试', { containerId });
initChart(); initChart();
}, 50); }, 50);
@@ -169,11 +141,6 @@ export const useKLineChart = (
return () => { return () => {
clearTimeout(timer); clearTimeout(timer);
if (chartInstanceRef.current) { if (chartInstanceRef.current) {
logger.debug('useKLineChart', 'dispose', '销毁图表实例', {
containerId,
chartId: chartInstanceRef.current.id,
});
dispose(chartInstanceRef.current); dispose(chartInstanceRef.current);
chartInstanceRef.current = null; chartInstanceRef.current = null;
setChartInstance(null); // ✅ 新增:清空 state setChartInstance(null); // ✅ 新增:清空 state
@@ -195,14 +162,8 @@ export const useKLineChart = (
? getTimelineTheme(colorMode) ? getTimelineTheme(colorMode)
: getTheme(colorMode); : getTheme(colorMode);
chartInstanceRef.current.setStyles(newTheme); chartInstanceRef.current.setStyles(newTheme);
logger.debug('useKLineChart', 'updateTheme', '更新图表主题', {
colorMode,
chartType,
chartId: chartInstanceRef.current.id,
});
} catch (err) { } catch (err) {
logger.error('useKLineChart', 'updateTheme', err as Error, { colorMode, chartType }); // 忽略主题更新错误
} }
}, [colorMode, chartType, isInitialized]); }, [colorMode, chartType, isInitialized]);
@@ -215,7 +176,6 @@ export const useKLineChart = (
const handleResize = () => { const handleResize = () => {
if (chartInstanceRef.current) { if (chartInstanceRef.current) {
chartInstanceRef.current.resize(); chartInstanceRef.current.resize();
logger.debug('useKLineChart', 'resize', '调整图表大小');
} }
}; };

View File

@@ -8,7 +8,6 @@ import { useEffect, useState, useCallback } from 'react';
import type { Chart } from 'klinecharts'; import type { Chart } from 'klinecharts';
import type { ChartType, KLineDataPoint, RawDataPoint } from '../types'; import type { ChartType, KLineDataPoint, RawDataPoint } from '../types';
import { processChartData } from '../utils/dataAdapter'; import { processChartData } from '../utils/dataAdapter';
import { logger } from '@utils/logger';
import { stockService } from '@services/eventService'; import { stockService } from '@services/eventService';
import { klineDataCache, getCacheKey } from '@views/Community/components/StockDetailPanel/utils/klineDataCache'; import { klineDataCache, getCacheKey } from '@views/Community/components/StockDetailPanel/utils/klineDataCache';
@@ -78,7 +77,6 @@ export const useKLineData = (
*/ */
const loadData = useCallback(async () => { const loadData = useCallback(async () => {
if (!stockCode) { if (!stockCode) {
logger.warn('useKLineData', 'loadData', '股票代码为空', { chartType });
return; return;
} }
@@ -86,11 +84,6 @@ export const useKLineData = (
setError(null); setError(null);
try { try {
logger.debug('useKLineData', 'loadData', '开始加载数据', {
stockCode,
chartType,
eventTime,
});
// 1. 先检查缓存 // 1. 先检查缓存
const cacheKey = getCacheKey(stockCode, eventTime, chartType); const cacheKey = getCacheKey(stockCode, eventTime, chartType);
@@ -125,19 +118,8 @@ export const useKLineData = (
const processedData = processChartData(rawDataList, chartType, eventTime); const processedData = processChartData(rawDataList, chartType, eventTime);
setData(processedData); setData(processedData);
logger.info('useKLineData', 'loadData', '数据加载成功', {
stockCode,
chartType,
rawCount: rawDataList.length,
processedCount: processedData.length,
});
} catch (err) { } catch (err) {
const error = err as Error; const error = err as Error;
logger.error('useKLineData', 'loadData', error, {
stockCode,
chartType,
});
setError(error); setError(error);
setData([]); setData([]);
setRawData([]); setRawData([]);
@@ -207,9 +189,7 @@ export const useKLineData = (
(chart as any).setOffsetRightDistance(50); (chart as any).setOffsetRightDistance(50);
} }
} catch (err) { } catch (err) {
logger.error('useKLineData', 'updateChartData', err as Error, { // 忽略调整可见范围时的错误
step: '调整可见范围失败',
});
} }
}, 100); // 延迟 100ms 确保数据已加载和渲染 }, 100); // 延迟 100ms 确保数据已加载和渲染
@@ -259,14 +239,8 @@ export const useKLineData = (
}, 200); // 延迟 200ms确保均价线创建完成后再添加 }, 200); // 延迟 200ms确保均价线创建完成后再添加
} }
logger.debug(
'useKLineData',
`updateChartData - ${stockCode} (${chartType}) - ${klineData.length}条数据加载成功`
);
} catch (err) { } catch (err) {
logger.error('useKLineData', 'updateChartData', err as Error, { // 忽略更新图表数据时的错误
dataCount: klineData.length,
});
} }
}, },
[chart, stockCode, chartType] [chart, stockCode, chartType]
@@ -279,11 +253,6 @@ export const useKLineData = (
(newData: KLineDataPoint[]) => { (newData: KLineDataPoint[]) => {
setData(newData); setData(newData);
updateChartData(newData); updateChartData(newData);
logger.debug(
'useKLineData',
`updateData - ${stockCode} (${chartType}) - ${newData.length}条数据手动更新`
);
}, },
[updateChartData] [updateChartData]
); );
@@ -298,7 +267,6 @@ export const useKLineData = (
if (chart) { if (chart) {
chart.resetData(); chart.resetData();
logger.debug('useKLineData', `clearData - chartId: ${(chart as any).id}`);
} }
}, [chart]); }, [chart]);

View File

@@ -4,8 +4,7 @@
* 包含图表初始化、技术指标管理等通用逻辑 * 包含图表初始化、技术指标管理等通用逻辑
*/ */
import type { Chart } from 'klinecharts'; import type { Chart, ActionType } from 'klinecharts';
import { logger } from '@utils/logger';
/** /**
* 安全地执行图表操作(捕获异常) * 安全地执行图表操作(捕获异常)
@@ -21,7 +20,6 @@ export const safeChartOperation = <T>(
try { try {
return fn(); return fn();
} catch (error) { } catch (error) {
logger.error('chartUtils', operation, error as Error);
return null; return null;
} }
}; };
@@ -50,13 +48,6 @@ export const createIndicator = (
isStack isStack
); );
logger.debug('chartUtils', 'createIndicator', '创建技术指标', {
indicatorName,
params,
isStack,
indicatorId,
});
return indicatorId; return indicatorId;
}); });
}; };
@@ -69,8 +60,11 @@ export const createIndicator = (
*/ */
export const removeIndicator = (chart: Chart, indicatorId?: string): void => { export const removeIndicator = (chart: Chart, indicatorId?: string): void => {
safeChartOperation('removeIndicator', () => { safeChartOperation('removeIndicator', () => {
chart.removeIndicator(indicatorId); if (indicatorId) {
logger.debug('chartUtils', 'removeIndicator', '移除技术指标', { indicatorId }); chart.removeIndicator({ id: indicatorId });
} else {
chart.removeIndicator({});
}
}); });
}; };
@@ -94,11 +88,6 @@ export const createSubIndicators = (
} }
}); });
logger.debug('chartUtils', 'createSubIndicators', '批量创建副图指标', {
indicators,
createdIds: ids,
});
return ids; return ids;
}; };
@@ -130,10 +119,6 @@ export const setChartZoom = (chart: Chart, zoom: number): void => {
}, },
}); });
logger.debug('chartUtils', 'setChartZoom', '设置图表缩放', {
zoom,
newBarSpace,
});
}); });
}; };
@@ -147,8 +132,6 @@ export const scrollToTimestamp = (chart: Chart, timestamp: number): void => {
safeChartOperation('scrollToTimestamp', () => { safeChartOperation('scrollToTimestamp', () => {
// KLineChart 10.0: 使用 scrollToTimestamp 方法 // KLineChart 10.0: 使用 scrollToTimestamp 方法
chart.scrollToTimestamp(timestamp); chart.scrollToTimestamp(timestamp);
logger.debug('chartUtils', 'scrollToTimestamp', '滚动到指定时间', { timestamp });
}); });
}; };
@@ -160,7 +143,6 @@ export const scrollToTimestamp = (chart: Chart, timestamp: number): void => {
export const resizeChart = (chart: Chart): void => { export const resizeChart = (chart: Chart): void => {
safeChartOperation('resizeChart', () => { safeChartOperation('resizeChart', () => {
chart.resize(); chart.resize();
logger.debug('chartUtils', 'resizeChart', '调整图表大小');
}); });
}; };
@@ -194,7 +176,6 @@ export const getVisibleRange = (chart: Chart): { from: number; to: number } | nu
export const clearChartData = (chart: Chart): void => { export const clearChartData = (chart: Chart): void => {
safeChartOperation('clearChartData', () => { safeChartOperation('clearChartData', () => {
chart.resetData(); chart.resetData();
logger.debug('chartUtils', 'clearChartData', '清空图表数据');
}); });
}; };
@@ -213,11 +194,6 @@ export const exportChartImage = (
// KLineChart 10.0: 使用 getConvertPictureUrl 方法 // KLineChart 10.0: 使用 getConvertPictureUrl 方法
const imageData = chart.getConvertPictureUrl(includeOverlay, 'png', '#ffffff'); const imageData = chart.getConvertPictureUrl(includeOverlay, 'png', '#ffffff');
logger.debug('chartUtils', 'exportChartImage', '导出图表图片', {
includeOverlay,
hasData: !!imageData,
});
return imageData; return imageData;
}); });
}; };
@@ -235,8 +211,6 @@ export const toggleCrosshair = (chart: Chart, show: boolean): void => {
show, show,
}, },
}); });
logger.debug('chartUtils', 'toggleCrosshair', '切换十字光标', { show });
}); });
}; };
@@ -253,8 +227,6 @@ export const toggleGrid = (chart: Chart, show: boolean): void => {
show, show,
}, },
}); });
logger.debug('chartUtils', 'toggleGrid', '切换网格', { show });
}); });
}; };
@@ -267,12 +239,11 @@ export const toggleGrid = (chart: Chart, show: boolean): void => {
*/ */
export const subscribeChartEvent = ( export const subscribeChartEvent = (
chart: Chart, chart: Chart,
eventName: string, eventName: ActionType,
handler: (...args: any[]) => void handler: (...args: any[]) => void
): void => { ): void => {
safeChartOperation(`subscribeChartEvent:${eventName}`, () => { safeChartOperation(`subscribeChartEvent:${eventName}`, () => {
chart.subscribeAction(eventName, handler); chart.subscribeAction(eventName, handler);
logger.debug('chartUtils', 'subscribeChartEvent', '订阅图表事件', { eventName });
}); });
}; };
@@ -285,11 +256,10 @@ export const subscribeChartEvent = (
*/ */
export const unsubscribeChartEvent = ( export const unsubscribeChartEvent = (
chart: Chart, chart: Chart,
eventName: string, eventName: ActionType,
handler: (...args: any[]) => void handler: (...args: any[]) => void
): void => { ): void => {
safeChartOperation(`unsubscribeChartEvent:${eventName}`, () => { safeChartOperation(`unsubscribeChartEvent:${eventName}`, () => {
chart.unsubscribeAction(eventName, handler); chart.unsubscribeAction(eventName, handler);
logger.debug('chartUtils', 'unsubscribeChartEvent', '取消订阅图表事件', { eventName });
}); });
}; };

View File

@@ -6,7 +6,6 @@
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import type { KLineDataPoint, RawDataPoint, ChartType } from '../types'; import type { KLineDataPoint, RawDataPoint, ChartType } from '../types';
import { logger } from '@utils/logger';
/** /**
* 将后端原始数据转换为 KLineChart 标准格式 * 将后端原始数据转换为 KLineChart 标准格式
@@ -22,7 +21,6 @@ export const convertToKLineData = (
eventTime?: string eventTime?: string
): KLineDataPoint[] => { ): KLineDataPoint[] => {
if (!rawData || !Array.isArray(rawData) || rawData.length === 0) { if (!rawData || !Array.isArray(rawData) || rawData.length === 0) {
logger.warn('dataAdapter', 'convertToKLineData', '原始数据为空', { chartType });
return []; return [];
} }
@@ -37,15 +35,11 @@ export const convertToKLineData = (
low: Number(item.low) || 0, low: Number(item.low) || 0,
close: Number(item.close) || 0, close: Number(item.close) || 0,
volume: Number(item.volume) || 0, volume: Number(item.volume) || 0,
turnover: item.turnover ? Number(item.turnover) : undefined, turnover: (item as any).turnover ? Number((item as any).turnover) : undefined,
prev_close: item.prev_close ? Number(item.prev_close) : undefined, // ✅ 新增:昨收价(用于百分比计算和基准线) prev_close: item.prev_close ? Number(item.prev_close) : undefined, // ✅ 新增:昨收价(用于百分比计算和基准线)
}; };
}); });
} catch (error) { } catch (error) {
logger.error('dataAdapter', 'convertToKLineData', error as Error, {
chartType,
dataLength: rawData.length,
});
return []; return [];
} }
}; };
@@ -90,7 +84,6 @@ const parseTimestamp = (
} }
// 默认返回当前时间(避免图表崩溃) // 默认返回当前时间(避免图表崩溃)
logger.warn('dataAdapter', 'parseTimestamp', '无法解析时间戳,使用当前时间', { item });
return Date.now(); return Date.now();
}; };
@@ -109,7 +102,6 @@ const parseTimelineTimestamp = (time: string, eventTime: string): number => {
const eventDate = dayjs(eventTime).startOf('day'); const eventDate = dayjs(eventTime).startOf('day');
return eventDate.hour(hours).minute(minutes).second(0).valueOf(); return eventDate.hour(hours).minute(minutes).second(0).valueOf();
} catch (error) { } catch (error) {
logger.error('dataAdapter', 'parseTimelineTimestamp', error as Error, { time, eventTime });
return dayjs(eventTime).valueOf(); return dayjs(eventTime).valueOf();
} }
}; };
@@ -126,19 +118,16 @@ export const validateAndCleanData = (data: KLineDataPoint[]): KLineDataPoint[] =
return data.filter((item) => { return data.filter((item) => {
// 移除价格为 0 或负数的数据 // 移除价格为 0 或负数的数据
if (item.open <= 0 || item.high <= 0 || item.low <= 0 || item.close <= 0) { if (item.open <= 0 || item.high <= 0 || item.low <= 0 || item.close <= 0) {
logger.warn('dataAdapter', 'validateAndCleanData', '价格异常,已移除', { item });
return false; return false;
} }
// 移除 high < low 的数据(数据错误) // 移除 high < low 的数据(数据错误)
if (item.high < item.low) { if (item.high < item.low) {
logger.warn('dataAdapter', 'validateAndCleanData', '最高价 < 最低价,已移除', { item });
return false; return false;
} }
// 移除成交量为负数的数据 // 移除成交量为负数的数据
if (item.volume < 0) { if (item.volume < 0) {
logger.warn('dataAdapter', 'validateAndCleanData', '成交量异常,已移除', { item });
return false; return false;
} }
@@ -213,17 +202,8 @@ export const trimDataByEventTime = (
return item.timestamp >= startTime && item.timestamp <= endTime; return item.timestamp >= startTime && item.timestamp <= endTime;
}); });
logger.debug('dataAdapter', 'trimDataByEventTime', '数据时间范围裁剪完成', {
originalLength: data.length,
trimmedLength: trimmedData.length,
eventTime,
chartType,
dateRange: `${dayjs(startTime).format('YYYY-MM-DD')} ~ ${dayjs(endTime).format('YYYY-MM-DD')}`,
});
return trimmedData; return trimmedData;
} catch (error) { } catch (error) {
logger.error('dataAdapter', 'trimDataByEventTime', error as Error, { eventTime });
return data; // 出错时返回原始数据 return data; // 出错时返回原始数据
} }
}; };
@@ -260,13 +240,6 @@ export const processChartData = (
data = trimDataByEventTime(data, eventTime, chartType); data = trimDataByEventTime(data, eventTime, chartType);
} }
logger.debug('dataAdapter', 'processChartData', '数据处理完成', {
rawLength: rawData.length,
processedLength: data.length,
chartType,
hasEventTime: !!eventTime,
});
return data; return data;
}; };

View File

@@ -9,7 +9,6 @@ import type { OverlayCreate } from 'klinecharts';
import type { EventMarker, KLineDataPoint } from '../types'; import type { EventMarker, KLineDataPoint } from '../types';
import { EVENT_MARKER_CONFIG } from '../config'; import { EVENT_MARKER_CONFIG } from '../config';
import { findClosestDataPoint } from './dataAdapter'; import { findClosestDataPoint } from './dataAdapter';
import { logger } from '@utils/logger';
/** /**
* 创建事件标记 OverlayKLineChart 10.0 格式) * 创建事件标记 OverlayKLineChart 10.0 格式)
@@ -27,10 +26,6 @@ export const createEventMarkerOverlay = (
const closestPoint = findClosestDataPoint(data, marker.timestamp); const closestPoint = findClosestDataPoint(data, marker.timestamp);
if (!closestPoint) { if (!closestPoint) {
logger.warn('eventMarkerUtils', 'createEventMarkerOverlay', '未找到匹配的数据点', {
markerId: marker.id,
timestamp: marker.timestamp,
});
return null; return null;
} }
@@ -64,10 +59,6 @@ export const createEventMarkerOverlay = (
style: 'fill', style: 'fill',
color: marker.color, color: marker.color,
borderRadius: EVENT_MARKER_CONFIG.text.borderRadius, borderRadius: EVENT_MARKER_CONFIG.text.borderRadius,
paddingLeft: EVENT_MARKER_CONFIG.text.padding,
paddingRight: EVENT_MARKER_CONFIG.text.padding,
paddingTop: EVENT_MARKER_CONFIG.text.padding,
paddingBottom: EVENT_MARKER_CONFIG.text.padding,
}, },
}, },
// 标记文本内容 // 标记文本内容
@@ -77,17 +68,8 @@ export const createEventMarkerOverlay = (
}, },
}; };
logger.debug('eventMarkerUtils', 'createEventMarkerOverlay', '创建事件标记', {
markerId: marker.id,
timestamp: closestPoint.timestamp,
label: marker.label,
});
return overlay; return overlay;
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'createEventMarkerOverlay', error as Error, {
markerId: marker.id,
});
return null; return null;
} }
}; };
@@ -108,7 +90,6 @@ export const createEventHighlightOverlay = (
const closestPoint = findClosestDataPoint(data, eventTimestamp); const closestPoint = findClosestDataPoint(data, eventTimestamp);
if (!closestPoint) { if (!closestPoint) {
logger.warn('eventMarkerUtils', 'createEventHighlightOverlay', '未找到匹配的数据点');
return null; return null;
} }
@@ -135,14 +116,8 @@ export const createEventHighlightOverlay = (
}, },
}; };
logger.debug('eventMarkerUtils', 'createEventHighlightOverlay', '创建事件高亮覆盖层', {
timestamp: closestPoint.timestamp,
eventTime,
});
return overlay; return overlay;
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'createEventHighlightOverlay', error as Error);
return null; return null;
} }
}; };
@@ -219,11 +194,6 @@ export const createEventMarkerOverlays = (
} }
}); });
logger.debug('eventMarkerUtils', 'createEventMarkerOverlays', '批量创建事件标记', {
totalMarkers: markers.length,
createdOverlays: overlays.length,
});
return overlays; return overlays;
}; };
@@ -235,10 +205,9 @@ export const createEventMarkerOverlays = (
*/ */
export const removeEventMarker = (chart: any, markerId: string): void => { export const removeEventMarker = (chart: any, markerId: string): void => {
try { try {
chart.removeOverlay(markerId); chart.removeOverlay({ id: markerId });
logger.debug('eventMarkerUtils', 'removeEventMarker', '移除事件标记', { markerId });
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'removeEventMarker', error as Error, { markerId }); // 忽略移除标记时的错误
} }
}; };
@@ -251,9 +220,8 @@ export const removeAllEventMarkers = (chart: any): void => {
try { try {
// KLineChart 10.0 API: removeOverlay() 不传参数时移除所有 overlays // KLineChart 10.0 API: removeOverlay() 不传参数时移除所有 overlays
chart.removeOverlay(); chart.removeOverlay();
logger.debug('eventMarkerUtils', 'removeAllEventMarkers', '移除所有事件标记');
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'removeAllEventMarkers', error as Error); // 忽略移除所有标记时的错误
} }
}; };
@@ -275,13 +243,8 @@ export const updateEventMarker = (
// 重新创建标记KLineChart 10.0 不支持直接更新 overlay // 重新创建标记KLineChart 10.0 不支持直接更新 overlay
// 注意:需要在调用方重新创建并添加 overlay // 注意:需要在调用方重新创建并添加 overlay
logger.debug('eventMarkerUtils', 'updateEventMarker', '更新事件标记', {
markerId,
updates,
});
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'updateEventMarker', error as Error, { markerId }); // 忽略更新标记时的错误
} }
}; };
@@ -309,12 +272,8 @@ export const highlightEventMarker = (
}, },
}); });
logger.debug('eventMarkerUtils', 'highlightEventMarker', '高亮事件标记', {
markerId,
highlight,
});
} catch (error) { } catch (error) {
logger.error('eventMarkerUtils', 'highlightEventMarker', error as Error, { markerId }); // 忽略高亮标记时的错误
} }
}; };

View File

@@ -4,7 +4,6 @@
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import type { Dispatch, SetStateAction, KeyboardEvent } from 'react'; import type { Dispatch, SetStateAction, KeyboardEvent } from 'react';
import axios from 'axios'; import axios from 'axios';
import { logger } from '@utils/logger';
import { MessageTypes, type Message } from '../constants/messageTypes'; import { MessageTypes, type Message } from '../constants/messageTypes';
import type { UploadedFile } from './useFileUpload'; import type { UploadedFile } from './useFileUpload';
import type { User } from './useAgentSessions'; import type { User } from './useAgentSessions';
@@ -221,7 +220,7 @@ export const useAgentChat = ({
loadSessions(); loadSessions();
} }
} catch (error: any) { } catch (error: any) {
logger.error('Agent chat error', error); console.error('Agent chat error:', error);
// 移除 "思考中" 和 "执行中" 消息 // 移除 "思考中" 和 "执行中" 消息
setMessages((prev) => setMessages((prev) =>

View File

@@ -4,7 +4,6 @@
import { useState, useEffect, useCallback } from 'react'; import { useState, useEffect, useCallback } from 'react';
import type { Dispatch, SetStateAction } from 'react'; import type { Dispatch, SetStateAction } from 'react';
import axios from 'axios'; import axios from 'axios';
import { logger } from '@utils/logger';
import { MessageTypes, type Message } from '../constants/messageTypes'; import { MessageTypes, type Message } from '../constants/messageTypes';
/** /**
@@ -103,7 +102,7 @@ export const useAgentSessions = ({
setSessions(response.data.data); setSessions(response.data.data);
} }
} catch (error) { } catch (error) {
logger.error('加载会话列表失败', error); console.error('加载会话列表失败:', error);
} finally { } finally {
setIsLoadingSessions(false); setIsLoadingSessions(false);
} }
@@ -135,7 +134,7 @@ export const useAgentSessions = ({
setMessages(formattedMessages); setMessages(formattedMessages);
} }
} catch (error) { } catch (error) {
logger.error('加载会话历史失败', error); console.error('加载会话历史失败:', error);
} }
}, },
[setMessages] [setMessages]