初始化2

This commit is contained in:
SunYF
2026-08-28 15:06:01 +08:00
parent b34325a16f
commit a9c3fbeb41
537 changed files with 176215 additions and 17 deletions
@@ -0,0 +1,28 @@
import { useEffect, useRef } from 'react';
import * as echarts from 'echarts';
import type { EChartsOption } from 'echarts';
interface EChartProps {
option: EChartsOption;
height?: number | string;
}
/** 简易 ECharts 容器,option 变化时自动更新,卸载时销毁实例。 */
export function EChart({ option, height = 260 }: EChartProps) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = ref.current;
if (!el) return;
const chart = echarts.init(el);
chart.setOption(option);
const onResize = () => chart.resize();
window.addEventListener('resize', onResize);
return () => {
window.removeEventListener('resize', onResize);
chart.dispose();
};
}, [option]);
return <div ref={ref} style={{ width: '100%', height }} />;
}
@@ -0,0 +1,43 @@
import { Button, Empty, Typography } from '@douyinfe/semi-ui';
import { IconRefresh } from '@douyinfe/semi-icons';
import type { ReactNode } from 'react';
import type { DataMode } from '../hooks/useDashboardData';
interface ErrorRetryProps {
error: string | null;
mode: DataMode;
loading: boolean;
onRetry: () => void;
children: ReactNode;
}
/** 数据加载失败时显示错误与重试按钮的兜底容器,避免空白崩溃。 */
export function ErrorRetry({ error, mode, loading, onRetry, children }: ErrorRetryProps) {
const failed = Boolean(error) && !loading;
return (
<div>
{failed ? (
<div style={{ textAlign: 'center', padding: '60px 0' }}>
<Empty
description={
<Typography.Text type="danger">
{error}
{mode !== 'init' ? `(当前连接方式:${mode === 'sse' ? 'SSE' : 'HTTP 轮询'})` : ''}
</Typography.Text>
}
/>
<Button
theme="solid"
icon={<IconRefresh />}
onClick={onRetry}
style={{ marginTop: 16 }}
>
重试
</Button>
</div>
) : (
children
)}
</div>
);
}