1068 lines
32 KiB
JavaScript
1068 lines
32 KiB
JavaScript
import React, { useState, useEffect, useRef } from 'react';
|
||
import {
|
||
Row, Col, Card, Button, Tag, Typography, Space, Statistic, message,
|
||
Divider, Input, Select, Switch, Upload, Progress, Tabs, Empty,
|
||
InputNumber, Radio, Spin
|
||
} from 'antd';
|
||
import {
|
||
ReloadOutlined, InfoCircleOutlined, ThunderboltOutlined,
|
||
AppstoreOutlined, CheckCircleOutlined, CloudOutlined,
|
||
AimOutlined, FireOutlined, InboxOutlined,
|
||
PlayCircleOutlined, FileTextOutlined, HistoryOutlined,
|
||
SearchOutlined, SettingOutlined, FullscreenOutlined,
|
||
UploadOutlined, LoadingOutlined, CheckOutlined,
|
||
SyncOutlined, DatabaseOutlined
|
||
} from '@ant-design/icons';
|
||
import {
|
||
getDetectModels,
|
||
submitDetectJob,
|
||
getDetectJobStatus,
|
||
getDetectJobResult,
|
||
submitSegmentationAnalyze
|
||
} from '../api/aiAnalysis';
|
||
import utils from '../lib/utils';
|
||
|
||
const { Title, Text } = Typography;
|
||
const { Dragger } = Upload;
|
||
const { Option } = Select;
|
||
|
||
// 算法列表定义
|
||
const algorithmList = [
|
||
{
|
||
id: 'detect',
|
||
name: '目标检测',
|
||
alias: 'waterway-trt',
|
||
desc: '图片/视频检测,创建任务后轮询结果。',
|
||
icon: <AimOutlined />,
|
||
status: '运行中'
|
||
},
|
||
{
|
||
id: 'segmentation',
|
||
name: '热成像分割',
|
||
alias: 'v1.0.0',
|
||
desc: '热成像热点、面板分区和温度统计。',
|
||
icon: <FireOutlined />,
|
||
status: '运行中'
|
||
}
|
||
];
|
||
|
||
export default function Agri() {
|
||
const [activeAlgo, setActiveAlgo] = useState('detect');
|
||
const [models, setModels] = useState([]);
|
||
const [loadingModels, setLoadingModels] = useState(false);
|
||
const [history, setHistory] = useState([]);
|
||
|
||
// 检测任务状态
|
||
const [detectForm, setDetectForm] = useState({
|
||
modelAlias: '',
|
||
inputType: 'image',
|
||
conf: 0.25,
|
||
iou: 0.45,
|
||
imgsz: 1280,
|
||
device: 'auto',
|
||
maxDet: 300,
|
||
vidStride: 1,
|
||
half: false,
|
||
speedPreset: 'speed'
|
||
});
|
||
const [detectFiles, setDetectFiles] = useState([]);
|
||
const [selectedHotspot, setSelectedHotspot] = useState(null);
|
||
|
||
const [detectJobId, setDetectJobId] = useState(null);
|
||
const [detectStatus, setDetectStatus] = useState(null);
|
||
const [detectResult, setDetectResult] = useState(null);
|
||
const [polling, setPolling] = useState(false);
|
||
|
||
// 分割任务状态
|
||
const [segForm, setSegForm] = useState({
|
||
threshold_c: 48,
|
||
min_area_px: 25,
|
||
max_regions: 120,
|
||
include_panel_segments: true
|
||
});
|
||
const [thermalFile, setThermalFile] = useState(null);
|
||
const [maskFile, setMaskFile] = useState(null);
|
||
const [geojsonFile, setGeojsonFile] = useState(null);
|
||
const [segResult, setSegResult] = useState(null);
|
||
const [segLoading, setSegLoading] = useState(false);
|
||
|
||
const pollTimer = useRef(null);
|
||
|
||
// 初始化:加载模型列表
|
||
useEffect(() => {
|
||
fetchModels();
|
||
}, []);
|
||
|
||
const fetchModels = async () => {
|
||
setLoadingModels(true);
|
||
try {
|
||
const res = await getDetectModels();
|
||
if (res && res.list) {
|
||
setModels(res.list);
|
||
const defaultModel = res.list.find(m => m.default) || res.list[0];
|
||
if (defaultModel) {
|
||
setDetectForm(prev => ({ ...prev, modelAlias: defaultModel.alias }));
|
||
}
|
||
}
|
||
} catch (err) {
|
||
utils.message.error('获取模型列表失败');
|
||
} finally {
|
||
setLoadingModels(false);
|
||
}
|
||
};
|
||
|
||
// --- 目标检测逻辑 ---
|
||
|
||
const handleSubmitDetect = async () => {
|
||
if (detectFiles.length === 0) {
|
||
utils.message.warning('请先上传图片或视频');
|
||
return;
|
||
}
|
||
|
||
const formData = new FormData();
|
||
detectFiles.forEach(file => {
|
||
console.log(file, "dsdsvc")
|
||
formData.append('files', file.originFileObj);
|
||
});
|
||
formData.append('inputType', detectForm.inputType);
|
||
formData.append('modelAlias', detectForm.modelAlias);
|
||
formData.append('conf', detectForm.conf.toString());
|
||
formData.append('iou', detectForm.iou.toString());
|
||
formData.append('imgsz', detectForm.imgsz.toString());
|
||
formData.append('device', detectForm.device);
|
||
formData.append('maxDet', detectForm.maxDet.toString());
|
||
formData.append('vidStride', detectForm.vidStride.toString());
|
||
formData.append('half', detectForm.half.toString());
|
||
|
||
try {
|
||
setDetectStatus('submitting');
|
||
const res = await submitDetectJob(formData);
|
||
if (res && res.jobId) {
|
||
setDetectJobId(res.jobId);
|
||
setDetectStatus('queued');
|
||
setPolling(true);
|
||
startPolling(res.jobId);
|
||
// 添加到历史
|
||
addToHistory('detect', res.jobId);
|
||
}
|
||
} catch (err) {
|
||
utils.message.error('提交任务失败');
|
||
setDetectStatus(null);
|
||
}
|
||
};
|
||
|
||
const startPolling = (jobId) => {
|
||
if (pollTimer.current) clearInterval(pollTimer.current);
|
||
pollTimer.current = setInterval(async () => {
|
||
try {
|
||
const statusRes = await getDetectJobStatus(jobId);
|
||
setDetectStatus(statusRes.status);
|
||
if (statusRes.status === 'succeeded') {
|
||
clearInterval(pollTimer.current);
|
||
setPolling(false);
|
||
const resultRes = await getDetectJobResult(jobId);
|
||
setDetectResult(resultRes);
|
||
utils.message.success('任务执行成功');
|
||
} else if (['failed', 'cancelled'].includes(statusRes.status)) {
|
||
clearInterval(pollTimer.current);
|
||
setPolling(false);
|
||
utils.message.error(`任务执行${statusRes.status === 'failed' ? '失败' : '被取消'}`);
|
||
}
|
||
} catch (err) {
|
||
console.error('轮询失败', err);
|
||
}
|
||
}, 2000);
|
||
};
|
||
|
||
// --- 热成像分割逻辑 ---
|
||
|
||
const handleSubmitSeg = async () => {
|
||
if (!thermalFile) {
|
||
utils.message.warning('请先上传热成像文件');
|
||
return;
|
||
}
|
||
|
||
const formData = new FormData();
|
||
formData.append('thermal_file', thermalFile.originFileObj);
|
||
if (maskFile) formData.append('array_mask_file', maskFile.originFileObj);
|
||
if (geojsonFile) formData.append('panel_geojson_file', geojsonFile.originFileObj);
|
||
formData.append('threshold_c', segForm.threshold_c.toString());
|
||
formData.append('min_area_px', segForm.min_area_px.toString());
|
||
formData.append('max_regions', segForm.max_regions.toString());
|
||
formData.append('include_panel_segments', segForm.include_panel_segments.toString());
|
||
|
||
setSegLoading(true);
|
||
try {
|
||
const res = await submitSegmentationAnalyze(formData);
|
||
setSegResult(res);
|
||
utils.message.success('热成像分析完成');
|
||
addToHistory('segmentation', res.analysisId || 'seg-' + Date.now());
|
||
} catch (err) {
|
||
utils.message.error('热成像分析失败');
|
||
} finally {
|
||
setSegLoading(false);
|
||
}
|
||
};
|
||
|
||
const addToHistory = (type, id) => {
|
||
const newItem = {
|
||
id,
|
||
type,
|
||
time: new Date().toLocaleString(),
|
||
name: type === 'detect' ? '目标检测任务' : '热成像分割分析'
|
||
};
|
||
setHistory(prev => [newItem, ...prev]);
|
||
};
|
||
|
||
|
||
// 替换成这个 renderStats
|
||
const renderStats = () => (
|
||
<Row gutter={[8, 8]} style={{ marginBottom: 8 }}>
|
||
{[
|
||
{
|
||
title: '算法数量',
|
||
value: '2',
|
||
unit: '检测 + 分割',
|
||
icon: <AppstoreOutlined />,
|
||
color: '#165DFF',
|
||
bg: '#E8F3FF',
|
||
},
|
||
{
|
||
title: '在线服务',
|
||
value: '2',
|
||
unit: 'health 实时检查',
|
||
icon: <CloudOutlined />,
|
||
color: '#00B42A',
|
||
bg: '#E8FFEA',
|
||
},
|
||
{
|
||
title: '模型数量',
|
||
value: models.length || 3,
|
||
unit: '检测模型 registry',
|
||
icon: <DatabaseOutlined />,
|
||
color: '#165DFF',
|
||
bg: '#E8F3FF',
|
||
},
|
||
{
|
||
title: '历史记录',
|
||
value: history.length,
|
||
unit: '本页联调记录',
|
||
icon: <HistoryOutlined />,
|
||
color: '#722ED1',
|
||
bg: '#F3E8FF',
|
||
},
|
||
].map((item, index) => (
|
||
<Col key={index} xs={24} sm={12} md={12} xl={6}>
|
||
<Card
|
||
bordered={false}
|
||
bodyStyle={{ padding: '20px 16px' }}
|
||
style={{ height: '100%' }}
|
||
>
|
||
<div
|
||
style={{
|
||
display: 'flex',
|
||
justifyContent: 'space-between',
|
||
alignItems: 'flex-start',
|
||
}}
|
||
>
|
||
<div style={{ flex: 1 }}>
|
||
<div
|
||
style={{
|
||
fontSize: 'clamp(12px, 0.8vw, 13px)',
|
||
color: '#86909C',
|
||
marginBottom: 8,
|
||
whiteSpace: 'nowrap',
|
||
}}
|
||
>
|
||
{item.title}
|
||
</div>
|
||
<div
|
||
style={{
|
||
fontSize: 'clamp(20px, 1.4vw, 24px)',
|
||
fontWeight: 800,
|
||
color: item.color,
|
||
display: 'flex',
|
||
alignItems: 'baseline',
|
||
gap: 4,
|
||
}}
|
||
>
|
||
{item.value}
|
||
{item.unit && (
|
||
<span
|
||
style={{
|
||
fontSize: 13,
|
||
fontWeight: 400,
|
||
color: '#86909C',
|
||
}}
|
||
>
|
||
{item.unit}
|
||
</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div
|
||
style={{
|
||
width: 44,
|
||
height: 44,
|
||
background: item.bg,
|
||
borderRadius: '12px',
|
||
display: 'flex',
|
||
justifyContent: 'center',
|
||
alignItems: 'center',
|
||
flexShrink: 0,
|
||
boxShadow: `0 4px 10px ${item.bg}80`,
|
||
}}
|
||
>
|
||
{React.cloneElement(item.icon, {
|
||
style: { fontSize: 22, color: item.color },
|
||
})}
|
||
</div>
|
||
</div>
|
||
</Card>
|
||
</Col>
|
||
))}
|
||
</Row>
|
||
);
|
||
|
||
// 渲染检测工作区
|
||
const renderDetectWorkspace = () => (
|
||
<div style={{ padding: '0 8px' }}>
|
||
<div style={{ marginBottom: 16 }}>
|
||
<Text strong style={{ fontSize: 15 }}>检测模型</Text>
|
||
<Select
|
||
style={{ width: '100%', marginTop: 8 }}
|
||
value={detectForm.modelAlias}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, modelAlias: val }))}
|
||
loading={loadingModels}
|
||
>
|
||
{models.map(m => (
|
||
<Option key={m.alias} value={m.alias}>{m.alias} {m.default ? '(默认)' : ''}</Option>
|
||
))}
|
||
</Select>
|
||
</div>
|
||
|
||
<Row gutter={[16, 16]}>
|
||
<Col span={12}>
|
||
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>输入类型</Text>
|
||
<Radio.Group
|
||
value={detectForm.inputType}
|
||
onChange={e => setDetectForm(prev => ({ ...prev, inputType: e.target.value }))}
|
||
buttonStyle="solid"
|
||
size="small"
|
||
>
|
||
<Radio.Button value="image">图片</Radio.Button>
|
||
<Radio.Button value="video">视频</Radio.Button>
|
||
</Radio.Group>
|
||
</Col>
|
||
<Col span={12}>
|
||
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>推理预设</Text>
|
||
<Radio.Group
|
||
value={detectForm.speedPreset}
|
||
onChange={e => setDetectForm(prev => ({ ...prev, speedPreset: e.target.value }))}
|
||
size="small"
|
||
>
|
||
<Radio.Button value="quality">质量</Radio.Button>
|
||
<Radio.Button value="speed">速度</Radio.Button>
|
||
</Radio.Group>
|
||
</Col>
|
||
</Row>
|
||
|
||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>conf</Text>
|
||
<InputNumber
|
||
size="small"
|
||
min={0} max={1} step={0.01}
|
||
value={detectForm.conf}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, conf: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>iou</Text>
|
||
<InputNumber
|
||
size="small"
|
||
min={0} max={1} step={0.01}
|
||
value={detectForm.iou}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, iou: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>imgsz</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={detectForm.imgsz}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, imgsz: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>device</Text>
|
||
<Select
|
||
size="small"
|
||
value={detectForm.device}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, device: val }))}
|
||
style={{ width: '100%' }}
|
||
>
|
||
<Option value="auto">auto</Option>
|
||
<Option value="cpu">cpu</Option>
|
||
<Option value="cuda:0">cuda:0</Option>
|
||
</Select>
|
||
</Col>
|
||
</Row>
|
||
|
||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>max_det</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={detectForm.maxDet}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, maxDet: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>vid_stride</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={detectForm.vidStride}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, vidStride: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>half</Text>
|
||
<Switch
|
||
size="small"
|
||
checked={detectForm.half}
|
||
onChange={val => setDetectForm(prev => ({ ...prev, half: val }))}
|
||
/>
|
||
</Col>
|
||
</Row>
|
||
|
||
<div style={{ marginTop: 24 }}>
|
||
<Dragger
|
||
fileList={detectFiles}
|
||
onChange={info => {
|
||
setDetectFiles(info.fileList.slice(-1));
|
||
}}
|
||
beforeUpload={() => false}
|
||
limit={1}
|
||
style={{ background: '#fafafa', borderRadius: 8 }}
|
||
>
|
||
<p className="ant-upload-drag-icon">
|
||
<InboxOutlined style={{ color: '#1677ff' }} />
|
||
</p>
|
||
<p className="ant-upload-text">拖拽文件到此处,或点击选择</p>
|
||
<p className="ant-upload-hint">支持 jpg/png/webp/mp4 等格式</p>
|
||
</Dragger>
|
||
</div>
|
||
|
||
<Space style={{ marginTop: 24 }}>
|
||
<Button
|
||
type="primary"
|
||
icon={polling ? <LoadingOutlined /> : <CheckCircleOutlined />}
|
||
onClick={handleSubmitDetect}
|
||
disabled={polling}
|
||
>
|
||
{polling ? '任务处理中...' : '提交检测任务'}
|
||
</Button>
|
||
<Button icon={<PlayCircleOutlined />}>调用服务器样例</Button>
|
||
<Button icon={<SyncOutlined />} onClick={fetchModels}>刷新模型</Button>
|
||
</Space>
|
||
</div>
|
||
);
|
||
|
||
// 渲染分割工作区
|
||
const renderSegWorkspace = () => (
|
||
<div style={{ padding: '0 8px' }}>
|
||
<Row gutter={[16, 16]}>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>threshold_c</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={segForm.threshold_c}
|
||
onChange={val => setSegForm(prev => ({ ...prev, threshold_c: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>min_area_px</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={segForm.min_area_px}
|
||
onChange={val => setSegForm(prev => ({ ...prev, min_area_px: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>max_regions</Text>
|
||
<InputNumber
|
||
size="small"
|
||
value={segForm.max_regions}
|
||
onChange={val => setSegForm(prev => ({ ...prev, max_regions: val }))}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Col>
|
||
<Col span={6}>
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>include_panel_segments</Text>
|
||
<Switch
|
||
size="small"
|
||
checked={segForm.include_panel_segments}
|
||
onChange={val => setSegForm(prev => ({ ...prev, include_panel_segments: val }))}
|
||
/>
|
||
</Col>
|
||
</Row>
|
||
|
||
<div style={{ marginTop: 24 }}>
|
||
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>热成像文件 thermal_file</Text>
|
||
<Dragger
|
||
fileList={thermalFile ? [thermalFile] : []}
|
||
onChange={info => setThermalFile(info.fileList[0])}
|
||
beforeUpload={() => false}
|
||
maxCount={1}
|
||
style={{ background: '#fafafa', borderRadius: 8, height: 120 }}
|
||
>
|
||
<p className="ant-upload-drag-icon" style={{ fontSize: 24 }}>
|
||
<CloudOutlined style={{ color: '#1677ff' }} />
|
||
</p>
|
||
<p style={{ fontSize: 12 }}>上传 TIFF / PNG / JPG 热成像文件</p>
|
||
</Dragger>
|
||
</div>
|
||
|
||
<Space style={{ marginTop: 16 }}>
|
||
<Upload
|
||
fileList={maskFile ? [maskFile] : []}
|
||
onChange={info => setMaskFile(info.fileList[0])}
|
||
beforeUpload={() => false}
|
||
maxCount={1}
|
||
>
|
||
<Button size="small">阵列 mask</Button>
|
||
</Upload>
|
||
<Upload
|
||
fileList={geojsonFile ? [geojsonFile] : []}
|
||
onChange={info => setGeojsonFile(info.fileList[0])}
|
||
beforeUpload={() => false}
|
||
maxCount={1}
|
||
>
|
||
<Button size="small">面板 GeoJSON</Button>
|
||
</Upload>
|
||
</Space>
|
||
|
||
<Space style={{ marginTop: 24 }}>
|
||
<Button
|
||
type="primary"
|
||
icon={segLoading ? <LoadingOutlined /> : <CheckOutlined />}
|
||
onClick={handleSubmitSeg}
|
||
loading={segLoading}
|
||
>
|
||
提交热成像分析
|
||
</Button>
|
||
<Button icon={<PlayCircleOutlined />}>调用服务器样例</Button>
|
||
<Button icon={<HistoryOutlined />}>读取服务器历史</Button>
|
||
</Space>
|
||
</div>
|
||
);
|
||
|
||
// 1. 目标检测的结果布局(第一张图的样式:三列)
|
||
const renderDetectResultLayout = () => {
|
||
const inputFile = detectFiles[0];
|
||
const hasResult = !!detectResult;
|
||
|
||
return (
|
||
<Card
|
||
title={<Text strong style={{ fontSize: 14 }}>结果展示</Text>}
|
||
bordered={false}
|
||
style={{ marginTop: 12, borderRadius: 8 }}
|
||
bodyStyle={{ padding: '12px' }}
|
||
>
|
||
<Text type="secondary" style={{ fontSize: 11, display: 'block', marginBottom: 12 }}>
|
||
原始预览、结果图与完整 JSON 同屏查看
|
||
</Text>
|
||
<Row gutter={12}>
|
||
{/* 输入预览 */}
|
||
<Col span={8}>
|
||
<Card size="small" title="输入预览" style={{ height: 480 }}>
|
||
<div style={{ height: 400, background: '#001529', display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }}>
|
||
{inputFile && (
|
||
detectForm.inputType === 'image' ? (
|
||
<img
|
||
src={URL.createObjectURL(inputFile.originFileObj)}
|
||
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
||
alt="input"
|
||
/>
|
||
) : (
|
||
<video
|
||
src={URL.createObjectURL(inputFile.originFileObj)}
|
||
controls
|
||
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
||
/>
|
||
)
|
||
)}
|
||
</div>
|
||
</Card>
|
||
</Col>
|
||
|
||
{/* 结果图/视频 */}
|
||
<Col span={8}>
|
||
<Card size="small" title="结果图 / 视频" style={{ height: 480 }}>
|
||
|
||
<div style={{ height: 400, display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#fafafa' }}>
|
||
{hasResult ? (
|
||
detectForm.inputType === 'image' ? (
|
||
<img
|
||
src={"http://47.100.102.7:10101" + detectResult.files[0]?.annotatedUrl || ''}
|
||
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
||
alt="result"
|
||
/>
|
||
) : (
|
||
<video
|
||
src={"http://47.100.102.7:10101" + detectResult.files[0]?.annotatedUrl || ''}
|
||
controls
|
||
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
||
/>
|
||
)
|
||
) : (
|
||
<Text type="secondary">任务完成后显示结果</Text>
|
||
)}
|
||
</div>
|
||
</Card>
|
||
</Col>
|
||
|
||
{/* 结果JSON */}
|
||
<Col span={8}>
|
||
<Card size="small" title="结果 JSON" style={{ height: 480 }}>
|
||
<div style={{ height: 400, overflowY: 'auto', background: '#fafafa', padding: 8 }}>
|
||
{hasResult ? (
|
||
<pre style={{ fontSize: 10, margin: 0 }}>{JSON.stringify(detectResult, null, 2)}</pre>
|
||
) : (
|
||
<Text type="secondary">暂无结果</Text>
|
||
)}
|
||
</div>
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
</Card>
|
||
);
|
||
};
|
||
|
||
// 2. 热成像分割的结果布局(第二张图的样式:两列)
|
||
// 2. 热成像分割的结果布局(第二张图的样式:两列 + 热点交互)
|
||
const renderSegResultLayout = () => {
|
||
const hasResult = !!segResult;
|
||
const inputFile = thermalFile;
|
||
const hotspots = segResult?.hotspots || [];
|
||
const panels = segResult?.panel_overview || [];
|
||
|
||
// 选中的点位详情
|
||
const selectedPoint = selectedHotspot
|
||
? hotspots.find(h => h.hotspot_id === selectedHotspot)
|
||
: null;
|
||
|
||
return (
|
||
<Card
|
||
title={<Text strong style={{ fontSize: 14 }}>结果展示</Text>}
|
||
bordered={false}
|
||
style={{ marginTop: 12, borderRadius: 8 }}
|
||
bodyStyle={{ padding: '12px' }}
|
||
>
|
||
<Text type="secondary" style={{ fontSize: 11, display: 'block', marginBottom: 12 }}>
|
||
原始预览、结果图与完整 JSON 同屏查看
|
||
</Text>
|
||
|
||
{/* 顶部统计卡片 */}
|
||
<div style={{ marginBottom: 16 }}>
|
||
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>热成像交互分析视图</Text>
|
||
<Text type="secondary" style={{ fontSize: 11, marginBottom: 12 }}>点击热点或面板查看温度、块号、GPS 与像素溯源信息</Text>
|
||
<Row gutter={8}>
|
||
<Col span={6}>
|
||
<Card
|
||
size="small"
|
||
bordered={false}
|
||
style={{
|
||
background: '#E8FFEA',
|
||
borderRadius: 8,
|
||
height: '100%'
|
||
}}
|
||
bodyStyle={{ padding: '12px 8px' }}
|
||
>
|
||
<Statistic
|
||
title="热点数量"
|
||
value={segResult?.summary?.panel_hotspot_count || 0}
|
||
titleStyle={{ fontSize: 12, color: '#333', marginBottom: 4 }}
|
||
valueStyle={{ fontSize: 18, fontWeight: 600, color: '#00B42A' }}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
|
||
<Col span={6}>
|
||
<Card
|
||
size="small"
|
||
bordered={false}
|
||
style={{
|
||
background: '#E6F4FF',
|
||
borderRadius: 8,
|
||
height: '100%'
|
||
}}
|
||
bodyStyle={{ padding: '12px 8px' }}
|
||
>
|
||
<Statistic
|
||
title="面板区域"
|
||
value={segResult?.summary?.panel_polygon_count || 0}
|
||
titleStyle={{ fontSize: 12, color: '#333', marginBottom: 4 }}
|
||
valueStyle={{ fontSize: 18, fontWeight: 600, color: '#1677FF' }}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
|
||
<Col span={6}>
|
||
<Card
|
||
size="small"
|
||
bordered={false}
|
||
style={{
|
||
background: '#FFF7E8',
|
||
borderRadius: 8,
|
||
height: '100%'
|
||
}}
|
||
bodyStyle={{ padding: '12px 8px' }}
|
||
>
|
||
<Statistic
|
||
title="最高温度"
|
||
value={hasResult ? `${segResult.summary?.max_temp_c || 0}℃` : '-'}
|
||
titleStyle={{ fontSize: 12, color: '#333', marginBottom: 4 }}
|
||
valueStyle={{ fontSize: 18, fontWeight: 600, color: '#FF7D00' }}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
|
||
<Col span={6}>
|
||
<Card
|
||
size="small"
|
||
bordered={false}
|
||
style={{
|
||
background: '#F3E8FF',
|
||
borderRadius: 8,
|
||
height: '100%'
|
||
}}
|
||
bodyStyle={{ padding: '12px 8px' }}
|
||
>
|
||
<Statistic
|
||
title="分析编号"
|
||
value={segResult?.analysis_id?.substring(0, 8) || '-'}
|
||
titleStyle={{ fontSize: 12, color: '#333', marginBottom: 4 }}
|
||
valueStyle={{ fontSize: 18, fontWeight: 600, color: '#722ED1' }}
|
||
/>
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
</div>
|
||
|
||
<Row gutter={12}>
|
||
{/* 左侧:结果图 + 热点标记 */}
|
||
<Col span={12}>
|
||
<div
|
||
style={{
|
||
background: '#001529',
|
||
borderRadius: 8,
|
||
height: 400,
|
||
display: 'flex',
|
||
alignItems: 'center',
|
||
justifyContent: 'center',
|
||
overflow: 'hidden',
|
||
position: 'relative'
|
||
}}
|
||
>
|
||
{/*{inputFile && (
|
||
<img
|
||
src={hasResult
|
||
? "http://47.100.102.7:10101" + segResult.image?.overlay_image_url
|
||
: URL.createObjectURL(inputFile.originFileObj)
|
||
}
|
||
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
||
alt="thermal"
|
||
/>
|
||
)}*/}
|
||
{!inputFile && (
|
||
<Empty description={<span style={{ color: '#fff' }}>请上传热成像文件</span>} image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||
)}
|
||
|
||
{/* 热点标记点 */}
|
||
{hasResult && hotspots.map(hotspot => {
|
||
// 计算图片缩放比例,把原始坐标转为百分比位置
|
||
const scaleX = 100 / (segResult.image?.source_width || 4000);
|
||
const scaleY = 100 / (segResult.image?.source_height || 3000);
|
||
const left = hotspot.peak_x * scaleX;
|
||
const top = hotspot.peak_y * scaleY;
|
||
|
||
const isSelected = selectedHotspot === hotspot.hotspot_id;
|
||
|
||
return (
|
||
<div
|
||
key={hotspot.hotspot_id}
|
||
onClick={() => setSelectedHotspot(hotspot.hotspot_id)}
|
||
style={{
|
||
position: 'absolute',
|
||
left: `${left}%`,
|
||
top: `${top}%`,
|
||
transform: 'translate(-50%, -50%)',
|
||
width: isSelected ? 36 : 28,
|
||
height: isSelected ? 36 : 28,
|
||
borderRadius: '50%',
|
||
background: isSelected ? '#ff4d4f' : '#fa8c16',
|
||
color: '#fff',
|
||
display: 'flex',
|
||
alignItems: 'center',
|
||
justifyContent: 'center',
|
||
fontSize: 12,
|
||
fontWeight: 'bold',
|
||
cursor: 'pointer',
|
||
boxShadow: isSelected ? '0 0 0 4px rgba(255,77,79,0.4)' : '0 2px 8px rgba(0,0,0,0.3)',
|
||
border: '2px solid white',
|
||
transition: 'all 0.2s'
|
||
}}
|
||
>
|
||
{hotspot.hotspot_id}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</Col>
|
||
|
||
{/* 右侧:点位详情 + 列表 */}
|
||
<Col span={12}>
|
||
<Card
|
||
size="small"
|
||
title="点位详情"
|
||
extra={<Text type="secondary" style={{ fontSize: 11 }}>请选择热点或面板</Text>}
|
||
style={{ height: 400 }}
|
||
bodyStyle={{ height: 350 }}
|
||
>
|
||
{/* 总容器:垂直布局,占满卡片内容区 */}
|
||
<div style={{
|
||
width: '100%',
|
||
height: '100%',
|
||
display: 'flex',
|
||
flexDirection: 'column',
|
||
boxSizing: 'border-box',
|
||
paddingBottom: 8
|
||
}}>
|
||
|
||
{/* --------------- 上半部分:点位详情 50% --------------- */}
|
||
<div style={{
|
||
flex: 1,
|
||
minHeight: 0,
|
||
overflowY: 'auto',
|
||
paddingRight: 4,
|
||
boxSizing: 'border-box',
|
||
height: "50%"
|
||
}}>
|
||
{selectedPoint ? (
|
||
<div>
|
||
<div style={{ marginBottom: 16 }}>
|
||
<Space>
|
||
<Text strong style={{ fontSize: 14 }}>热点 {selectedPoint.hotspot_id}</Text>
|
||
<Tag color="red">热点</Tag>
|
||
</Space>
|
||
</div>
|
||
|
||
{[
|
||
{ label: '温度', value: `${selectedPoint.peak_temp_c}℃` },
|
||
{ label: '块号', value: selectedPoint.panel_id || '-' },
|
||
{ label: 'GPS', value: selectedPoint.gps?.text || '-' },
|
||
{ label: '原图像素', value: `${selectedPoint.peak_x}, ${selectedPoint.peak_y}` },
|
||
{ label: '叠加图像素', value: `${selectedPoint.peak_x}, ${selectedPoint.peak_y}` },
|
||
{ label: '面积', value: `${selectedPoint.area_px} px` }
|
||
].map((item, i) => (
|
||
<div key={i} style={{
|
||
display: 'flex',
|
||
justifyContent: 'space-between',
|
||
padding: '8px 0',
|
||
borderBottom: '1px dashed #eee'
|
||
}}>
|
||
<Text type="secondary">{item.label}</Text>
|
||
<Text>{item.value}</Text>
|
||
</div>
|
||
))}
|
||
</div>
|
||
) : (
|
||
<Text type="secondary" style={{ fontSize: 12, display: 'block' }}>
|
||
等待分割结果,完成后可点击热点/面板查看详情
|
||
</Text>
|
||
)}
|
||
</div>
|
||
|
||
{/* 分割线 */}
|
||
<div style={{
|
||
height: 1,
|
||
background: '#eee',
|
||
margin: '12px 0',
|
||
flexShrink: 0
|
||
}} />
|
||
|
||
{/* --------------- 下半部分:热点/面板列表 50% --------------- */}
|
||
<div style={{
|
||
flex: 1,
|
||
minHeight: 0,
|
||
overflowY: 'auto',
|
||
paddingRight: 4,
|
||
boxSizing: 'border-box'
|
||
}}>
|
||
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>热点/面板列表</Text>
|
||
{panels.map((p, i) => (
|
||
<div
|
||
key={i}
|
||
onClick={() => {
|
||
const matchHotspot = hotspots.find(h => h.hotspot_id === i + 1);
|
||
if (matchHotspot) setSelectedHotspot(matchHotspot.hotspot_id);
|
||
}}
|
||
style={{
|
||
display: 'flex',
|
||
justifyContent: 'space-between',
|
||
padding: '8px 12px',
|
||
borderRadius: 4,
|
||
marginBottom: 4,
|
||
background: selectedHotspot === i + 1 ? '#e6f4ff' : '#fafafa',
|
||
cursor: 'pointer',
|
||
fontSize: 12
|
||
}}
|
||
>
|
||
<span>{p.label || `面板 #${i + 1}`}</span>
|
||
<span style={{ color: '#ff4d4f' }}>{p.peak_temp_c}℃</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
</div>
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
</Card>
|
||
);
|
||
};
|
||
// 主渲染结果方法:根据算法选择不同布局
|
||
const renderResults = () => {
|
||
if (activeAlgo === 'detect') {
|
||
return renderDetectResultLayout();
|
||
} else {
|
||
return renderSegResultLayout();
|
||
}
|
||
};
|
||
|
||
return (
|
||
<div style={{ padding: '8px', background: '#f4f7f9', minHeight: '100vh' }}>
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', paddingBottom: "16px" }}>
|
||
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(18px, 1.5vw, 24px)', color: '#1D2129' }}>
|
||
算法分析中心
|
||
</Typography.Title>
|
||
</div>
|
||
{renderStats()}
|
||
|
||
<Row gutter={12} style={{ flexWrap: 'wrap' }}>
|
||
{/* 左侧:算法列表 */}
|
||
<Col xs={24} sm={12} md={12} lg={4}>
|
||
<Card
|
||
title={<Text strong style={{ fontSize: 14 }}>算法列表</Text>}
|
||
bordered={false}
|
||
bodyStyle={{ padding: '8px' }}
|
||
style={{ borderRadius: 8, height: '100%' }}
|
||
extra={<Text type="secondary" style={{ fontSize: 11 }}>已接入 2 套</Text>}
|
||
>
|
||
{algorithmList.map(algo => (
|
||
<div
|
||
key={algo.id}
|
||
onClick={() => setActiveAlgo(algo.id)}
|
||
style={{
|
||
padding: '12px',
|
||
borderRadius: 8,
|
||
cursor: 'pointer',
|
||
marginBottom: 8,
|
||
border: `1px solid ${activeAlgo === algo.id ? '#1677ff' : '#f0f0f0'}`,
|
||
background: activeAlgo === algo.id ? '#e6f4ff' : '#fff',
|
||
transition: 'all 0.3s'
|
||
}}
|
||
>
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
|
||
<Space>
|
||
<span style={{ color: activeAlgo === algo.id ? '#1677ff' : '#666', fontSize: 16 }}>{algo.icon}</span>
|
||
<Text strong style={{ color: activeAlgo === algo.id ? '#1677ff' : '#333' }}>{algo.name}</Text>
|
||
</Space>
|
||
<Tag color="blue" size="small" style={{ margin: 0, fontSize: 10 }}>{algo.status}</Tag>
|
||
</div>
|
||
<div style={{ fontSize: 11, color: '#999', marginBottom: 4 }}>{algo.alias}</div>
|
||
<div style={{ fontSize: 11, color: '#999' }}>{algo.desc}</div>
|
||
</div>
|
||
))}
|
||
</Card>
|
||
</Col>
|
||
|
||
{/* 中间:工作区 */}
|
||
<Col xs={24} sm={24} md={12} lg={14}>
|
||
<Card
|
||
title={
|
||
<Space>
|
||
<Text strong style={{ fontSize: 14 }}>
|
||
{activeAlgo === 'detect' ? '检测任务工作区' : '热成像分割工作区'}
|
||
</Text>
|
||
<Tag color="blue" size="small">
|
||
{activeAlgo === 'detect' ? '异步任务' : '同步分析'}
|
||
</Tag>
|
||
</Space>
|
||
}
|
||
bordered={false}
|
||
bodyStyle={{ padding: '16px' }}
|
||
style={{ borderRadius: 8 }}
|
||
>
|
||
<Text type="secondary" style={{ fontSize: 11, display: 'block', marginBottom: 16 }}>
|
||
{activeAlgo === 'detect'
|
||
? '提交图片或视频检测任务,轮询状态并查看检测结果图。'
|
||
: '上传热成像图与可选 mask/geojson,同步返回叠加图和热点 JSON。'}
|
||
</Text>
|
||
|
||
{activeAlgo === 'detect' ? renderDetectWorkspace() : renderSegWorkspace()}
|
||
</Card>
|
||
|
||
{renderResults()}
|
||
</Col>
|
||
|
||
{/* 右侧:历史记录 */}
|
||
<Col xs={24} sm={12} md={12} lg={6}>
|
||
<Card
|
||
title={<Text strong style={{ fontSize: 14 }}>历史分析记录</Text>}
|
||
bordered={false}
|
||
bodyStyle={{ padding: '8px' }}
|
||
style={{ borderRadius: 8, height: '100%' }}
|
||
extra={<Text type="secondary" style={{ fontSize: 11 }}>{history.length} 条</Text>}
|
||
>
|
||
{history.length === 0 ? (
|
||
<Empty description="暂无历史" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||
) : (
|
||
history.map(item => (
|
||
<div
|
||
key={item.id}
|
||
style={{
|
||
padding: '10px',
|
||
borderRadius: 6,
|
||
border: '1px solid #f0f0f0',
|
||
marginBottom: 8,
|
||
fontSize: 12
|
||
}}
|
||
>
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4 }}>
|
||
<Text strong>{item.name}</Text>
|
||
<Tag size="small" color={item.type === 'detect' ? 'cyan' : 'purple'}>
|
||
{item.type === 'detect' ? '检测' : '分割'}
|
||
</Tag>
|
||
</div>
|
||
<div style={{ color: '#999', fontSize: 11, marginBottom: 4 }}>ID: {item.id.substring(0, 12)}...</div>
|
||
<div style={{ color: '#ccc', fontSize: 10 }}>{item.time}</div>
|
||
</div>
|
||
))
|
||
)}
|
||
</Card>
|
||
</Col>
|
||
</Row>
|
||
</div>
|
||
);
|
||
}
|