refactor: 拆分业务、信任内容与公共工作台模块
This commit is contained in:
1 parent
357f271639
commit
466dc66907
33 files changed
+4950
-4500
No files matched your search
@@ -0,0 +1,117 @@
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
import type { TrustContent } from "@personal-brand/api-client";
|
||||
|
||||
export 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 fallbackTypeSeeds = [
|
||||
{
|
||||
value: "schedule",
|
||||
label: "时间与服务安排",
|
||||
help: "说明你通常什么时候提供服务、接受预约或处理订单。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "coverage",
|
||||
label: "服务范围与方式",
|
||||
help: "说明服务地点、覆盖范围、适用对象或承接边界。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "process",
|
||||
label: "合作流程",
|
||||
help: "说明客户从提出需求到完成合作会经历哪些步骤,每行写一步。",
|
||||
},
|
||||
{
|
||||
value: "credential",
|
||||
label: "资质与专业证明",
|
||||
help: "说明资质、经验、制作标准或让客户放心的专业依据。",
|
||||
},
|
||||
{
|
||||
value: "case",
|
||||
label: "案例与客户反馈",
|
||||
help: "写代表性案例、服务结果或客户评价,多条内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "promise",
|
||||
label: "服务承诺与响应说明",
|
||||
help: "说明回复时间、交付承诺、售后方式或合作预期。",
|
||||
},
|
||||
];
|
||||
|
||||
export const fallbackTrustTypes: TrustTypeOption[] = fallbackTypeSeeds.map(
|
||||
({ value, label, help }) => ({
|
||||
type: value,
|
||||
label,
|
||||
adminFields: { title: "标题", summary: "摘要", content: "详细内容" },
|
||||
help,
|
||||
}),
|
||||
);
|
||||
|
||||
const pageLabels: Record<string, string> = {
|
||||
home: "首页",
|
||||
offerings: "业务展示页",
|
||||
detail: "详情页",
|
||||
profile: "主理人页",
|
||||
};
|
||||
|
||||
export function createTrustPageLabelResolver(navigation?: Array<{ page: string; label: string }>) {
|
||||
return (page: string) =>
|
||||
navigation?.find((item) => item.page === page)?.label ?? pageLabels[page] ?? page;
|
||||
}
|
||||
|
||||
export function selectTrustTypeOptions(workspaceTypes?: TrustTypeOption[]): TrustTypeOption[] {
|
||||
return workspaceTypes?.length ? workspaceTypes : fallbackTrustTypes;
|
||||
}
|
||||
|
||||
export function groupTrustContentByType(items: TrustContent[]) {
|
||||
const contentByType = new Map<string, TrustContent>();
|
||||
|
||||
for (const item of items) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return contentByType;
|
||||
}
|
||||
|
||||
export function getTrustContentPreview(item: TrustContent, typeMeta?: TrustTypeOption): string {
|
||||
if (typeMeta?.hideStandardFields?.includes("content")) {
|
||||
return (
|
||||
typeMeta.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 || "未填写";
|
||||
}
|
||||
Reference in new issue
Block a user