feat: 让模板声明信任内容编辑语义

This commit is contained in:
que01 committed 2026-09-27 12:51:21 +08:00
1 parent 6d7fae95b3
commit e3a4074d8e
12 files changed
+159 -13

No files matched your search

@@ -51,6 +51,17 @@ const types = [
help: "说明回复时间、交付承诺、售后方式或合作预期。",
},
];
type TrustTypeOption = {
type: string;
label: string;
help?: string;
placeholder?: string;
};
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
type: value,
label,
help,
}));
export function TrustContentPage() {
const client = createApiClient();
@@ -58,10 +69,20 @@ export function TrustContentPage() {
const [editing, setEditing] = useState<TrustContent | null>(null);
const [open, setOpen] = useState(false);
const [form] = Form.useForm<TrustContentInput>();
const selectedType = Form.useWatch("type", form);
const query = useQuery({
queryKey: ["trust-content"],
queryFn: () => client.listAdminTrustContent(),
});
const workspace = useQuery({
queryKey: ["admin-workspace-trust-types"],
queryFn: () => client.getAdminWorkspace(),
});
const availableTypes: TrustTypeOption[] = workspace.data?.templateContent?.trustContentTypes
?.length
? workspace.data.templateContent.trustContentTypes
: fallbackTypes;
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
const save = useMutation({
mutationFn: (values: TrustContentInput) =>
editing
@@ -99,7 +120,11 @@ export function TrustContentPage() {
);
};
return (
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
<QueryState
loading={query.isLoading || workspace.isLoading}
error={query.error || workspace.error}
onRetry={() => void Promise.all([query.refetch(), workspace.refetch()])}
>
<AdminPageHeader
title="信任内容"
description="用经历、案例、资历、流程和反馈,让访客知道为什么可以信任你。"
@@ -171,7 +196,9 @@ export function TrustContentPage() {
>
<Form form={form} layout="vertical" onFinish={(values) => save.mutate(values)}>
<Form.Item name="type" label="内容用途" rules={[{ required: true }]}>
<Select options={types} />
<Select
options={availableTypes.map((item) => ({ value: item.type, label: item.label }))}
/>
</Form.Item>
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
<Input placeholder="例如:服务过 30+ 位独立创作者" />
@@ -182,14 +209,16 @@ export function TrustContentPage() {
<Form.Item
name="content"
label="详细内容"
help="每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
help={
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
}
rules={[{ required: true }]}
>
<Input.TextArea
rows={8}
showCount
maxLength={2000}
placeholder="例如:\n周一至周五 17:00 - 22:30\n周末接受团体预约"
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
/>
</Form.Item>
<Form.Item
@@ -250,14 +250,8 @@ export function WorkspacePage() {
<Space direction="vertical" style={{ width: "100%" }}>
<Space wrap>
<Tag color="blue">Schema {runtimeQuery.data?.schemaVersion ?? "-"}</Tag>
<Tag>模块 {runtimeQuery.data?.runtimeModules?.length ?? 0}</Tag>
<Tag>能力 {runtimeQuery.data?.runtimeCapabilities?.length ?? 0}</Tag>
<Tag>
公开业务{" "}
{runtimeQuery.data?.runtimeOfferings?.length ??
runtimeQuery.data?.offerings?.length ??
0}
</Tag>
<Tag>能力 {runtimeQuery.data?.capabilities?.length ?? 0}</Tag>
<Tag>公开业务 {runtimeQuery.data?.offerings?.length ?? 0}</Tag>
<Tag>插件 {runtimeQuery.data?.plugins?.length ?? 0}</Tag>
</Space>
<Typography.Paragraph type="secondary" style={{ marginBottom: 0 }}>
@@ -0,0 +1,2 @@
UPDATE "TrustContent" SET "type" = 'credential' WHERE "type" IN ('profile', 'experience');
UPDATE "TrustContent" SET "type" = 'case' WHERE "type" IN ('portfolio', 'testimonial');
@@ -184,6 +184,7 @@ class AdminWorkspaceController {
displayName: manifest.displayName,
admin: manifest.admin,
assetSlots: manifest.assetSlots,
trustContentTypes: manifest.trustContentTypes ?? [],
}
: null,
};
+2
View File
@@ -826,6 +826,8 @@ test("admin can install a template and public workspace exposes enabled configur
assert.equal(JSON.parse(workspace.body).fields.length, 5);
const templateContent = JSON.parse(workspace.body).templateContent;
assert.equal(templateContent.displayName, "阿成校园餐");
assert.ok(templateContent.trustContentTypes.some((item) => item.type === "schedule"));
assert.ok(templateContent.trustContentTypes.some((item) => item.label === "出摊与营业安排"));
assert.ok(templateContent.admin.sections.some((section) => section.title === "首页出摊信息"));
assert.ok(
templateContent.admin.sections