import { Button, Card, Collapse, Form, Input, Space, Typography } from "antd";
import {
CaretDownOutlined,
CaretUpOutlined,
DeleteOutlined,
PlusOutlined,
} from "@ant-design/icons";
import type { TemplateAdminField } from "@personal-brand/api-client";
import { EmptyState } from "./EmptyState.js";
export function TemplateListField({
field,
name,
}: {
field: TemplateAdminField;
name: string | (string | number)[];
}) {
return (
field.required && (!Array.isArray(values) || values.length === 0)
? Promise.reject(new Error(`请至少填写一项${field.label}`))
: Promise.resolve(),
},
]}
>
{(rows, { add, remove, move }, { errors }) => (
{rows.length === 0 ? : null}
{rows.map((row, index) => {
const titleField = field.itemFields?.[0];
const primaryTitle = titleField ? (
{
const previous = Array.isArray(prev)
? (prev[row.name] as Record | undefined)
: undefined;
const nextRow = Array.isArray(next)
? (next[row.name] as Record | undefined)
: undefined;
return previous?.[titleField.key] !== nextRow?.[titleField.key];
}}
>
{({ getFieldValue }) => {
const value = String(
getFieldValue([...name, row.name, titleField.key] as const) ?? "",
);
return (
{`${index + 1}. ${value || titleField.label}`}
);
}}
) : (
{`${index + 1}. ${field.label}`}
);
return (
}
disabled={index === 0}
onClick={() => move(index, index - 1)}
/>
}
disabled={index === rows.length - 1}
onClick={() => move(index, index + 1)}
/>
}
onClick={() => remove(row.name)}
/>
}
>
{field.itemFields?.map((itemField) => (
{itemField.input === "textarea" ? : }
))}
);
})}
{rows.length > 1 ? (
使用每张卡片右上角的箭头调整顺序,保存后预览也会按当前顺序展示。
),
},
]}
/>
) : null}
} onClick={() => add()}>
新增{field.label}
)}
);
}