算法分析界面完成

This commit is contained in:
mmc
2026-05-21 14:50:28 +08:00
parent eee617ca83
commit 7cb9148aaa
2 changed files with 378 additions and 106 deletions

View File

@@ -1,15 +1,15 @@
import request from '../request';
// 检测服务 Base URL
const DETECT_BASE = 'http://50.50.50.117:10101';
const DETECT_BASE = 'http://47.100.102.7:10101';
// 热成像分割服务 Base URL
const SEGMENT_BASE = 'http://50.50.50.117:10102';
const SEGMENT_BASE = 'http://47.100.102.7:10102';
/**
* 获取检测模型列表
*/
export function getDetectModels() {
return fetch(`${DETECT_BASE}/api/v1/detect/models`).then(res => res.json());
return fetch(`${DETECT_BASE}/api/v1/detect/models`).then(res => res.json());
}
/**
@@ -17,24 +17,24 @@ export function getDetectModels() {
* @param formData 包含 files, inputType, modelAlias, conf, iou, imgsz, device, maxDet, vidStride
*/
export function submitDetectJob(formData: FormData) {
return fetch(`${DETECT_BASE}/api/v1/detect/jobs`, {
method: 'POST',
body: formData
}).then(res => res.json());
return fetch(`${DETECT_BASE}/api/v1/detect/jobs`, {
method: 'POST',
body: formData
}).then(res => res.json());
}
/**
* 查询检测任务状态
*/
export function getDetectJobStatus(jobId: string) {
return fetch(`${DETECT_BASE}/api/v1/detect/jobs/${jobId}`).then(res => res.json());
return fetch(`${DETECT_BASE}/api/v1/detect/jobs/${jobId}`).then(res => res.json());
}
/**
* 查询检测结果
*/
export function getDetectJobResult(jobId: string) {
return fetch(`${DETECT_BASE}/api/v1/detect/jobs/${jobId}/result`).then(res => res.json());
return fetch(`${DETECT_BASE}/api/v1/detect/jobs/${jobId}/result`).then(res => res.json());
}
/**
@@ -42,15 +42,15 @@ export function getDetectJobResult(jobId: string) {
* @param formData 包含 thermal_file, array_mask_file, panel_geojson_file, threshold_c, min_area_px, max_regions, open_k, close_k, shrink_in, include_panel_segments
*/
export function submitSegmentationAnalyze(formData: FormData) {
return fetch(`${SEGMENT_BASE}/api/v1/segmentation/analyze`, {
method: 'POST',
body: formData
}).then(res => res.json());
return fetch(`${SEGMENT_BASE}/api/v1/segmentation/analyze`, {
method: 'POST',
body: formData
}).then(res => res.json());
}
/**
* 获取热成像分析报告历史
*/
export function getSegmentationHistory() {
return fetch(`${SEGMENT_BASE}/api/v1/segmentation/analyses/report`).then(res => res.json());
return fetch(`${SEGMENT_BASE}/api/v1/segmentation/analyses/report`).then(res => res.json());
}

View File

@@ -66,6 +66,8 @@ export default function Agri() {
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);
@@ -119,6 +121,7 @@ export default function Agri() {
const formData = new FormData();
detectFiles.forEach(file => {
console.log(file, "dsdsvc")
formData.append('files', file.originFileObj);
});
formData.append('inputType', detectForm.inputType);
@@ -440,10 +443,12 @@ export default function Agri() {
<div style={{ marginTop: 24 }}>
<Dragger
multiple={detectForm.inputType === 'image'}
fileList={detectFiles}
onChange={info => setDetectFiles(info.fileList)}
onChange={info => {
setDetectFiles(info.fileList.slice(-1));
}}
beforeUpload={() => false}
limit={1}
style={{ background: '#fafafa', borderRadius: 8 }}
>
<p className="ant-upload-drag-icon">
@@ -560,10 +565,100 @@ export default function Agri() {
</div>
);
// 渲染结果展示
const renderResults = () => {
const result = activeAlgo === 'detect' ? detectResult : segResult;
const inputFiles = activeAlgo === 'detect' ? detectFiles : (thermalFile ? [thermalFile] : []);
// 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
@@ -576,104 +671,283 @@ export default function Agri() {
原始预览、结果图与完整 JSON 同屏查看
</Text>
{activeAlgo === 'segmentation' && segResult && (
<div style={{ marginBottom: 16 }}>
<Row gutter={8}>
<Col span={6}>
<Card size="small" bodyStyle={{ padding: 8 }}>
<Statistic title="热点数量" value={segResult.summary?.panel_hotspot_count || 0} valueStyle={{ fontSize: 16 }} />
</Card>
</Col>
<Col span={6}>
<Card size="small" bodyStyle={{ padding: 8 }}>
<Statistic title="面板区域" value={segResult.summary?.panel_polygon_count || 0} valueStyle={{ fontSize: 16 }} />
</Card>
</Col>
<Col span={6}>
<Card size="small" bodyStyle={{ padding: 8 }}>
<Statistic title="最高温度" value="-" valueStyle={{ fontSize: 16 }} />
</Card>
</Col>
<Col span={6}>
<Card size="small" bodyStyle={{ padding: 8 }}>
<Statistic title="分析编号" value={segResult.analysisId?.substring(0, 8) || '-'} valueStyle={{ fontSize: 16 }} />
</Card>
</Col>
</Row>
</div>
)}
{/* 顶部统计卡片 */}
<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={16}>
<div style={{ background: '#001529', borderRadius: 8, height: 450, display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden', position: 'relative' }}>
{result ? (
activeAlgo === 'detect' ? (
detectForm.inputType === 'image' ? (
<img
src={result.files?.[0]?.annotatedUrl}
style={{ maxWidth: '100%', maxHeight: '100%' }}
alt="result"
/>
) : (
<video
src={result.files?.[0]?.annotatedUrl}
controls
style={{ maxWidth: '100%', maxHeight: '100%' }}
/>
)
) : (
<img
src={result.image?.overlay_image_url}
style={{ maxWidth: '100%', maxHeight: '100%' }}
alt="result"
/>
)
) : (
<div style={{ textAlign: 'center', color: '#fff' }}>
<Empty description={<span style={{ color: '#fff' }}>等待上传或调用服务器样例后显示结果图</span>} image={Empty.PRESENTED_IMAGE_SIMPLE} />
</div>
{/* 左侧:结果图 + 热点标记 */}
<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>
<div style={{ textAlign: 'center', marginTop: 8 }}><Text strong style={{ fontSize: 13 }}>分析结果视图</Text></div>
</Col>
<Col span={8}>
<div style={{ background: '#f5f5f5', borderRadius: 8, height: 450, padding: 8, display: 'flex', flexDirection: 'column' }}>
<div style={{ flex: 1, overflowY: 'auto' }}>
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>点位详情</Text>
{activeAlgo === 'segmentation' && segResult ? (
<div>
<div style={{ padding: '8px', background: '#fff', borderRadius: 4, marginBottom: 8 }}>
<div style={{ fontSize: 12, color: '#999' }}>热点 GPS 样例</div>
<div style={{ fontSize: 12 }}>{segResult.hotspots?.[0]?.gps?.text || '暂无 GPS 信息'}</div>
</div>
<Divider style={{ margin: '8px 0' }} />
<Text strong style={{ fontSize: 12 }}>热点/面板列表</Text>
<div style={{ marginTop: 8 }}>
{segResult.panel_overview?.slice(0, 10).map((p, i) => (
<div key={i} style={{ fontSize: 11, padding: '4px 0', borderBottom: '1px solid #eee' }}>
面板 #{i + 1}: {p.gps_text}
{/* 右侧:点位详情 + 列表 */}
<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>
</div>
) : (
<Empty description="请选择热点或面板" image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
) : (
<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>
<Divider style={{ margin: '8px 0' }} />
<div style={{ flex: 1, overflowY: 'auto' }}>
<Text strong style={{ fontSize: 13, display: 'block', marginBottom: 8 }}>结果 JSON</Text>
{result ? (
<pre style={{ fontSize: 10, margin: 0 }}>{JSON.stringify(result, null, 2)}</pre>
) : <Empty description="暂无结果" image={Empty.PRESENTED_IMAGE_SIMPLE} />}
</div>
</div>
<div style={{ textAlign: 'center', marginTop: 8 }}><Text strong style={{ fontSize: 13 }}>详细数据</Text></div>
</Card>
</Col>
</Row>
</Card>
);
};
// 主渲染结果方法:根据算法选择不同布局
const renderResults = () => {
if (activeAlgo === 'detect') {
return renderDetectResultLayout();
} else {
return renderSegResultLayout();
}
};
return (
<div style={{ padding: '8px', background: '#f4f7f9', minHeight: '100vh' }}>
@@ -681,11 +955,9 @@ export default function Agri() {
<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}>