import React from "react"; import { Form, Input, Select, Button, Space, Divider, Card, Checkbox, Typography, Image, } from "antd"; import { PlusOutlined, MinusCircleOutlined } from "@ant-design/icons"; import TagSelector from "../Template/components/TagSelector"; const { Option } = Select; const { TextArea } = Input; const { Text } = Typography; interface TemplateConfigurationFormProps { form: any; } const TemplateConfigurationForm: React.FC = ({ form, }) => { const needsOptions = (type: string) => { return ["Choices", "RectangleLabels", "PolygonLabels", "Labels"].includes( type ); }; /** 判断对象类型是否为文本类 */ const isTextType = (type: string) => { return ["Text", "HyperText", "Table", "List"].includes(type); }; /** 判断对象类型是否为图片类 */ const isImageType = (type: string) => { return ["Image"].includes(type); }; /** 获取示例数据输入提示 */ const getExamplePlaceholder = (type: string) => { const map: Record = { Text: "输入示例文本内容...", HyperText: "输入示例 HTML 内容...", Image: "输入图片 URL,如 https://example.com/image.jpg", Audio: "输入音频 URL,如 https://example.com/audio.mp3", Video: "输入视频 URL,如 https://example.com/video.mp4", Table: "输入示例表格数据(JSON 格式)...", List: "输入示例列表数据(JSON 格式)...", TimeSeries: "输入时间序列数据 URL...", }; return map[type] || "输入示例数据..."; }; return ( <> 数据对象 {(fields, { add, remove }) => ( <> {fields.map((field) => ( {fields.length > 1 && ( remove(field.name)} /> )} ))} )} 标签控件 {(fields, { add, remove }) => ( <> {fields.map((field) => ( 控件 {fields.indexOf(field) + 1} {() => { const controlType = form.getFieldValue([ "labels", field.name, "type", ]); const fromName = form.getFieldValue([ "labels", field.name, "fromName", ]); if (controlType || fromName) { return ( ({fromName || "未命名"} -{" "} {controlType || "未设置类型"}) ); } return null; }} } extra={ remove(field.name)} /> } > {/* Row 1: 控件名称, 标注目标对象, 控件类型 */}
必填
{/* Row 2: 取值范围定义(添加选项) - Conditionally rendered based on type */} { const prevType = prevValues.labels?.[field.name]?.type; const currType = currentValues.labels?.[field.name]?.type; return prevType !== currType; }} > {({ getFieldValue }) => { const controlType = getFieldValue([ "labels", field.name, "type", ]); const fieldName = controlType === "Choices" ? "options" : "labels"; if (needsOptions(controlType)) { return (
))} )}
示例数据(可选) 为数据对象提供示例数据,帮助用户在模板预览时直观了解标注效果 prev.objects !== curr.objects}> {({ getFieldValue }) => { const objects = getFieldValue("objects") || []; if (objects.length === 0) { return ( 请先添加数据对象 ); } return ( {objects.map((obj: any, index: number) => { if (!obj?.name) return null; const varName = obj.value?.replace(/^\$/, "") || obj.name; const objType = obj.type || "Text"; return (
{obj.name} ({objType})
{isTextType(objType) ? (