From 59a8fae52333c035842b96b99a2962bbe5068bf9 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Fri, 19 Dec 2025 10:15:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20financialService?= =?UTF-8?q?=20=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E=E5=92=8C=20EChartsWrapp?= =?UTF-8?q?er=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - financialService.d.ts: 为 JS 服务文件提供 TypeScript 类型声明 - EChartsWrapper.tsx: 按需引入的 ECharts 包装组件,减小打包体积 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/services/financialService.d.ts | 49 +++++++++++++++++++ .../Company/components/EChartsWrapper.tsx | 48 ++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/services/financialService.d.ts create mode 100644 src/views/Company/components/EChartsWrapper.tsx diff --git a/src/services/financialService.d.ts b/src/services/financialService.d.ts new file mode 100644 index 00000000..98be3fd7 --- /dev/null +++ b/src/services/financialService.d.ts @@ -0,0 +1,49 @@ +// financialService 类型声明 + +export interface RequestOptions { + signal?: AbortSignal; +} + +export interface ApiResponse { + success: boolean; + data: T; + message?: string; +} + +export interface FinancialService { + getStockInfo(seccode: string, options?: RequestOptions): Promise>; + getBalanceSheet(seccode: string, limit?: number, options?: RequestOptions): Promise>; + getIncomeStatement(seccode: string, limit?: number, options?: RequestOptions): Promise>; + getCashflow(seccode: string, limit?: number, options?: RequestOptions): Promise>; + getFinancialMetrics(seccode: string, limit?: number, options?: RequestOptions): Promise>; + getMainBusiness(seccode: string, periods?: number, options?: RequestOptions): Promise>; + getForecast(seccode: string, options?: RequestOptions): Promise>; + getIndustryRank(seccode: string, limit?: number, options?: RequestOptions): Promise>; + getPeriodComparison(seccode: string, periods?: number, options?: RequestOptions): Promise>; +} + +export const financialService: FinancialService; + +export interface FormatUtils { + formatLargeNumber(num: number, decimal?: number): string; + formatPercent(num: number, decimal?: number): string; + formatDate(dateStr: string): string; + getReportType(dateStr: string): string; + getGrowthColor(value: number): string; + getTrendIcon(current: number, previous: number): 'up' | 'down' | 'stable'; + calculateYoY(current: number, yearAgo: number): number | null; + calculateQoQ(current: number, previous: number): number | null; + getFinancialHealthScore(metrics: any): { score: number; level: string; color: string } | null; + getTableColumns(type: string): any[]; +} + +export const formatUtils: FormatUtils; + +export interface ChartUtils { + prepareTrendData(data: any[], metrics: any[]): any[]; + preparePieData(data: any[], valueKey: string, nameKey: string): any[]; + prepareComparisonData(data: any[], periods: any[], metrics: any[]): any[]; + getChartColors(theme?: string): string[]; +} + +export const chartUtils: ChartUtils; diff --git a/src/views/Company/components/EChartsWrapper.tsx b/src/views/Company/components/EChartsWrapper.tsx new file mode 100644 index 00000000..386a3f52 --- /dev/null +++ b/src/views/Company/components/EChartsWrapper.tsx @@ -0,0 +1,48 @@ +/** + * ECharts 包装组件 - 按需引入版本 + * + * 使用方式: + * import EChartsWrapper from '../EChartsWrapper'; + * + * + * 优势: + * - 减小打包体积(从 ~800KB 降至 ~200-300KB) + * - 统一管理图表实例 + * - 兼容原有 ReactECharts 的所有属性 + */ + +import React, { memo } from 'react'; +import ReactEChartsCore from 'echarts-for-react/lib/core'; +import { echarts, type EChartsOption } from '@lib/echarts'; +import type { EChartsReactProps } from 'echarts-for-react'; + +// 重新导出类型 +export type { EChartsOption }; + +interface EChartsWrapperProps extends Omit { + option: EChartsOption; +} + +/** + * ECharts 包装组件 + * + * 使用按需引入的 echarts 实例,减小打包体积 + */ +const EChartsWrapper: React.FC = memo((props) => { + const { option, ...restProps } = props; + + return ( + + ); +}); + +EChartsWrapper.displayName = 'EChartsWrapper'; + +export default EChartsWrapper;