feat: 让模板声明信任内容编辑语义
This commit is contained in:
1 parent
6d7fae95b3
commit
e3a4074d8e
12 files changed
+159
-13
No files matched your search
@@ -8,6 +8,8 @@
|
||||
- 阿成首页、出摊服务、主理人页面消费 `trustItems`;无对应类型时不渲染区块。
|
||||
- `AGENTS.md` 固化模板 package 与品牌数据库的边界,禁止用全局 seed 承载模板集合。
|
||||
- Admin 信任内容页面改用通用中文类型和逐行填写说明,不再出现餐饮专属管理术语;演示 seed 与模板 sampleContent 已移除旧 `profile/portfolio` 类型。
|
||||
- 模板 manifest 现在可以声明信任类型的行业化 label、help 和 placeholder;Admin 通过 workspace contract 消费这些声明,平台不再硬编码行业文案。
|
||||
- 新增迁移,将历史 `profile/experience/portfolio/testimonial` 数据归一化到 `credential/case`。
|
||||
|
||||
## 验证
|
||||
|
||||
@@ -15,3 +17,4 @@
|
||||
- miniapp fixture、visual fixture、template compiler:通过。
|
||||
- typecheck、lint:通过。
|
||||
- Admin typecheck、production build、template catalog validation:通过。
|
||||
- API integration:37/37 通过,包含模板化信任类型声明和历史类型迁移。
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -87,6 +87,7 @@ export interface TemplateAdminSection {
|
||||
export interface AdminTemplateContent {
|
||||
displayName: string;
|
||||
admin: { sections: TemplateAdminSection[] };
|
||||
trustContentTypes?: Array<{ type: string; label: string; help?: string; placeholder?: string }>;
|
||||
assetSlots: Array<{
|
||||
key: string;
|
||||
binding: string;
|
||||
|
||||
@@ -288,6 +288,41 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
"trustContentTypes": [
|
||||
{
|
||||
"type": "schedule",
|
||||
"label": "出摊与营业安排",
|
||||
"help": "说明固定出摊时间、临时营业安排或接受预订的时段。",
|
||||
"placeholder": "例如:周一至周五 17:00 - 22:30"
|
||||
},
|
||||
{
|
||||
"type": "coverage",
|
||||
"label": "取餐与配送范围",
|
||||
"help": "说明服务地点、取餐方式和可配送范围。",
|
||||
"placeholder": "例如:支持校内宿舍楼下配送"
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "定制餐品流程",
|
||||
"help": "每行写一步,从提出需求到完成交付。",
|
||||
"placeholder": "例如:提交需求\n确认菜单\n制作交付"
|
||||
},
|
||||
{
|
||||
"type": "credential",
|
||||
"label": "食品安全与制作标准",
|
||||
"help": "填写让顾客放心的资质、卫生或制作标准。"
|
||||
},
|
||||
{
|
||||
"type": "case",
|
||||
"label": "客户案例与反馈",
|
||||
"help": "填写代表性订单、活动案例或客户评价。"
|
||||
},
|
||||
{
|
||||
"type": "promise",
|
||||
"label": "回复与服务承诺",
|
||||
"help": "说明回复时间、退改规则或服务承诺。"
|
||||
}
|
||||
],
|
||||
"sampleContent": {
|
||||
"food": {
|
||||
"templateKey": "food",
|
||||
@@ -681,6 +716,39 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
"trustContentTypes": [
|
||||
{
|
||||
"type": "schedule",
|
||||
"label": "服务与合作安排",
|
||||
"help": "说明可预约时间、服务周期或项目排期。"
|
||||
},
|
||||
{
|
||||
"type": "coverage",
|
||||
"label": "服务范围与适用对象",
|
||||
"help": "说明服务地区、项目类型或合作边界。"
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "合作流程",
|
||||
"help": "每行写一步,从初次沟通到交付完成。",
|
||||
"placeholder": "例如:需求沟通\n方案确认\n落地交付"
|
||||
},
|
||||
{
|
||||
"type": "credential",
|
||||
"label": "专业资历与方法",
|
||||
"help": "填写经验、资质、专业标准或工作方法。"
|
||||
},
|
||||
{
|
||||
"type": "case",
|
||||
"label": "项目案例与客户反馈",
|
||||
"help": "填写代表性项目、成果或客户评价。"
|
||||
},
|
||||
{
|
||||
"type": "promise",
|
||||
"label": "合作预期与响应承诺",
|
||||
"help": "说明回复时间、合作边界和后续跟进方式。"
|
||||
}
|
||||
],
|
||||
"sampleContent": {
|
||||
"doors": {
|
||||
"templateKey": "doors",
|
||||
@@ -912,4 +980,4 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
];
|
||||
export const generatedTemplatePackageRegistryHash =
|
||||
"ebcac61077ff8d4097065555e86c651b93f99f91196b55b9503a13c6dcb9631a";
|
||||
"afbd1045ccdc7eda85bd9707ce27083ba699899f115a26a3c60459a88a5e5148";
|
||||
@@ -225,6 +225,12 @@ export interface TemplatePackageManifest {
|
||||
fields: readonly { key: string; binding: string; label: string; required?: boolean }[];
|
||||
}[];
|
||||
};
|
||||
trustContentTypes?: readonly {
|
||||
type: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
}[];
|
||||
sampleContent?: Partial<Record<BrandTemplateKey, TemplateSampleContent>>;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,14 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"trustContentTypes": [
|
||||
{ "type": "schedule", "label": "出摊与营业安排", "help": "说明固定出摊时间、临时营业安排或接受预订的时段。", "placeholder": "例如:周一至周五 17:00 - 22:30" },
|
||||
{ "type": "coverage", "label": "取餐与配送范围", "help": "说明服务地点、取餐方式和可配送范围。", "placeholder": "例如:支持校内宿舍楼下配送" },
|
||||
{ "type": "process", "label": "定制餐品流程", "help": "每行写一步,从提出需求到完成交付。", "placeholder": "例如:提交需求\n确认菜单\n制作交付" },
|
||||
{ "type": "credential", "label": "食品安全与制作标准", "help": "填写让顾客放心的资质、卫生或制作标准。" },
|
||||
{ "type": "case", "label": "客户案例与反馈", "help": "填写代表性订单、活动案例或客户评价。" },
|
||||
{ "type": "promise", "label": "回复与服务承诺", "help": "说明回复时间、退改规则或服务承诺。" }
|
||||
],
|
||||
"sampleContent": {
|
||||
"food": {
|
||||
"templateKey": "food",
|
||||
|
||||
@@ -64,6 +64,13 @@ export type TemplateAdminManifest = {
|
||||
sections: TemplateAdminSection[];
|
||||
};
|
||||
|
||||
export type TemplateTrustContentType = {
|
||||
type: "schedule" | "coverage" | "process" | "credential" | "case" | "promise" | (string & {});
|
||||
label: string;
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
};
|
||||
|
||||
export type TemplateSampleContent = {
|
||||
templateKey: string;
|
||||
offerings: Array<Record<string, unknown>>;
|
||||
@@ -96,6 +103,7 @@ export type TemplatePackageManifest = {
|
||||
dataSlots: TemplateDataSlot[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
trustContentTypes?: TemplateTrustContentType[];
|
||||
sampleContent?: Record<string, TemplateSampleContent>;
|
||||
};
|
||||
|
||||
@@ -125,6 +133,22 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push("data slot source is invalid");
|
||||
}
|
||||
}
|
||||
if (manifest.trustContentTypes !== undefined) {
|
||||
if (!Array.isArray(manifest.trustContentTypes))
|
||||
errors.push("trustContentTypes must be an array");
|
||||
else {
|
||||
for (const [index, item] of manifest.trustContentTypes.entries()) {
|
||||
if (!item || typeof item !== "object") {
|
||||
errors.push(`trustContentTypes.${index} must be an object`);
|
||||
continue;
|
||||
}
|
||||
if (typeof item.type !== "string" || !item.type.trim())
|
||||
errors.push(`trustContentTypes.${index}.type is required`);
|
||||
if (typeof item.label !== "string" || !item.label.trim())
|
||||
errors.push(`trustContentTypes.${index}.label is required`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(manifest.assetSlots)) errors.push("assetSlots must be an array");
|
||||
else {
|
||||
for (const slot of manifest.assetSlots) {
|
||||
|
||||
@@ -269,6 +269,14 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"trustContentTypes": [
|
||||
{ "type": "schedule", "label": "服务与合作安排", "help": "说明可预约时间、服务周期或项目排期。" },
|
||||
{ "type": "coverage", "label": "服务范围与适用对象", "help": "说明服务地区、项目类型或合作边界。" },
|
||||
{ "type": "process", "label": "合作流程", "help": "每行写一步,从初次沟通到交付完成。", "placeholder": "例如:需求沟通\n方案确认\n落地交付" },
|
||||
{ "type": "credential", "label": "专业资历与方法", "help": "填写经验、资质、专业标准或工作方法。" },
|
||||
{ "type": "case", "label": "项目案例与客户反馈", "help": "填写代表性项目、成果或客户评价。" },
|
||||
{ "type": "promise", "label": "合作预期与响应承诺", "help": "说明回复时间、合作边界和后续跟进方式。" }
|
||||
],
|
||||
"sampleContent": {
|
||||
"doors": {
|
||||
"templateKey": "doors",
|
||||
|
||||
Reference in new issue
Block a user