feat: 完善模板内容后台配置能力
This commit is contained in:
1 parent
2bc2193b44
commit
9266ec824a
37 files changed
+2273
-63
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { Button, Form, Input, Space } from "antd";
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
|
||||
export function TemplateListField({
|
||||
field,
|
||||
name,
|
||||
}: {
|
||||
field: TemplateAdminField;
|
||||
name: string | (string | number)[];
|
||||
}) {
|
||||
return (
|
||||
<Form.Item label={field.label} help={field.help}>
|
||||
<Form.List name={name}>
|
||||
{(rows, { add, remove }) => (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{rows.map((row, index) => (
|
||||
<Space key={row.key} align="start" wrap>
|
||||
{field.itemFields?.map((itemField) => (
|
||||
<Form.Item
|
||||
key={itemField.key}
|
||||
name={[row.name, itemField.key]}
|
||||
label={`${index + 1}. ${itemField.label}`}
|
||||
rules={
|
||||
itemField.required === false
|
||||
? []
|
||||
: [{ required: true, message: `请填写${itemField.label}` }]
|
||||
}
|
||||
>
|
||||
{itemField.input === "textarea" ? <Input.TextArea rows={2} /> : <Input />}
|
||||
</Form.Item>
|
||||
))}
|
||||
<Button onClick={() => remove(row.name)}>删除</Button>
|
||||
</Space>
|
||||
))}
|
||||
<Button onClick={() => add()}>新增{field.label}</Button>
|
||||
</Space>
|
||||
)}
|
||||
</Form.List>
|
||||
</Form.Item>
|
||||
);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { useEffect, useMemo } from "react";
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
@@ -62,7 +63,16 @@ export function PresentationEditor({
|
||||
}: PresentationEditorProps) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const sections = templateContent?.admin.sections ?? [];
|
||||
const sections = useMemo(
|
||||
() =>
|
||||
(templateContent?.admin.sections ?? [])
|
||||
.map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter((field) => field.binding.startsWith("brand.config.")),
|
||||
}))
|
||||
.filter((section) => section.fields.length > 0),
|
||||
[templateContent],
|
||||
);
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
for (const section of sections) {
|
||||
@@ -70,6 +80,7 @@ export function PresentationEditor({
|
||||
values[presentationFieldName(section.key, field.key)] = readPresentationValue(
|
||||
config,
|
||||
field.binding,
|
||||
field,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +93,7 @@ export function PresentationEditor({
|
||||
return createApiClient().updateAdminBrand({ config: nextConfig });
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面内容已保存,小程序将使用最新内容");
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
@@ -125,17 +136,28 @@ export function PresentationEditor({
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col key={field.key} xs={24} md={field.input === "textarea" ? 24 : 12}>
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export type PresentationField = {
|
||||
key: string;
|
||||
binding: string;
|
||||
input?: string;
|
||||
itemValueKey?: string;
|
||||
};
|
||||
|
||||
export type PresentationSection = {
|
||||
@@ -8,7 +10,7 @@ export type PresentationSection = {
|
||||
fields: PresentationField[];
|
||||
};
|
||||
|
||||
export type PresentationValues = Record<string, string | number | null | undefined>;
|
||||
export type PresentationValues = Record<string, unknown>;
|
||||
|
||||
function asObject(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value)
|
||||
@@ -17,8 +19,11 @@ function asObject(value: unknown): Record<string, unknown> {
|
||||
}
|
||||
|
||||
function safePath(binding: string): string[] | null {
|
||||
if (!binding.startsWith("brand.config.")) return null;
|
||||
const path = binding.slice("brand.config.".length).split(".");
|
||||
const prefix = ["brand.config.", "offering.config.", "trust.config."].find((candidate) =>
|
||||
binding.startsWith(candidate),
|
||||
);
|
||||
if (!prefix) return null;
|
||||
const path = binding.slice(prefix.length).split(".");
|
||||
if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part)))
|
||||
return null;
|
||||
return path;
|
||||
@@ -31,18 +36,25 @@ export function presentationFieldName(sectionKey: string, fieldKey: string): str
|
||||
export function readPresentationValue(
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
binding: string,
|
||||
): string | number | undefined {
|
||||
field?: PresentationField,
|
||||
): unknown {
|
||||
const path = safePath(binding);
|
||||
if (!path) return undefined;
|
||||
let value: unknown = asObject(config);
|
||||
for (const part of path) value = asObject(value)[part];
|
||||
if (field?.input === "list") {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return field.itemValueKey
|
||||
? (value as unknown[]).map((item) => ({ [field.itemValueKey as string]: item }))
|
||||
: value;
|
||||
}
|
||||
return typeof value === "string" || typeof value === "number" ? value : undefined;
|
||||
}
|
||||
|
||||
function writePath(
|
||||
source: Record<string, unknown>,
|
||||
path: string[],
|
||||
value: string | number | null | undefined,
|
||||
value: unknown,
|
||||
): Record<string, unknown> {
|
||||
const [head, ...tail] = path;
|
||||
if (!head) return source;
|
||||
@@ -63,11 +75,16 @@ export function applyPresentationValues(
|
||||
for (const field of section.fields) {
|
||||
const path = safePath(field.binding);
|
||||
if (!path) continue;
|
||||
nextConfig = writePath(
|
||||
nextConfig,
|
||||
path,
|
||||
values[presentationFieldName(section.key, field.key)],
|
||||
);
|
||||
const raw = values[presentationFieldName(section.key, field.key)];
|
||||
const value =
|
||||
field.input === "list" && Array.isArray(raw)
|
||||
? field.itemValueKey
|
||||
? raw
|
||||
.map((item) => asObject(item)[field.itemValueKey as string])
|
||||
.filter((item) => typeof item === "string" && item.trim())
|
||||
: raw
|
||||
: raw;
|
||||
nextConfig = writePath(nextConfig, path, value);
|
||||
}
|
||||
}
|
||||
return nextConfig;
|
||||
|
||||
@@ -13,11 +13,17 @@ import {
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { Offering } from "@personal-brand/api-client";
|
||||
import type { Offering, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../brand/presentation-bindings.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
|
||||
export function ServicesPage() {
|
||||
@@ -30,11 +36,32 @@ export function ServicesPage() {
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-offering-fields"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const templateFields: TemplateAdminField[] = (
|
||||
workspace.data?.templateContent?.admin.sections ?? []
|
||||
)
|
||||
.filter((section) => section.target === "offering")
|
||||
.flatMap((section) =>
|
||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||
);
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) =>
|
||||
editingOffering
|
||||
? client.updateAdminOffering(editingOffering.id, values)
|
||||
: client.createAdminOffering(values as Omit<Offering, "id" | "brandId">),
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
const fields = Object.fromEntries(
|
||||
Object.entries(values).filter(([key]) => key !== "config" && !key.startsWith("offering:")),
|
||||
);
|
||||
const config = applyPresentationValues(
|
||||
editingOffering?.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const body = { ...fields, config };
|
||||
return editingOffering
|
||||
? client.updateAdminOffering(editingOffering.id, body)
|
||||
: client.createAdminOffering(body as Omit<Offering, "id" | "brandId">);
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已保存");
|
||||
setOfferingOpen(false);
|
||||
@@ -72,16 +99,33 @@ export function ServicesPage() {
|
||||
coverUrl: item.coverUrl ?? "",
|
||||
sortOrder: item.sortOrder,
|
||||
isEnabled: item.isEnabled,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
readPresentationValue(item.config, field.binding, field),
|
||||
]),
|
||||
),
|
||||
}
|
||||
: { kind: "service", isEnabled: true, sortOrder: 0 },
|
||||
: {
|
||||
kind: "service",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
field.input === "list" ? [] : undefined,
|
||||
]),
|
||||
),
|
||||
},
|
||||
);
|
||||
};
|
||||
return (
|
||||
<QueryState
|
||||
loading={offerings.isLoading}
|
||||
error={offerings.error}
|
||||
loading={offerings.isLoading || workspace.isLoading}
|
||||
error={offerings.error || workspace.error}
|
||||
onRetry={() => {
|
||||
void offerings.refetch();
|
||||
void workspace.refetch();
|
||||
}}
|
||||
>
|
||||
<AdminPageHeader
|
||||
@@ -229,6 +273,30 @@ export function ServicesPage() {
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
{templateFields.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField
|
||||
key={field.key}
|
||||
field={field}
|
||||
name={presentationFieldName("offering", field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={presentationFieldName("offering", field.key)}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
>
|
||||
{field.input === "textarea" ? (
|
||||
<Input.TextArea rows={3} />
|
||||
) : field.input === "image" ? (
|
||||
<ImageUrlField />
|
||||
) : (
|
||||
<Input />
|
||||
)}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
</Form>
|
||||
</Modal>
|
||||
</QueryState>
|
||||
|
||||
@@ -14,11 +14,16 @@ import {
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import type {
|
||||
TemplateAdminField,
|
||||
TrustContent,
|
||||
TrustContentInput,
|
||||
} from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
|
||||
const types = [
|
||||
@@ -59,6 +64,7 @@ type TrustTypeOption = {
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
};
|
||||
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
|
||||
type: value,
|
||||
@@ -86,7 +92,19 @@ export function TrustContentPage() {
|
||||
? workspace.data.templateContent.trustContentTypes
|
||||
: fallbackTypes;
|
||||
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
|
||||
const contentByType = new Map((query.data ?? []).map((item) => [item.type, item]));
|
||||
const contentByType = new Map<string, TrustContent>();
|
||||
for (const item of query.data ?? []) {
|
||||
const current = contentByType.get(item.type);
|
||||
const hasConfig = Object.keys(item.config ?? {}).length > 0;
|
||||
const currentHasConfig = Object.keys(current?.config ?? {}).length > 0;
|
||||
if (
|
||||
!current ||
|
||||
(item.isPublished && !current.isPublished) ||
|
||||
(item.isPublished === current.isPublished && hasConfig && !currentHasConfig)
|
||||
) {
|
||||
contentByType.set(item.type, item);
|
||||
}
|
||||
}
|
||||
const firstMissingRequiredType =
|
||||
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
|
||||
availableTypes[0]?.type ??
|
||||
@@ -121,10 +139,11 @@ export function TrustContentPage() {
|
||||
title: item.title,
|
||||
...(item.summary ? { summary: item.summary } : {}),
|
||||
content: item.content,
|
||||
config: item.config ?? {},
|
||||
...(item.coverUrl ? { coverUrl: item.coverUrl } : {}),
|
||||
isPublished: item.isPublished,
|
||||
}
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false },
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false, config: {} },
|
||||
);
|
||||
};
|
||||
return (
|
||||
@@ -266,6 +285,21 @@ export function TrustContentPage() {
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
</Form.Item>
|
||||
{(!editing || contentByType.get(selectedType)?.id === editing.id) &&
|
||||
selectedTypeMeta?.configFields?.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField key={field.key} field={field} name={["config", field.key]} />
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={["config", field.key]}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
>
|
||||
{field.input === "textarea" ? <Input.TextArea rows={3} /> : <Input />}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="配图地址"
|
||||
|
||||
@@ -56,3 +56,55 @@ const unsafe = applyPresentationValues(
|
||||
|
||||
assert.deepEqual(unsafe, { founder: "原主理人" });
|
||||
assert.equal({}.polluted, undefined);
|
||||
|
||||
const listFields = [
|
||||
{
|
||||
key: "details",
|
||||
fields: [
|
||||
{ key: "coverage", binding: "brand.config.profilePresentation.coverage", input: "list" },
|
||||
{
|
||||
key: "warranty",
|
||||
binding: "brand.config.profilePresentation.warranty",
|
||||
input: "list",
|
||||
itemValueKey: "value",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const existingLists = {
|
||||
profilePresentation: {
|
||||
coverage: [{ title: "原区域", content: "原说明" }],
|
||||
warranty: ["原承诺"],
|
||||
other: "保留",
|
||||
},
|
||||
};
|
||||
assert.deepEqual(
|
||||
readPresentationValue(
|
||||
existingLists,
|
||||
"brand.config.profilePresentation.warranty",
|
||||
listFields[0].fields[1],
|
||||
),
|
||||
[{ value: "原承诺" }],
|
||||
);
|
||||
const updatedLists = applyPresentationValues(existingLists, listFields, {
|
||||
[presentationFieldName("details", "coverage")]: [{ title: "新区域", content: "新说明" }],
|
||||
[presentationFieldName("details", "warranty")]: [{ value: "新承诺" }, { value: "" }],
|
||||
});
|
||||
assert.deepEqual(updatedLists.profilePresentation.coverage, [
|
||||
{ title: "新区域", content: "新说明" },
|
||||
]);
|
||||
assert.deepEqual(updatedLists.profilePresentation.warranty, ["新承诺"]);
|
||||
assert.equal(updatedLists.profilePresentation.other, "保留");
|
||||
assert.deepEqual(existingLists.profilePresentation.warranty, ["原承诺"]);
|
||||
|
||||
const offering = applyPresentationValues(
|
||||
{ details: { background: "旧背景", preserve: "保留" } },
|
||||
[
|
||||
{
|
||||
key: "offering",
|
||||
fields: [{ key: "background", binding: "offering.config.details.background" }],
|
||||
},
|
||||
],
|
||||
{ [presentationFieldName("offering", "background")]: "新背景" },
|
||||
);
|
||||
assert.deepEqual(offering.details, { background: "新背景", preserve: "保留" });
|
||||
@@ -1206,6 +1206,125 @@ test("public workspace exposes declared brand and trust presentation data", asyn
|
||||
}
|
||||
});
|
||||
|
||||
test("edited template facts reach public workspace only after publication", async () => {
|
||||
const doorsBrand = await prisma.brandProfile.findUniqueOrThrow({
|
||||
where: { slug: "linjing-doors" },
|
||||
});
|
||||
const trust = await prisma.trustContent.findFirstOrThrow({
|
||||
where: { brandId: doorsBrand.id, type: "credential", isPublished: true },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
});
|
||||
const offering = await prisma.offering.findFirstOrThrow({
|
||||
where: { brandId: doorsBrand.id, isEnabled: true },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
});
|
||||
const adminUser = await prisma.adminUser.findUniqueOrThrow({
|
||||
where: { username: "admin" },
|
||||
select: { id: true },
|
||||
});
|
||||
const token = signIdentity({ subject: adminUser.id, brandId: doorsBrand.id, role: "admin" });
|
||||
const headers = { authorization: `Bearer ${token}` };
|
||||
const originalBrandConfig = doorsBrand.config;
|
||||
const originalTrustConfig = trust.config;
|
||||
const originalOfferingConfig = offering.config;
|
||||
const before = JSON.parse((await request("/public/workspace?brandSlug=linjing-doors")).body);
|
||||
const changedTitle = "集成测试定制首页标题";
|
||||
const changedArea = "集成测试项目地点";
|
||||
const changedIntro = "集成测试发布后联系说明";
|
||||
const changedHint = "集成测试咨询后处理说明";
|
||||
const changedDetailHero = "https://example.com/integration-detail.jpg";
|
||||
const changedStats = [{ value: "42", label: "测试成果" }];
|
||||
try {
|
||||
const brandConfig = originalBrandConfig ?? {};
|
||||
const presentation = brandConfig.visualPresentation ?? {};
|
||||
const brandUpdate = await request("/admin/config/brand", {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: {
|
||||
config: {
|
||||
homeHero: { ...brandConfig.homeHero, title: changedTitle },
|
||||
visualPresentation: {
|
||||
...presentation,
|
||||
success: { ...presentation.success, intro: changedIntro },
|
||||
detail: { ...presentation.detail, inquiryHint: changedHint },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.equal(brandUpdate.statusCode, 200);
|
||||
const trustUpdate = await request(`/admin/config/trust-content/${trust.id}`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { config: { ...(trust.config ?? {}), stats: changedStats } },
|
||||
});
|
||||
assert.equal(trustUpdate.statusCode, 200);
|
||||
const offeringUpdate = await request(`/admin/workspace/offerings/${offering.id}`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: {
|
||||
config: {
|
||||
...(offering.config ?? {}),
|
||||
area: changedArea,
|
||||
detailHero: changedDetailHero,
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.equal(offeringUpdate.statusCode, 200);
|
||||
|
||||
const draftView = JSON.parse((await request("/public/workspace?brandSlug=linjing-doors")).body);
|
||||
assert.deepEqual(draftView.brand.homeHero, before.brand.homeHero);
|
||||
assert.equal(
|
||||
draftView.brand.visualPresentation.success.intro,
|
||||
before.brand.visualPresentation.success.intro,
|
||||
);
|
||||
assert.equal(
|
||||
draftView.brand.visualPresentation.detail.inquiryHint,
|
||||
before.brand.visualPresentation.detail.inquiryHint,
|
||||
);
|
||||
assert.deepEqual(draftView.trustPresentation.stats, before.trustPresentation.stats);
|
||||
assert.equal(draftView.offerings[0].presentation.area, before.offerings[0].presentation.area);
|
||||
assert.equal(
|
||||
draftView.offerings[0].presentation.heroImage,
|
||||
before.offerings[0].presentation.heroImage,
|
||||
);
|
||||
|
||||
const publish = await request("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { note: "集成测试模板内容编辑" },
|
||||
});
|
||||
assert.equal(publish.statusCode, 201);
|
||||
const afterPublish = JSON.parse(
|
||||
(await request("/public/workspace?brandSlug=linjing-doors")).body,
|
||||
);
|
||||
assert.equal(afterPublish.brand.homeHero.title, changedTitle);
|
||||
assert.equal(afterPublish.brand.visualPresentation.success.intro, changedIntro);
|
||||
assert.equal(afterPublish.brand.visualPresentation.detail.inquiryHint, changedHint);
|
||||
assert.deepEqual(afterPublish.trustPresentation.stats, changedStats);
|
||||
assert.equal(afterPublish.offerings[0].presentation.area, changedArea);
|
||||
assert.equal(afterPublish.offerings[0].presentation.heroImage, changedDetailHero);
|
||||
} finally {
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: doorsBrand.id },
|
||||
data: { config: originalBrandConfig },
|
||||
});
|
||||
await prisma.trustContent.update({
|
||||
where: { id: trust.id },
|
||||
data: { config: originalTrustConfig },
|
||||
});
|
||||
await prisma.offering.update({
|
||||
where: { id: offering.id },
|
||||
data: { config: originalOfferingConfig },
|
||||
});
|
||||
const restored = await request("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { note: "恢复集成测试模板基线" },
|
||||
});
|
||||
assert.equal(restored.statusCode, 201);
|
||||
}
|
||||
});
|
||||
|
||||
test("admin can create and version an inquiry form", async () => {
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
|
||||
@@ -1 +1 @@
|
||||
<view class="form"><view wx:for="{{fields}}" wx:key="key" class="field"><text class="label">{{item.label}}{{item.required ? ' *' : ''}}</text><input wx:if="{{item.type === 'tel' || item.type === 'phone' || item.type === 'number' || item.type === 'text'}}" type="{{item.type === 'number' ? 'number' : item.type === 'tel' || item.type === 'phone' ? 'number' : 'text'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input"/><textarea wx:elif="{{item.type === 'textarea'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" auto-height="true"/><picker wx:elif="{{item.type === 'date'}}" mode="date" data-key="{{item.key}}" value="{{values[item.key]}}" bindchange="dateChange"><view class="picker-value">{{values[item.key] || '请选择日期'}}</view></picker><picker wx:elif="{{item.type === 'select' || item.type === 'radio'}}" mode="selector" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker-value">{{values[item.key] || '请选择'}}</view></picker></view><button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button><text class="privacy">信息仅用于本次方案沟通,我们不会向第三方披露。</text></view>
|
||||
<view class="form"><view wx:for="{{fields}}" wx:key="key" class="field"><text class="label">{{item.label}}{{item.required ? ' *' : ''}}</text><input wx:if="{{item.type === 'tel' || item.type === 'phone' || item.type === 'number' || item.type === 'text'}}" type="{{item.type === 'number' ? 'number' : item.type === 'tel' || item.type === 'phone' ? 'number' : 'text'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input"/><textarea wx:elif="{{item.type === 'textarea'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" auto-height="true"/><picker wx:elif="{{item.type === 'date'}}" mode="date" data-key="{{item.key}}" value="{{values[item.key]}}" bindchange="dateChange"><view class="picker-value">{{values[item.key] || '请选择日期'}}</view></picker><picker wx:elif="{{item.type === 'select' || item.type === 'radio'}}" mode="selector" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker-value">{{values[item.key] || '请选择'}}</view></picker></view><button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button></view>
|
||||
@@ -1 +1 @@
|
||||
<view class="success"><view class="mark">✓</view><text class="eyebrow">{{presentation.eyebrow}}</text><text class="title">{{presentation.title}}</text><text class="intro">{{presentation.intro}}</text><view class="summary"><view><text>档案编号</text><text>{{record.id}}</text></view><view><text>定制类型</text><text>{{record.type}}</text></view><view><text>当前状态</text><text>{{record.status}}</text></view></view><button bindtap="records">{{presentation.recordsAction}}</button><button class="secondary" bindtap="home">{{presentation.homeAction}}</button></view>
|
||||
<view class="success"><view class="mark">✓</view><text class="eyebrow">{{presentation.eyebrow}}</text><text class="title">{{presentation.title}}</text><text class="intro">{{presentation.intro}}</text><view class="summary"><view><text>档案编号</text><text>{{record.id}}</text></view><view wx:if="{{record.type}}"><text>咨询类型</text><text>{{record.type}}</text></view><view><text>当前状态</text><text>{{record.status}}</text></view></view><button bindtap="records">{{presentation.recordsAction}}</button><button class="secondary" bindtap="home">{{presentation.homeAction}}</button></view>
|
||||
@@ -6,7 +6,7 @@ Page({
|
||||
submitting: false,
|
||||
eyebrow: "CONSULTATION",
|
||||
title: "需求咨询",
|
||||
subtitle: "提交信息后由主理人与你联系",
|
||||
subtitle: "",
|
||||
submitLabel: "提交需求",
|
||||
presentation: {},
|
||||
values: {},
|
||||
@@ -34,7 +34,7 @@ Page({
|
||||
formId: form?.key || form?.id || "",
|
||||
title: isQuote ? "获取报价方案" : presentation.title || "需求咨询",
|
||||
eyebrow: isQuote ? "QUOTE REQUEST" : presentation.eyebrow || "CONSULTATION",
|
||||
subtitle: presentation.subtitle || "提交信息后由主理人与你联系",
|
||||
subtitle: presentation.subtitle || "",
|
||||
submitLabel: isQuote ? "提交报价需求" : presentation.submitLabel || "提交需求",
|
||||
presentation,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user