feat: 完善模板字段编辑与分类治理
This commit is contained in:
1 parent
91322fa9a0
commit
26bcb2b66e
23 files changed
+631
-250
No files matched your search
@@ -0,0 +1,96 @@
|
||||
import { Input, InputNumber, Select, Switch } from "antd";
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { ImageUrlField } from "./ImageUrlField.js";
|
||||
|
||||
export function TemplateFieldRenderer({
|
||||
field,
|
||||
id,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
field: TemplateAdminField;
|
||||
id?: string;
|
||||
value?: unknown;
|
||||
onChange?: (value: unknown) => void;
|
||||
}) {
|
||||
if (field.input === "textarea")
|
||||
return (
|
||||
<Input.TextArea
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
rows={3}
|
||||
maxLength={field.maxLength}
|
||||
showCount={!!field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "image")
|
||||
return (
|
||||
<ImageUrlField
|
||||
{...(id ? { id } : {})}
|
||||
{...(field.placeholder ? { placeholder: field.placeholder } : {})}
|
||||
{...(typeof value === "string" ? { value } : {})}
|
||||
{...(onChange ? { onChange: (next: string) => onChange(next) } : {})}
|
||||
/>
|
||||
);
|
||||
if (field.input === "phone")
|
||||
return (
|
||||
<Input
|
||||
{...(id ? { id } : {})}
|
||||
type="tel"
|
||||
placeholder={field.placeholder}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
/>
|
||||
);
|
||||
if (field.input === "number")
|
||||
return (
|
||||
<InputNumber
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "number" ? value : null}
|
||||
onChange={(input) => onChange?.(input ?? undefined)}
|
||||
min={0}
|
||||
style={{ width: "100%" }}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "boolean")
|
||||
return (
|
||||
<Switch
|
||||
{...(id ? { id } : {})}
|
||||
checked={Boolean(value)}
|
||||
onChange={(checked) => onChange?.(checked)}
|
||||
/>
|
||||
);
|
||||
if (field.input === "select")
|
||||
return (
|
||||
<Select
|
||||
{...(id ? { id } : {})}
|
||||
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||
value={typeof value === "string" || typeof value === "number" ? value : undefined}
|
||||
onChange={(selected) => onChange?.(selected)}
|
||||
{...(field.placeholder ? { placeholder: field.placeholder } : {})}
|
||||
/>
|
||||
);
|
||||
if (field.input === "multi-select")
|
||||
return (
|
||||
<Select
|
||||
{...(id ? { id } : {})}
|
||||
mode="multiple"
|
||||
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||
value={Array.isArray(value) ? value.map(String) : []}
|
||||
onChange={(selected) => onChange?.(selected)}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<Input
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
maxLength={field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user