Browse Source

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

master
qinjian 2 months ago
parent
commit
26d5d22013
  1. 15
      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

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

@ -285,15 +285,14 @@ const CameraView = ({
const videoRect = screenToVideoCoordinates(x, y, w, h);
if (videoRect && rectangles.length < maxRectangles) {
// 4idkey
const ts = Date.now().toString();
const shortId = ts.slice(-4);
const nextIndex = Number(rectangles[rectangles.length - 1]?.id) ? Number(rectangles[rectangles.length - 1]?.id)-100+1 : 1;
const fixedId = `10${nextIndex}`;
//
const templateParams = selectedTemplate
? {
//
name:
`target${rectangles.length + 1}` || selectedTemplate.name,
name: `target${nextIndex}` || selectedTemplate.name,
radius: selectedTemplate.physicalRadius || 40.0,
isReferencePoint: selectedTemplate.isBaseline || false,
gradientThreshold:
@ -305,7 +304,7 @@ const CameraView = ({
}
: {
//
name: `target${rectangles.length + 1}`,
name: `target${nextIndex}`,
radius: 40.0,
isReferencePoint: false,
gradientThreshold: 100,
@ -316,8 +315,8 @@ const CameraView = ({
};
const newRect = {
id: shortId,
key: shortId,
id: fixedId,
key: fixedId,
...videoRect,
...templateParams,
//

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save