- 统一说明文案层级:Typography.Paragraph 次要文案迁移到 admin-section-description - 状态色补齐边框与中间调令牌,Alert/错误条/Descriptions 与 StatusTag 同源 - 咨询详情描述列表去表格线,改为键值展示并统一令牌 - 新增 BrandMark,侧栏与登录页标识改用品牌首字 - 信任内容改用列表行,空状态、表格骨架屏、主按钮脏检查落地 - design.md 同步令牌映射、切换控件选型与组件清单
140 lines
5.1 KiB
TypeScript
140 lines
5.1 KiB
TypeScript
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 (
|
|
<Form.Item label={field.label} help={field.help}>
|
|
<Form.List
|
|
name={name}
|
|
rules={[
|
|
{
|
|
validator: (_rule, values: unknown) =>
|
|
field.required && (!Array.isArray(values) || values.length === 0)
|
|
? Promise.reject(new Error(`请至少填写一项${field.label}`))
|
|
: Promise.resolve(),
|
|
},
|
|
]}
|
|
>
|
|
{(rows, { add, remove, move }, { errors }) => (
|
|
<div className="admin-stack admin-stack-tight">
|
|
{rows.length === 0 ? <EmptyState compact title={`还没有${field.label}内容`} /> : null}
|
|
{rows.map((row, index) => {
|
|
const titleField = field.itemFields?.[0];
|
|
const primaryTitle = titleField ? (
|
|
<Form.Item
|
|
noStyle
|
|
shouldUpdate={(prev: unknown, next: unknown) => {
|
|
const previous = Array.isArray(prev)
|
|
? (prev[row.name] as Record<string, unknown> | undefined)
|
|
: undefined;
|
|
const nextRow = Array.isArray(next)
|
|
? (next[row.name] as Record<string, unknown> | undefined)
|
|
: undefined;
|
|
return previous?.[titleField.key] !== nextRow?.[titleField.key];
|
|
}}
|
|
>
|
|
{({ getFieldValue }) => {
|
|
const value = String(
|
|
getFieldValue([...name, row.name, titleField.key] as const) ?? "",
|
|
);
|
|
return (
|
|
<Typography.Text
|
|
strong
|
|
>{`${index + 1}. ${value || titleField.label}`}</Typography.Text>
|
|
);
|
|
}}
|
|
</Form.Item>
|
|
) : (
|
|
<Typography.Text strong>{`${index + 1}. ${field.label}`}</Typography.Text>
|
|
);
|
|
return (
|
|
<Card
|
|
key={row.key}
|
|
size="small"
|
|
title={primaryTitle}
|
|
extra={
|
|
<Space size={0}>
|
|
<Button
|
|
type="text"
|
|
size="small"
|
|
aria-label={`上移第 ${index + 1} 项`}
|
|
icon={<CaretUpOutlined />}
|
|
disabled={index === 0}
|
|
onClick={() => move(index, index - 1)}
|
|
/>
|
|
<Button
|
|
type="text"
|
|
size="small"
|
|
aria-label={`下移第 ${index + 1} 项`}
|
|
icon={<CaretDownOutlined />}
|
|
disabled={index === rows.length - 1}
|
|
onClick={() => move(index, index + 1)}
|
|
/>
|
|
<Button
|
|
type="text"
|
|
danger
|
|
size="small"
|
|
aria-label={`删除第 ${index + 1} 项`}
|
|
icon={<DeleteOutlined />}
|
|
onClick={() => remove(row.name)}
|
|
/>
|
|
</Space>
|
|
}
|
|
>
|
|
{field.itemFields?.map((itemField) => (
|
|
<Form.Item
|
|
key={itemField.key}
|
|
name={[row.name, itemField.key]}
|
|
label={itemField.label}
|
|
rules={
|
|
itemField.required === false
|
|
? []
|
|
: [{ required: true, message: `请填写${itemField.label}` }]
|
|
}
|
|
>
|
|
{itemField.input === "textarea" ? <Input.TextArea rows={2} /> : <Input />}
|
|
</Form.Item>
|
|
))}
|
|
</Card>
|
|
);
|
|
})}
|
|
{rows.length > 1 ? (
|
|
<Collapse
|
|
ghost
|
|
items={[
|
|
{
|
|
key: "sort-help",
|
|
label: "排序说明",
|
|
children: (
|
|
<Typography.Text type="secondary">
|
|
使用每张卡片右上角的箭头调整顺序,保存后预览也会按当前顺序展示。
|
|
</Typography.Text>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
) : null}
|
|
<Form.ErrorList errors={errors} />
|
|
<Button block icon={<PlusOutlined />} onClick={() => add()}>
|
|
新增{field.label}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</Form.List>
|
|
</Form.Item>
|
|
);
|
|
}
|