fix: 修复 AgentChat hooks 中的 logger 调用

This commit is contained in:
zdl
2025-11-26 09:47:54 +08:00
parent 0818a7bff7
commit 601b06d79e
2 changed files with 24 additions and 29 deletions

View File

@@ -64,7 +64,7 @@ export const useKLineChart = (
// 全局注册自定义均价线指标(只执行一次) // 全局注册自定义均价线指标(只执行一次)
useEffect(() => { useEffect(() => {
try { try {
registerIndicator(avgPriceIndicator); registerIndicator(avgPriceIndicator as any);
} catch (err) { } catch (err) {
// 如果已注册会报错,忽略即可 // 如果已注册会报错,忽略即可
} }

View File

@@ -5,17 +5,18 @@
* 计算公式:累计成交额 / 累计成交量 * 计算公式:累计成交额 / 累计成交量
*/ */
import type { Indicator, KLineData } from 'klinecharts'; import type { KLineData } from 'klinecharts';
export const avgPriceIndicator: Indicator = { // 使用部分类型定义,因为 Indicator 类型很复杂
export const avgPriceIndicator = {
name: 'AVG', name: 'AVG',
shortName: 'AVG', shortName: 'AVG',
calcParams: [], calcParams: [] as number[],
shouldOhlc: false, // 不显示 OHLC 信息 shouldOhlc: false, // 不显示 OHLC 信息
shouldFormatBigNumber: false, shouldFormatBigNumber: false,
precision: 2, precision: 2,
minValue: null, minValue: null as number | null,
maxValue: null, maxValue: null as number | null,
figures: [ figures: [
{ {
@@ -61,33 +62,27 @@ export const avgPriceIndicator: Indicator = {
}, },
/** /**
* Tooltip 格式化(显示均价 + 涨跌幅) * 自定义 Tooltip 数据源
* 符合 IndicatorTooltipData 接口要求
*/ */
createTooltipDataSource: ({ kLineData, indicator, defaultStyles }: any) => { createTooltipDataSource: ({ kLineData, indicator, defaultStyles }: any) => {
if (!indicator?.avg) { const avgValue = kLineData?.avg;
return { const lineColor = defaultStyles?.lines?.[0]?.color || '#FF9800';
title: { text: '均价', color: defaultStyles.tooltip.text.color },
value: { text: '--', color: '#FF9800' },
};
}
const avgPrice = indicator.avg;
const prevClose = kLineData?.prev_close;
// 计算均价涨跌幅
let changeText = `¥${avgPrice.toFixed(2)}`;
if (prevClose && prevClose > 0) {
const changePercent = ((avgPrice - prevClose) / prevClose * 100).toFixed(2);
const changeValue = (avgPrice - prevClose).toFixed(2);
changeText = `¥${avgPrice.toFixed(2)} (${changeValue}, ${changePercent}%)`;
}
return { return {
title: { text: '均价', color: defaultStyles.tooltip.text.color }, name: 'AVG',
calcParamsText: '',
features: [] as any[],
legends: [
{
title: { text: '均价: ', color: lineColor },
value: { value: {
text: changeText, text: avgValue !== undefined ? avgValue.toFixed(2) : '--',
color: '#FF9800', color: lineColor,
}, },
},
],
}; };
}, },
}; };