feat: 完善模板字段编辑与分类治理

This commit is contained in:
que01 committed 2026-10-11 23:07:53 +08:00
1 parent 91322fa9a0
commit 26bcb2b66e
23 files changed
+631 -250

No files matched your search

@@ -36,25 +36,16 @@ const inquiryFieldTypes = [
{ value: "multi-select", label: "多项选择" },
];
function optionsToText(options: unknown): string {
if (!Array.isArray(options)) return "";
return options
.map((option) => {
if (!option || typeof option !== "object") return "";
const label = (option as { label?: unknown }).label;
return typeof label === "string" ? label : "";
})
.filter(Boolean)
.join("\n");
function readOptionLabel(option: unknown): string {
const value = option as { label?: unknown } | null | undefined;
return typeof value?.label === "string" ? value.label : "";
}
function optionsFromText(value: unknown): Array<{ label: string; value: string }> {
if (typeof value !== "string") return [];
return value
.split(/\r?\n|、|,/)
.map((item) => item.trim())
.filter(Boolean)
.map((item) => ({ label: item, value: item }));
function normalizeOptionLabels(options: unknown): Array<{ label: string; value: string }> {
return (Array.isArray(options) ? options : [])
.map(readOptionLabel)
.filter((label) => label.trim())
.map((label) => ({ label, value: label }));
}
function supportsIndustry(
@@ -541,11 +532,11 @@ export function WorkspacePage() {
name: item.name,
purpose: item.purpose,
offeringId: item.offeringId ?? undefined,
fieldsSnapshot: item.fieldsSnapshot.map((field) => {
fieldsSnapshot: item.fieldsSnapshot.map((field: unknown) => {
const value = field as Record<string, unknown>;
return {
...value,
optionsText: optionsToText(value.options),
options: normalizeOptionLabels(value.options),
};
}),
});
@@ -719,12 +710,15 @@ export function WorkspacePage() {
fieldsSnapshot: (Array.isArray(values.fieldsSnapshot)
? values.fieldsSnapshot
: []
).map((field) => {
).map((field: unknown) => {
const item = field as Record<string, unknown>;
const { optionsText, ...rest } = item;
const { options, ...rest } = item;
const type = typeof rest.type === "string" ? rest.type : "text";
return ["select", "radio", "multi-select"].includes(type)
? { ...rest, options: optionsFromText(optionsText) }
? {
...rest,
options: normalizeOptionLabels(options),
}
: rest;
}),
};
@@ -824,18 +818,54 @@ export function WorkspacePage() {
["select", "radio", "multi-select"].includes(
String(getFieldValue(["fieldsSnapshot", name, "type"])),
) ? (
<Form.Item
{...restField}
name={[name, "optionsText"]}
label="可选内容"
help="每行填写一个选项,也可以用顿号分隔。"
rules={[{ required: true, message: "请至少填写一个选项" }]}
<Form.List
name={[name, "options"]}
rules={[
{
validator: (_, value: unknown) =>
Array.isArray(value) &&
value.some((option: unknown) => readOptionLabel(option).trim())
? Promise.resolve()
: Promise.reject(new Error("请至少添加一个选项")),
},
]}
>
<Input.TextArea
rows={2}
placeholder="例如:预算内、需要沟通、暂不确定"
/>
</Form.Item>
{(optionFields, { add, remove }, { errors }) => (
<>
{optionFields.map((optionField) => (
<Space
key={optionField.key}
align="center"
style={{ display: "flex" }}
>
<Form.Item
{...optionField}
name={[optionField.name, "label"]}
initialValue=""
rules={[{ required: true, message: "请填写选项内容" }]}
style={{ flex: 1, minWidth: 240, marginBottom: 8 }}
>
<Input placeholder="例如:预算内" />
</Form.Item>
<Button
danger
onClick={() => remove(optionField.name)}
style={{ marginBottom: 8 }}
>
删除
</Button>
</Space>
))}
<Button
onClick={() => add({ label: "", value: "" })}
style={{ marginBottom: 8 }}
>
新增选项
</Button>
<Form.ErrorList errors={errors} />
</>
)}
</Form.List>
) : null
}
</Form.Item>