diff --git a/apps/admin/src/components/TemplateListField.tsx b/apps/admin/src/components/TemplateListField.tsx
index 1d4ec09..46ae173 100644
--- a/apps/admin/src/components/TemplateListField.tsx
+++ b/apps/admin/src/components/TemplateListField.tsx
@@ -10,8 +10,18 @@ export function TemplateListField({
}) {
return (
-
- {(rows, { add, remove }) => (
+
+ field.required && (!Array.isArray(values) || values.length === 0)
+ ? Promise.reject(new Error(`请至少填写一项${field.label}`))
+ : Promise.resolve(),
+ },
+ ]}
+ >
+ {(rows, { add, remove }, { errors }) => (
{rows.map((row, index) => (
@@ -32,6 +42,7 @@ export function TemplateListField({
))}
+
)}
diff --git a/apps/admin/src/features/brand/BrandPage.tsx b/apps/admin/src/features/brand/BrandPage.tsx
index c27cd4b..488d894 100644
--- a/apps/admin/src/features/brand/BrandPage.tsx
+++ b/apps/admin/src/features/brand/BrandPage.tsx
@@ -33,7 +33,7 @@ export function BrandPage() {
{!brand.data ? null : (
<>
{template.data?.name ?? "当前模板"}}
/>
@@ -152,7 +152,9 @@ export function BrandPage() {
- 小程序首页将优先使用以下信息
+
+ 这些资料会用于小程序首页和联系区域
+
{brand.data.name || "品牌名称"}
{brand.data.tagline || "一句话定位"}
diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx
index 0fed01b..30d0bdf 100644
--- a/apps/admin/src/features/brand/PresentationEditor.tsx
+++ b/apps/admin/src/features/brand/PresentationEditor.tsx
@@ -2,17 +2,23 @@ import {
Alert,
Button,
Card,
+ Divider,
Col,
Form,
+ Grid,
Input,
InputNumber,
Row,
+ Select,
+ Segmented,
Space,
+ Tag,
Typography,
message,
} from "antd";
import { useMutation, useQueryClient } from "@tanstack/react-query";
-import { useEffect, useMemo } from "react";
+import { useEffect, useMemo, useState } from "react";
+import { useNavigate } from "react-router-dom";
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
import { createApiClient } from "../../lib/api.js";
import { ImageUrlField } from "../../components/ImageUrlField.js";
@@ -46,6 +52,22 @@ function renderField(field: TemplateAdminField) {
return ;
if (field.input === "number")
return ;
+ if (field.input === "boolean")
+ return (
+
+ );
+ if (field.input === "select" || field.input === "multi-select")
+ return (
+
+ );
return (
();
const queryClient = useQueryClient();
- 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 navigate = useNavigate();
+ const breakpoints = Grid.useBreakpoint();
+ const [activePage, setActivePage] = useState();
+ const sections = useMemo(() => {
+ const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
+ ...field,
+ binding: field.binding ?? `brand.config.templateData.${field.key}`,
+ }));
+ return [
+ ...(declaredTemplateFields.length
+ ? [
+ {
+ key: "template-data",
+ title: "模板专属内容",
+ description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。",
+ page: templateContent?.templateFields?.[0]?.page ?? "home",
+ target: "brand" as const,
+ fields: declaredTemplateFields,
+ },
+ ]
+ : []),
+ ...(templateContent?.admin.sections ?? []),
+ ]
+ .map((section) => ({
+ ...section,
+ fields: section.fields.filter(
+ (field) =>
+ field.binding.startsWith("brand.config.") ||
+ [
+ "brand.avatarUrl",
+ "brand.description",
+ "brand.contactPhone",
+ "brand.contactWechat",
+ "brand.address",
+ ].includes(field.binding),
+ ),
+ }))
+ .filter((section) => section.fields.length > 0);
+ }, [templateContent]);
+ const pageOptions = useMemo(() => {
+ const pages = new Map();
+ for (const item of templateContent?.navigation ?? []) pages.set(item.page, item.label);
+ for (const section of templateContent?.admin.sections ?? []) {
+ const navigation = templateContent?.navigation.find((item) => item.page === section.page);
+ if (!pages.has(section.page))
+ pages.set(section.page, navigation?.label ?? pageTitle(section.page));
+ }
+ return [...pages].map(([value, label]) => ({ value, label }));
+ }, [templateContent]);
+ const selectedPage = pageOptions.some((item) => item.value === activePage)
+ ? activePage
+ : pageOptions[0]?.value;
+ const visibleSections = sections.filter((section) => section.page === selectedPage);
+ const relatedTargets = [
+ ...(templateContent?.admin.sections ?? [])
+ .filter((section) => section.page === selectedPage && section.target !== "brand")
+ .map((section) => section.target),
+ ...((templateContent?.trustContentTypes ?? []).some((item) =>
+ item.pages?.includes(selectedPage ?? ""),
+ )
+ ? ["trust"]
+ : []),
+ ];
+ const pageLinks = [...new Set(relatedTargets)].flatMap((target) =>
+ target === "trust"
+ ? (templateContent?.trustContentTypes ?? [])
+ .filter((item) => item.pages?.includes(selectedPage ?? ""))
+ .map((item) => ({
+ target: `trust:${item.type}`,
+ label: `编辑${item.label}`,
+ }))
+ : [
+ {
+ target,
+ label: (
+ { offering: "管理此页展示的业务内容", inquiry: "管理此页的咨询表单" } as Record<
+ string,
+ string
+ >
+ )[target],
+ },
+ ],
);
const initialValues = useMemo(() => {
const values: PresentationValues = {};
@@ -105,10 +200,20 @@ export function PresentationEditor({
form.setFieldsValue(initialValues);
}, [form, initialValues]);
+ useEffect(() => {
+ if (!pageOptions.some((item) => item.value === activePage))
+ setActivePage(pageOptions[0]?.value);
+ }, [activePage, pageOptions]);
+
return (
-
+ {templateContent.displayName} : null}
+ style={{ marginTop: 32 }}
+ styles={{ body: { minHeight: breakpoints.md ? 760 : 620 } }}
+ >
- 编辑访客在小程序中看到的文字和图片。不同模板会提供适合本行业的内容项目。
+ 按小程序页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
{loading ? : null}
{error ? (
@@ -119,51 +224,108 @@ export function PresentationEditor({
) : null}
{templateContent ? (
<>
- {templateContent.displayName}
+
+ {breakpoints.xs ? (
+
+ ) : (
+ setActivePage(String(value))}
+ />
+ )}
+
);
}
+
+function pageTitle(page: string): string {
+ return (
+ (
+ {
+ home: "首页",
+ offerings: "业务展示",
+ service: "服务说明",
+ detail: "详情页",
+ inquiry: "咨询页",
+ success: "提交成功页",
+ records: "记录页",
+ profile: "主理人页",
+ } as Record
+ )[page] ?? page
+ );
+}
diff --git a/apps/admin/src/features/brand/presentation-bindings.ts b/apps/admin/src/features/brand/presentation-bindings.ts
index 2b4394c..287b487 100644
--- a/apps/admin/src/features/brand/presentation-bindings.ts
+++ b/apps/admin/src/features/brand/presentation-bindings.ts
@@ -48,7 +48,10 @@ export function readPresentationValue(
? (value as unknown[]).map((item) => ({ [field.itemValueKey as string]: item }))
: value;
}
- return typeof value === "string" || typeof value === "number" ? value : undefined;
+ if (field?.input === "multi-select") return Array.isArray(value) ? value : [];
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean"
+ ? value
+ : undefined;
}
function writePath(
diff --git a/apps/admin/src/features/overview/OverviewPage.tsx b/apps/admin/src/features/overview/OverviewPage.tsx
index 13c3c95..8c8bd6f 100644
--- a/apps/admin/src/features/overview/OverviewPage.tsx
+++ b/apps/admin/src/features/overview/OverviewPage.tsx
@@ -98,7 +98,7 @@ export function OverviewPage() {
item.isPublished).length ?? 0}
suffix="条已发布"
/>
@@ -107,7 +107,7 @@ export function OverviewPage() {
item.isEnabled).length ?? 0}
suffix="项公开"
/>
diff --git a/apps/admin/src/features/publication/PublicationPage.tsx b/apps/admin/src/features/publication/PublicationPage.tsx
index de37025..026fc75 100644
--- a/apps/admin/src/features/publication/PublicationPage.tsx
+++ b/apps/admin/src/features/publication/PublicationPage.tsx
@@ -98,8 +98,12 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
});
const importSample = useMutation({
mutationFn: () => client.importAdminSampleContent(),
- onSuccess: () => {
- message.success("示例内容已导入草稿");
+ onSuccess: ({ counts }) => {
+ message.success(
+ counts.inquiryForms
+ ? "示例内容和客户咨询表单已导入草稿"
+ : "示例内容已导入草稿,现有客户咨询表单已保留",
+ );
refresh();
},
});
@@ -259,9 +263,9 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
.join("、") || "无"}
-
-
-
+
+
+
diff --git a/apps/admin/src/features/services/ServicesPage.tsx b/apps/admin/src/features/services/ServicesPage.tsx
index 22f3c4a..36e4fae 100644
--- a/apps/admin/src/features/services/ServicesPage.tsx
+++ b/apps/admin/src/features/services/ServicesPage.tsx
@@ -1,6 +1,5 @@
import {
Button,
- Card,
Form,
Input,
Modal,
@@ -47,6 +46,18 @@ export function ServicesPage() {
.flatMap((section) =>
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
);
+ const offeringPageLabel =
+ workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
+ "业务展示页";
+ const detailPageLabel =
+ workspace.data?.templateContent?.navigation.find((item) => item.page === "detail")?.label ??
+ "详情页";
+ const detailSections = (workspace.data?.templateContent?.admin.sections ?? []).filter(
+ (section) => section.target === "offering" && section.page === "detail",
+ );
+ const hasTemplateDetailCopy = templateFields.some(
+ (field) => field.binding === "offering.config.details.background",
+ );
const saveOffering = useMutation({
mutationFn: (values: Record) => {
const fields = Object.fromEntries(
@@ -129,15 +140,28 @@ export function ServicesPage() {
}}
>
beginOffering()}>
新增业务提供项
}
/>
- 小程序优先展示}>
+
+
+
+ {offeringPageLabel}中的内容
+
+ 已启用的项目会公开展示
+
+ {detailSections.length ? (
+
+ 编辑单项详情时,附加字段将用于:
+ {detailSections.map((section) => section.title).join("、")}
+ 。列表中的名称、说明、价格和封面也会显示在业务展示页。
+
+ ) : null}
-
+
-
-
-
+ {!hasTemplateDetailCopy ? (
+
+
+
+ ) : null}
diff --git a/apps/admin/src/features/trust-content/TrustContentPage.tsx b/apps/admin/src/features/trust-content/TrustContentPage.tsx
index c0800c5..9bdf1bc 100644
--- a/apps/admin/src/features/trust-content/TrustContentPage.tsx
+++ b/apps/admin/src/features/trust-content/TrustContentPage.tsx
@@ -1,6 +1,6 @@
import {
Button,
- Card,
+ Divider,
Form,
Input,
List,
@@ -14,12 +14,14 @@ import {
message,
} from "antd";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { isTrustContentComplete } from "@personal-brand/api-client";
import type {
TemplateAdminField,
TrustContent,
TrustContentInput,
} from "@personal-brand/api-client";
-import { useState } from "react";
+import { useEffect, useState } from "react";
+import { useSearchParams } from "react-router-dom";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { ImageUrlField } from "../../components/ImageUrlField.js";
@@ -61,14 +63,25 @@ const types = [
type TrustTypeOption = {
type: string;
label: string;
+ adminFields: {
+ title: string;
+ summary: string;
+ content: string;
+ summaryHelp?: string;
+ summaryPlaceholder?: string;
+ };
+ pages?: string[];
help?: string;
placeholder?: string;
required?: boolean;
configFields?: TemplateAdminField[];
+ hideStandardFields?: Array<"summary" | "content">;
+ maxPublishedItems?: number;
};
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
type: value,
label,
+ adminFields: { title: "标题", summary: "摘要", content: "详细内容" },
help,
}));
@@ -78,6 +91,7 @@ export function TrustContentPage() {
const [editing, setEditing] = useState(null);
const [open, setOpen] = useState(false);
const [form] = Form.useForm();
+ const [searchParams] = useSearchParams();
const selectedType = Form.useWatch("type", form);
const query = useQuery({
queryKey: ["trust-content"],
@@ -91,6 +105,21 @@ export function TrustContentPage() {
?.length
? workspace.data.templateContent.trustContentTypes
: fallbackTypes;
+ const pageLabel = (page: string) =>
+ workspace.data?.templateContent?.navigation.find((item) => item.page === page)?.label ??
+ (
+ { home: "首页", offerings: "业务展示页", detail: "详情页", profile: "主理人页" } as Record<
+ string,
+ string
+ >
+ )[page] ??
+ page;
+ const trustPageLabels = [
+ ...new Set(availableTypes.flatMap((item) => item.pages ?? []).map(pageLabel)),
+ ];
+ const trustPlacement = trustPageLabels.length
+ ? `小程序的${trustPageLabels.join("、")}中`
+ : "小程序对应的信任展示区域中";
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
const contentByType = new Map();
for (const item of query.data ?? []) {
@@ -109,13 +138,14 @@ export function TrustContentPage() {
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
availableTypes[0]?.type ??
"credential";
+ const requestedType = searchParams.get("type");
const save = useMutation({
mutationFn: (values: TrustContentInput) =>
editing
? client.updateAdminTrustContent(editing.id, values)
: client.createAdminTrustContent(values),
onSuccess: () => {
- message.success("信任内容已保存");
+ message.success("品牌内容已保存为草稿,发布后小程序才会更新");
setOpen(false);
setEditing(null);
form.resetFields();
@@ -125,7 +155,7 @@ export function TrustContentPage() {
const remove = useMutation({
mutationFn: (id: string) => client.deleteAdminTrustContent(id),
onSuccess: () => {
- message.success("内容已删除");
+ message.success("品牌内容已删除");
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
},
});
@@ -146,6 +176,10 @@ export function TrustContentPage() {
: { type: type ?? firstMissingRequiredType, isPublished: false, config: {} },
);
};
+ useEffect(() => {
+ if (!requestedType || !availableTypes.some((item) => item.type === requestedType)) return;
+ begin(contentByType.get(requestedType), requestedType);
+ }, [requestedType, availableTypes.length]);
return (
void Promise.all([query.refetch(), workspace.refetch()])}
>
begin()}>
- 新增信任内容
+ 添加品牌内容
}
/>
-
+
+
+ 当前模板需要配置的内容
+
- 这些内容会帮助访客判断你是否值得信任。带有“发布必需”的项目需要填写完整后,才能发布小程序。
+ 标记为“发布必填”的项目需要填写完整后,才能发布小程序。
{
const content = contentByType.get(item.type);
- const complete = Boolean(content?.title?.trim() && content?.content?.trim());
+ const publishedCount = (query.data ?? []).filter(
+ (record) => record.type === item.type && record.isPublished,
+ ).length;
+ const tooMany =
+ item.maxPublishedItems !== undefined && publishedCount > item.maxPublishedItems;
+ const complete = Boolean(content && isTrustContentComplete(content, item) && !tooMany);
return (
{item.label}
- {item.required && 发布必需}
+ {item.required && 发布必填}
+ {(item.pages ?? []).map((page) => (
+ {pageLabel(page)}
+ ))}
- {complete ? "内容完整" : content ? "需要完善" : "尚未填写"}
+ {tooMany
+ ? `公开内容过多(${publishedCount} 条)`
+ : complete
+ ? "内容完整"
+ : content
+ ? "需要完善"
+ : "尚未填写"}
{item.help && {item.help}}
@@ -196,15 +247,16 @@ export function TrustContentPage() {
);
}}
/>
-
-
+
+
+
(
{availableTypes.find((item) => item.type === value)?.label ?? value}
@@ -212,15 +264,32 @@ export function TrustContentPage() {
},
{ title: "标题", dataIndex: "title" },
{
- title: "摘要",
- dataIndex: "summary",
- render: (value) => (typeof value === "string" && value ? value : "未填写"),
+ title: "内容预览",
+ ellipsis: { showTitle: true },
+ render: (_value: unknown, item: TrustContent) => {
+ const meta = availableTypes.find((type) => type.type === item.type);
+ if (meta?.hideStandardFields?.includes("content")) {
+ return (
+ meta.configFields
+ ?.flatMap((field) => {
+ const value = item.config?.[field.key];
+ if (Array.isArray(value))
+ return value.length ? [`${field.label}:${value.length} 项`] : [];
+ return typeof value === "string" && value.trim()
+ ? [`${field.label}:${value}`]
+ : [];
+ })
+ .join(";") || "尚未填写区块内容"
+ );
+ }
+ return item.summary || item.content || "未填写";
+ },
},
{
- title: "状态",
+ title: "发布状态",
dataIndex: "isPublished",
render: (value) => (
- {value ? "已公开" : "草稿"}
+ {value ? "随发布展示" : "草稿"}
),
},
{
@@ -232,7 +301,7 @@ export function TrustContentPage() {
remove.mutate(item.id)}
>