Browse Source

fix: 修复标靶数量上限提示逻辑,优化标靶ID生成方式,更新模板名称为“标靶模板1”,并添加输入验证规则

master
qinjian 2 months ago
parent
commit
26d5d22013
  1. 17
      client/src/sections/wuyuanbiaoba/components/CameraView.jsx
  2. 1
      client/src/sections/wuyuanbiaoba/components/TargetDetailModal.jsx
  3. 1
      client/src/sections/wuyuanbiaoba/components/TargetList.jsx
  4. 23
      client/src/sections/wuyuanbiaoba/components/TemplateModal.jsx
  5. 6
      client/src/sections/wuyuanbiaoba/hooks/useTargetStorage.js
  6. 4
      client/src/sections/wuyuanbiaoba/hooks/useTemplateStorage.js

17
client/src/sections/wuyuanbiaoba/components/CameraView.jsx

@ -167,7 +167,7 @@ const CameraView = ({
setStartPos({ x: mouseX, y: mouseY }); setStartPos({ x: mouseX, y: mouseY });
setDrawing(true); setDrawing(true);
setCurrentDrawingRect(null); setCurrentDrawingRect(null);
}else{ } else {
message.warning("已达到标靶数量上限(5个)!"); message.warning("已达到标靶数量上限(5个)!");
} }
} }
@ -285,15 +285,14 @@ const CameraView = ({
const videoRect = screenToVideoCoordinates(x, y, w, h); const videoRect = screenToVideoCoordinates(x, y, w, h);
if (videoRect && rectangles.length < maxRectangles) { if (videoRect && rectangles.length < maxRectangles) {
// 4idkey const nextIndex = Number(rectangles[rectangles.length - 1]?.id) ? Number(rectangles[rectangles.length - 1]?.id)-100+1 : 1;
const ts = Date.now().toString(); const fixedId = `10${nextIndex}`;
const shortId = ts.slice(-4);
// //
const templateParams = selectedTemplate const templateParams = selectedTemplate
? { ? {
// //
name: name: `target${nextIndex}` || selectedTemplate.name,
`target${rectangles.length + 1}` || selectedTemplate.name,
radius: selectedTemplate.physicalRadius || 40.0, radius: selectedTemplate.physicalRadius || 40.0,
isReferencePoint: selectedTemplate.isBaseline || false, isReferencePoint: selectedTemplate.isBaseline || false,
gradientThreshold: gradientThreshold:
@ -305,7 +304,7 @@ const CameraView = ({
} }
: { : {
// //
name: `target${rectangles.length + 1}`, name: `target${nextIndex}`,
radius: 40.0, radius: 40.0,
isReferencePoint: false, isReferencePoint: false,
gradientThreshold: 100, gradientThreshold: 100,
@ -316,8 +315,8 @@ const CameraView = ({
}; };
const newRect = { const newRect = {
id: shortId, id: fixedId,
key: shortId, key: fixedId,
...videoRect, ...videoRect,
...templateParams, ...templateParams,
// //

1
client/src/sections/wuyuanbiaoba/components/TargetDetailModal.jsx

@ -138,6 +138,7 @@ const TargetDetailModal = ({
rules={[ rules={[
{ required: true, message: "请输入标靶描述" }, { required: true, message: "请输入标靶描述" },
{ max: 50, message: "标靶描述不能超过50个字符" }, { max: 50, message: "标靶描述不能超过50个字符" },
{ pattern: /^[^\u4e00-\u9fa5]+$/, message: "仅支持英文、数字及符号" },
]} ]}
> >
<Input placeholder="请输入标靶描述" /> <Input placeholder="请输入标靶描述" />

1
client/src/sections/wuyuanbiaoba/components/TargetList.jsx

@ -9,6 +9,7 @@ const TargetList = ({
onSelectTarget, onSelectTarget,
onClickClearAll, onClickClearAll,
}) => { }) => {
const targetColumns = [ const targetColumns = [
{ {
title: "标靶操作", title: "标靶操作",

23
client/src/sections/wuyuanbiaoba/components/TemplateModal.jsx

@ -49,9 +49,8 @@ const TemplateModal = ({
name: templateData.name, name: templateData.name,
gaussianBlur: templateData.gaussianBlur || 1, gaussianBlur: templateData.gaussianBlur || 1,
physicalRadius: templateData.physicalRadius || 40.0, physicalRadius: templateData.physicalRadius || 40.0,
gradientThresholdValue: gradientThresholdValue: templateData.gradientThresholdValue,
templateData.gradientThresholdValue || 100, anchorThresholdValue: templateData.anchorThresholdValue,
anchorThresholdValue: templateData.anchorThresholdValue || 80,
}); });
setIsBaseline(templateData.isBaseline || false); setIsBaseline(templateData.isBaseline || false);
setIsPerspectiveCorrection( setIsPerspectiveCorrection(
@ -60,10 +59,8 @@ const TemplateModal = ({
setBinaryThreshold(templateData.binaryThreshold || 100); setBinaryThreshold(templateData.binaryThreshold || 100);
setGaussianBlur(templateData.gaussianBlur || 1); setGaussianBlur(templateData.gaussianBlur || 1);
setPhysicalRadius(templateData.physicalRadius || 40.0); setPhysicalRadius(templateData.physicalRadius || 40.0);
setGradientThresholdValue( setGradientThresholdValue(templateData.gradientThresholdValue);
templateData.gradientThresholdValue || 100 setAnchorThresholdValue(templateData.anchorThresholdValue);
);
setAnchorThresholdValue(templateData.anchorThresholdValue || 80);
// //
if (templateData.imageUrl) { if (templateData.imageUrl) {
@ -161,6 +158,7 @@ const TemplateModal = ({
const handleOk = async () => { const handleOk = async () => {
try { try {
debugger;
const values = await form.validateFields(); const values = await form.validateFields();
// //
@ -201,7 +199,7 @@ const TemplateModal = ({
const handleDelete = () => { const handleDelete = () => {
if (templateData) { if (templateData) {
// //
if (templateData.key === 'builtin_1') { if (templateData.key === "builtin_1") {
message.warning("该模板为内置模板,不允许删除!"); message.warning("该模板为内置模板,不允许删除!");
return; return;
} }
@ -220,7 +218,7 @@ const TemplateModal = ({
onCancel={onCancel} onCancel={onCancel}
width={500} width={500}
footer={[ footer={[
mode === "edit" && templateData?.key !== 'builtin_1' && ( mode === "edit" && templateData?.key !== "builtin_1" && (
<Popconfirm <Popconfirm
key="delete" key="delete"
title={`确认删除标靶模板[${templateData?.name}]?`} title={`确认删除标靶模板[${templateData?.name}]?`}
@ -262,7 +260,12 @@ const TemplateModal = ({
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label="标靶图片" label={
<>
标靶图片
<span style={{ color: "red", marginLeft: 4 }}>*</span>
</>
}
rules={[{ required: true, message: "请上传标靶图片" }]} rules={[{ required: true, message: "请上传标靶图片" }]}
> >
<Upload <Upload

6
client/src/sections/wuyuanbiaoba/hooks/useTargetStorage.js

@ -81,8 +81,8 @@ export const useTargetStorage = () => {
const threshold = info.threshold || {}; const threshold = info.threshold || {};
return { return {
key: info.id !== undefined ? info.id.toString() : targetKey, key: info.id,
id: info.id !== undefined ? info.id.toString() : targetKey, id: info.id,
name: info.desc || `目标${targetKey}`, name: info.desc || `目标${targetKey}`,
radius: info.radius || 40.0, radius: info.radius || 40.0,
isReferencePoint: info.base || false, isReferencePoint: info.base || false,
@ -97,7 +97,7 @@ export const useTargetStorage = () => {
perspective: targetInfo.perspective || null, perspective: targetInfo.perspective || null,
handlerInfo: targetInfo.handler_info || null, handlerInfo: targetInfo.handler_info || null,
}; };
}); }).sort((a, b) => Number(a.id) - Number(b.id)); // 按id数字升序排序;
setTargets(formattedTargets); setTargets(formattedTargets);
setError(null); setError(null);

4
client/src/sections/wuyuanbiaoba/hooks/useTemplateStorage.js

@ -43,7 +43,7 @@ const createBuiltinTemplate = async () => {
return { return {
key: 'builtin_1', key: 'builtin_1',
name: 'template1', name: '标靶模板1',
isBaseline: false, isBaseline: false,
isPerspectiveCorrection: false, isPerspectiveCorrection: false,
binaryThreshold: 100, binaryThreshold: 100,
@ -59,7 +59,7 @@ const createBuiltinTemplate = async () => {
// 如果图片加载失败,返回不带图片的内置模板 // 如果图片加载失败,返回不带图片的内置模板
return { return {
key: 'builtin_1', key: 'builtin_1',
name: '模板1', name: '标靶模板1',
isBaseline: false, isBaseline: false,
isPerspectiveCorrection: false, isPerspectiveCorrection: false,
binaryThreshold: 100, binaryThreshold: 100,

Loading…
Cancel
Save