refactor: 模板注册与默认模板收敛到目录驱动
This commit is contained in:
1 parent
f87b26b201
commit
89fdfd7d83
25 files changed
+122
-96
No files matched your search
@@ -2,6 +2,7 @@ node_modules/
|
|||||||
.pnpm-store/
|
.pnpm-store/
|
||||||
.turbo/
|
.turbo/
|
||||||
dist/
|
dist/
|
||||||
|
packages/config/dist/
|
||||||
.next/
|
.next/
|
||||||
coverage/
|
coverage/
|
||||||
.env
|
.env
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export function RecordContentEditor({
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate("/admin/brand", {
|
navigate("/admin/brand", {
|
||||||
state: {
|
state: {
|
||||||
targetKey: visualSelection?.targetKey ?? "linjing-editorial.offerings.item",
|
targetKey: visualSelection?.targetKey ?? "offering.list.item",
|
||||||
recordId: record.id,
|
recordId: record.id,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ export function BrandPage() {
|
|||||||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||||||
enabled: Boolean(brand.data?.templateKey),
|
enabled: Boolean(brand.data?.templateKey),
|
||||||
});
|
});
|
||||||
|
const templateCatalog = useQuery({
|
||||||
|
queryKey: ["template-catalog"],
|
||||||
|
queryFn: () => client.listPublicTemplates(),
|
||||||
|
});
|
||||||
const save = useMutation({
|
const save = useMutation({
|
||||||
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@@ -190,10 +194,10 @@ export function BrandPage() {
|
|||||||
>
|
>
|
||||||
<Select
|
<Select
|
||||||
disabled
|
disabled
|
||||||
options={[
|
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
||||||
{ value: "personal", label: "个人品牌" },
|
value: item.key,
|
||||||
{ value: "food", label: "餐饮模板" },
|
label: item.name,
|
||||||
]}
|
}))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
|||||||
import { Alert } from "antd";
|
import { Alert } from "antd";
|
||||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||||
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||||
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
|
||||||
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
|
||||||
import "./ComponentTemplatePreview.css";
|
import "./ComponentTemplatePreview.css";
|
||||||
|
|
||||||
type PreviewProps = {
|
type PreviewProps = {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { TemplatePage as FoodTemplatePage } from "../../../../../packages/template-acheng-campus-food/taro/index.tsx";
|
|
||||||
import { TemplatePage as EditorialTemplatePage } from "../../../../../packages/template-linjing-editorial/taro/index.tsx";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
|
import { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
|
||||||
import { Records } from "../../../../taro/src/components/Records.tsx";
|
import { Records } from "../../../../taro/src/components/Records.tsx";
|
||||||
import { Success } from "../../../../taro/src/components/Success.tsx";
|
import { Success } from "../../../../taro/src/components/Success.tsx";
|
||||||
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||||
|
|
||||||
|
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
|
||||||
|
eager: true,
|
||||||
|
});
|
||||||
|
|
||||||
function pageContent({ workspace, page }) {
|
function pageContent({ workspace, page }) {
|
||||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||||
if (page === "records") return <Records workspace={workspace} preview />;
|
if (page === "records") return <Records workspace={workspace} preview />;
|
||||||
@@ -13,28 +15,22 @@ function pageContent({ workspace, page }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function FoodPreview(props) {
|
|
||||||
return (
|
|
||||||
<TemplateAssetContext.Provider value="acheng-campus-food">
|
|
||||||
<FoodTemplatePage {...props}>{pageContent(props)}</FoodTemplatePage>
|
|
||||||
</TemplateAssetContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
function EditorialPreview(props) {
|
|
||||||
return (
|
|
||||||
<TemplateAssetContext.Provider value="linjing-editorial">
|
|
||||||
<EditorialTemplatePage {...props}>{pageContent(props)}</EditorialTemplatePage>
|
|
||||||
</TemplateAssetContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveTemplateRenderer(workspace) {
|
export function resolveTemplateRenderer(workspace) {
|
||||||
const config = workspace?.brand?.config;
|
const config = workspace?.brand?.config;
|
||||||
const key =
|
const key =
|
||||||
config && typeof config === "object" && !Array.isArray(config)
|
config && typeof config === "object" && !Array.isArray(config)
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: undefined;
|
: undefined;
|
||||||
if (key === "acheng-campus-food") return FoodPreview;
|
if (typeof key !== "string") return null;
|
||||||
if (key === "linjing-editorial") return EditorialPreview;
|
const suffix = `/template-${key}/taro/index.tsx`;
|
||||||
return null;
|
const entry = Object.entries(templateRenderers).find(([path]) => path.endsWith(suffix));
|
||||||
|
const TemplatePage = entry?.[1]?.TemplatePage;
|
||||||
|
if (!TemplatePage) return null;
|
||||||
|
return function TemplatePreview(props) {
|
||||||
|
return (
|
||||||
|
<TemplateAssetContext.Provider value={key}>
|
||||||
|
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
|
||||||
|
</TemplateAssetContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -147,14 +147,16 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
workspace.data?.installations[0]?.templateKey ??
|
workspace.data?.installations[0]?.templateKey ??
|
||||||
workspace.data?.brand?.templateKey ??
|
workspace.data?.brand?.templateKey ??
|
||||||
brand.data?.templateKey ??
|
brand.data?.templateKey ??
|
||||||
"personal";
|
catalog.data?.industries[0]?.key ??
|
||||||
const visuals = (catalog.data?.visuals ?? []).filter((item) =>
|
null;
|
||||||
item.supportedIndustryTemplates.includes(industryKey),
|
const visuals = (catalog.data?.visuals ?? []).filter(
|
||||||
|
(item) =>
|
||||||
|
typeof industryKey === "string" && item.supportedIndustryTemplates.includes(industryKey),
|
||||||
);
|
);
|
||||||
const visualKey =
|
const visualKey =
|
||||||
typeof brand.data?.config?.visualTemplateKey === "string"
|
typeof brand.data?.config?.visualTemplateKey === "string"
|
||||||
? brand.data.config.visualTemplateKey
|
? brand.data.config.visualTemplateKey
|
||||||
: "linjing-editorial";
|
: (visuals[0]?.key ?? null);
|
||||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||||
const publishedHistory = (releases.data ?? []).filter(
|
const publishedHistory = (releases.data ?? []).filter(
|
||||||
(item) => item.status === "published" || item.status === "superseded",
|
(item) => item.status === "published" || item.status === "superseded",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function ServicesPage() {
|
|||||||
const listTarget = previewTargets.offerings.find((target) =>
|
const listTarget = previewTargets.offerings.find((target) =>
|
||||||
templateFields.some((field) => field.previewTarget === target.key),
|
templateFields.some((field) => field.previewTarget === target.key),
|
||||||
) ?? {
|
) ?? {
|
||||||
key: "linjing-editorial.offerings.item",
|
key: "offering.list.item",
|
||||||
label: "业务卡片",
|
label: "业务卡片",
|
||||||
page: "offerings",
|
page: "offerings",
|
||||||
source: "offering",
|
source: "offering",
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ export function WorkspacePage() {
|
|||||||
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
||||||
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
||||||
const [industryTarget, setIndustryTarget] = useState<IndustryTarget | null>(null);
|
const [industryTarget, setIndustryTarget] = useState<IndustryTarget | null>(null);
|
||||||
const [previewIndustry, setPreviewIndustry] = useState<BrandTemplateKey>("personal");
|
const [previewIndustry, setPreviewIndustry] = useState<BrandTemplateKey | null>(null);
|
||||||
const [previewVisual, setPreviewVisual] = useState("linjing-editorial");
|
const [previewVisual, setPreviewVisual] = useState<string | null>(null);
|
||||||
const [form] = Form.useForm<Record<string, unknown>>();
|
const [form] = Form.useForm<Record<string, unknown>>();
|
||||||
const [inquiryForm] = Form.useForm<Record<string, unknown>>();
|
const [inquiryForm] = Form.useForm<Record<string, unknown>>();
|
||||||
const openNewInquiryForm = () => {
|
const openNewInquiryForm = () => {
|
||||||
@@ -69,14 +69,28 @@ export function WorkspacePage() {
|
|||||||
setFormOpen(true);
|
setFormOpen(true);
|
||||||
};
|
};
|
||||||
const { query, runtimeQuery, templateCatalog, forms, templatePreview } = useWorkspaceQueries();
|
const { query, runtimeQuery, templateCatalog, forms, templatePreview } = useWorkspaceQueries();
|
||||||
|
const previewIndustryKey =
|
||||||
|
previewIndustry ??
|
||||||
|
query.data?.installations[0]?.templateKey ??
|
||||||
|
query.data?.brand.templateKey ??
|
||||||
|
templateCatalog.data?.industries[0]?.key;
|
||||||
|
const previewVisualKey =
|
||||||
|
previewVisual ??
|
||||||
|
runtimeQuery.data?.visualTemplate?.key ??
|
||||||
|
(templateCatalog.data?.visuals ?? []).find((visual) =>
|
||||||
|
supportsIndustry(visual, previewIndustryKey ?? ""),
|
||||||
|
)?.key;
|
||||||
const combinationPreview = useQuery({
|
const combinationPreview = useQuery({
|
||||||
queryKey: ["template-combination-preview", previewIndustry, previewVisual],
|
queryKey: ["template-combination-preview", previewIndustryKey, previewVisualKey],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
createApiClient().previewPublicTemplateCombination(previewIndustry, previewVisual),
|
createApiClient().previewPublicTemplateCombination(
|
||||||
enabled: Boolean(templateCatalog.data),
|
previewIndustryKey ?? "",
|
||||||
|
previewVisualKey ?? "",
|
||||||
|
),
|
||||||
|
enabled: Boolean(templateCatalog.data && previewIndustryKey && previewVisualKey),
|
||||||
});
|
});
|
||||||
const compatibleVisuals = (templateCatalog.data?.visuals ?? []).filter((visual) =>
|
const compatibleVisuals = (templateCatalog.data?.visuals ?? []).filter((visual) =>
|
||||||
supportsIndustry(visual, query.data?.brand?.templateKey ?? "personal"),
|
supportsIndustry(visual, query.data?.brand?.templateKey ?? ""),
|
||||||
);
|
);
|
||||||
const { visualTemplate, rollbackVisual, install, upgrade, rollback } = useTemplateMutations({
|
const { visualTemplate, rollbackVisual, install, upgrade, rollback } = useTemplateMutations({
|
||||||
runtimeConfig: runtimeQuery.data?.brand?.config ?? undefined,
|
runtimeConfig: runtimeQuery.data?.brand?.config ?? undefined,
|
||||||
@@ -185,9 +199,9 @@ export function WorkspacePage() {
|
|||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Typography.Text strong>视觉模板</Typography.Text>
|
<Typography.Text strong>视觉模板</Typography.Text>
|
||||||
<Select
|
<Select
|
||||||
value={runtimeQuery.data?.visualTemplate?.key ?? "linjing-editorial"}
|
value={runtimeQuery.data?.visualTemplate?.key}
|
||||||
loading={visualTemplate.isPending}
|
loading={visualTemplate.isPending}
|
||||||
onChange={(key) => setVisualTarget(key)}
|
onChange={(key) => setVisualTarget(key ?? null)}
|
||||||
options={[
|
options={[
|
||||||
...compatibleVisuals.map((visual) => ({ value: visual.key, label: visual.name })),
|
...compatibleVisuals.map((visual) => ({ value: visual.key, label: visual.name })),
|
||||||
]}
|
]}
|
||||||
@@ -354,18 +368,18 @@ export function WorkspacePage() {
|
|||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Select
|
<Select
|
||||||
value={previewIndustry}
|
value={previewIndustryKey ?? null}
|
||||||
onChange={setPreviewIndustry}
|
onChange={(key) => setPreviewIndustry(key)}
|
||||||
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
||||||
value: item.key,
|
value: item.key,
|
||||||
label: item.name,
|
label: item.name,
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
value={previewVisual}
|
value={previewVisualKey ?? null}
|
||||||
onChange={setPreviewVisual}
|
onChange={(key) => setPreviewVisual(key)}
|
||||||
options={(templateCatalog.data?.visuals ?? [])
|
options={(templateCatalog.data?.visuals ?? [])
|
||||||
.filter((item) => supportsIndustry(item, previewIndustry))
|
.filter((item) => supportsIndustry(item, previewIndustryKey ?? ""))
|
||||||
.map((item) => ({ value: item.key, label: item.name }))}
|
.map((item) => ({ value: item.key, label: item.name }))}
|
||||||
/>
|
/>
|
||||||
</Space>
|
</Space>
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ import {
|
|||||||
Max,
|
Max,
|
||||||
Min,
|
Min,
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
|
import { brandTemplateKeys } from "@personal-brand/config";
|
||||||
|
import type { BrandTemplateKey } from "@personal-brand/config";
|
||||||
|
|
||||||
export class UpdateBrandDto {
|
export class UpdateBrandDto {
|
||||||
@IsOptional() @IsString() name?: string;
|
@IsOptional() @IsString() name?: string;
|
||||||
@IsOptional() @IsIn(["food", "personal", "doors"]) templateKey?: "food" | "personal" | "doors";
|
@IsOptional() @IsIn(brandTemplateKeys) templateKey?: BrandTemplateKey;
|
||||||
@IsOptional() @IsString() tagline?: string;
|
@IsOptional() @IsString() tagline?: string;
|
||||||
@IsOptional() @IsString() description?: string;
|
@IsOptional() @IsString() description?: string;
|
||||||
@IsOptional() @IsString() avatarUrl?: string;
|
@IsOptional() @IsString() avatarUrl?: string;
|
||||||
@@ -101,8 +103,8 @@ export class UpdateBookingTagsDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class InstallTemplateDto {
|
export class InstallTemplateDto {
|
||||||
@IsIn(["personal", "food", "doors"])
|
@IsIn(brandTemplateKeys)
|
||||||
templateKey!: "personal" | "food" | "doors";
|
templateKey!: BrandTemplateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateCapabilityInstallationDto {
|
export class UpdateCapabilityInstallationDto {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import {
|
import {
|
||||||
|
defaultBrandTemplateKey,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
isVisualTemplateCompatible,
|
isVisualTemplateCompatible,
|
||||||
@@ -67,7 +68,7 @@ export class BrandReleaseApiService {
|
|||||||
const visualKey =
|
const visualKey =
|
||||||
typeof config.visualTemplateKey === "string"
|
typeof config.visualTemplateKey === "string"
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||||
const visual = getVisualTemplate(visualKey);
|
const visual = getVisualTemplate(visualKey);
|
||||||
const packageManifest = getTemplatePackageManifestForVisualKey(visualKey);
|
const packageManifest = getTemplatePackageManifestForVisualKey(visualKey);
|
||||||
const [offerings, forms, trustItems] = await Promise.all([
|
const [offerings, forms, trustItems] = await Promise.all([
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import {
|
import {
|
||||||
|
defaultBrandTemplateKey,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
getVisualTemplateManifest,
|
getVisualTemplateManifest,
|
||||||
@@ -44,7 +45,7 @@ export async function buildBrandReleaseSnapshot(
|
|||||||
database.trustContent.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }),
|
database.trustContent.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }),
|
||||||
database.capabilityInstallation.findMany({ where: { brandId } }),
|
database.capabilityInstallation.findMany({ where: { brandId } }),
|
||||||
]);
|
]);
|
||||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
const templateKey = installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey;
|
||||||
const config =
|
const config =
|
||||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||||
? (brand.config as Record<string, unknown>)
|
? (brand.config as Record<string, unknown>)
|
||||||
@@ -52,7 +53,7 @@ export async function buildBrandReleaseSnapshot(
|
|||||||
const visualKey =
|
const visualKey =
|
||||||
typeof config.visualTemplateKey === "string"
|
typeof config.visualTemplateKey === "string"
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||||
const jsonObject = (value: object): Record<string, unknown> =>
|
const jsonObject = (value: object): Record<string, unknown> =>
|
||||||
JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
|
JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
UpdateTrustContentDto,
|
UpdateTrustContentDto,
|
||||||
} from "../../admin.dto.js";
|
} from "../../admin.dto.js";
|
||||||
import {
|
import {
|
||||||
|
defaultVisualTemplateKey,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
isVisualTemplateCompatible,
|
isVisualTemplateCompatible,
|
||||||
@@ -278,7 +279,7 @@ export class AdminConfigController {
|
|||||||
const currentKey =
|
const currentKey =
|
||||||
typeof config.visualTemplateKey === "string"
|
typeof config.visualTemplateKey === "string"
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: "linjing-editorial";
|
: defaultVisualTemplateKey;
|
||||||
const current = getVisualTemplate(currentKey);
|
const current = getVisualTemplate(currentKey);
|
||||||
return {
|
return {
|
||||||
current: current
|
current: current
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { BrandReleaseSnapshot } from "../../brand-release.service.js";
|
|||||||
import type { Prisma } from "@prisma/client";
|
import type { Prisma } from "@prisma/client";
|
||||||
import {
|
import {
|
||||||
capabilityPlugins,
|
capabilityPlugins,
|
||||||
|
defaultBrandTemplateKey,
|
||||||
type BrandTemplateKey,
|
type BrandTemplateKey,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getDefaultVisualTemplateKey,
|
getDefaultVisualTemplateKey,
|
||||||
@@ -96,7 +97,7 @@ export function assemblePublicWorkspace(input: {
|
|||||||
asString(releaseSnapshot.templateKey) ||
|
asString(releaseSnapshot.templateKey) ||
|
||||||
asString(installationData.templateKey) ||
|
asString(installationData.templateKey) ||
|
||||||
asString(brandData.templateKey) ||
|
asString(brandData.templateKey) ||
|
||||||
"personal";
|
defaultBrandTemplateKey;
|
||||||
const template = releaseSnapshot.templateDefinition ?? getBrandTemplate(templateKey);
|
const template = releaseSnapshot.templateDefinition ?? getBrandTemplate(templateKey);
|
||||||
const capabilityData = asArray(releaseSnapshot.capabilities) as Array<Record<string, unknown>>;
|
const capabilityData = asArray(releaseSnapshot.capabilities) as Array<Record<string, unknown>>;
|
||||||
const capabilities = capabilityData.length
|
const capabilities = capabilityData.length
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/comm
|
|||||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
import { BrandReleaseService } from "../../brand-release.service.js";
|
import { BrandReleaseService } from "../../brand-release.service.js";
|
||||||
import {
|
import {
|
||||||
|
defaultBrandTemplateKey,
|
||||||
|
defaultVisualTemplateKey,
|
||||||
brandTemplates,
|
brandTemplates,
|
||||||
|
brandTemplateKeys,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
isVisualTemplateCompatible,
|
isVisualTemplateCompatible,
|
||||||
resolveCapabilities,
|
resolveCapabilities,
|
||||||
visualTemplates,
|
visualTemplates,
|
||||||
|
visualTemplateKeys,
|
||||||
} from "@personal-brand/config";
|
} from "@personal-brand/config";
|
||||||
|
|
||||||
@Controller("public")
|
@Controller("public")
|
||||||
@@ -74,15 +78,15 @@ export class PublicTemplateController {
|
|||||||
@Get()
|
@Get()
|
||||||
list(): unknown {
|
list(): unknown {
|
||||||
return {
|
return {
|
||||||
industries: Object.values(brandTemplates),
|
industries: brandTemplateKeys.map((key) => brandTemplates[key]),
|
||||||
visuals: Object.values(visualTemplates),
|
visuals: visualTemplateKeys.map((key) => visualTemplates[key]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("preview")
|
@Get("preview")
|
||||||
preview(
|
preview(
|
||||||
@Query("industry") industry = "personal",
|
@Query("industry") industry = defaultBrandTemplateKey,
|
||||||
@Query("visual") visual = "linjing-editorial",
|
@Query("visual") visual = defaultVisualTemplateKey,
|
||||||
): unknown {
|
): unknown {
|
||||||
const industryTemplate = getBrandTemplate(industry);
|
const industryTemplate = getBrandTemplate(industry);
|
||||||
const visualTemplate = getVisualTemplate(visual);
|
const visualTemplate = getVisualTemplate(visual);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
import {
|
import {
|
||||||
|
defaultBrandTemplateKey,
|
||||||
getDefaultVisualTemplateKey,
|
getDefaultVisualTemplateKey,
|
||||||
getTemplatePackageManifestForVisualKey,
|
getTemplatePackageManifestForVisualKey,
|
||||||
} from "@personal-brand/config";
|
} from "@personal-brand/config";
|
||||||
@@ -28,7 +29,7 @@ export class AdminWorkspaceService {
|
|||||||
const templateKey =
|
const templateKey =
|
||||||
typeof config.visualTemplateKey === "string"
|
typeof config.visualTemplateKey === "string"
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||||
const manifest = getTemplatePackageManifestForVisualKey(templateKey);
|
const manifest = getTemplatePackageManifestForVisualKey(templateKey);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import {
|
import {
|
||||||
|
type BrandTemplateKey,
|
||||||
|
defaultBrandTemplateKey,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
getVisualTemplateManifest,
|
getVisualTemplateManifest,
|
||||||
@@ -9,7 +11,6 @@ import {
|
|||||||
isVisualTemplateCompatible,
|
isVisualTemplateCompatible,
|
||||||
} from "@personal-brand/config";
|
} from "@personal-brand/config";
|
||||||
import type { CreateTrustContentDto, UpdateTrustContentDto } from "./admin.dto.js";
|
import type { CreateTrustContentDto, UpdateTrustContentDto } from "./admin.dto.js";
|
||||||
import type { BrandTemplateKey } from "@personal-brand/types";
|
|
||||||
import { PrismaService } from "./prisma.service.js";
|
import { PrismaService } from "./prisma.service.js";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -27,7 +28,7 @@ export class TemplateWorkspaceService {
|
|||||||
const visualKey =
|
const visualKey =
|
||||||
typeof config.visualTemplateKey === "string"
|
typeof config.visualTemplateKey === "string"
|
||||||
? config.visualTemplateKey
|
? config.visualTemplateKey
|
||||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||||
return (
|
return (
|
||||||
getTemplatePackageManifestForVisualKey(visualKey)?.trustContentTypes?.map(
|
getTemplatePackageManifestForVisualKey(visualKey)?.trustContentTypes?.map(
|
||||||
(item) => item.type,
|
(item) => item.type,
|
||||||
@@ -72,10 +73,12 @@ export class TemplateWorkspaceService {
|
|||||||
select: { templateKey: true },
|
select: { templateKey: true },
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
const key = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
const key =
|
||||||
return getBrandTemplate(key) ? (key as BrandTemplateKey) : "personal";
|
getBrandTemplate(installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey)
|
||||||
|
?.key ?? defaultBrandTemplateKey;
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
async install(brandId: string, templateKey: "personal" | "food" | "doors") {
|
async install(brandId: string, templateKey: BrandTemplateKey) {
|
||||||
const template = getBrandTemplate(templateKey);
|
const template = getBrandTemplate(templateKey);
|
||||||
if (!template) throw new BadRequestException("行业模板不存在");
|
if (!template) throw new BadRequestException("行业模板不存在");
|
||||||
const [existing, brand] = await Promise.all([
|
const [existing, brand] = await Promise.all([
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ export function Inquiry({
|
|||||||
const [sending, setSending] = useState(false);
|
const [sending, setSending] = useState(false);
|
||||||
const busy = useRef(false);
|
const busy = useRef(false);
|
||||||
const p = presentation(workspace, "inquiry");
|
const p = presentation(workspace, "inquiry");
|
||||||
const food = workspace.brand.visualTemplateKey === "acheng-campus-food";
|
const compactFieldKeys = new Set(["people", "date", "budget", "delivery"]);
|
||||||
|
const compactForm = Boolean(form?.fields.some((field) => compactFieldKeys.has(field.key)));
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
const query = takeQuery("inquiry");
|
const query = takeQuery("inquiry");
|
||||||
if (query.offeringId) setOfferingId(query.offeringId);
|
if (query.offeringId) setOfferingId(query.offeringId);
|
||||||
@@ -82,7 +83,7 @@ export function Inquiry({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<View className={`inquiry-page ${food ? "food-inquiry" : "editorial-inquiry"}`}>
|
<View className={`inquiry-page ${compactForm ? "food-inquiry" : "editorial-inquiry"}`}>
|
||||||
<View className="form-intro">
|
<View className="form-intro">
|
||||||
<Text className="eyebrow">{p.eyebrow}</Text>
|
<Text className="eyebrow">{p.eyebrow}</Text>
|
||||||
<Text className="form-title">{p.title || "提交咨询"}</Text>
|
<Text className="form-title">{p.title || "提交咨询"}</Text>
|
||||||
@@ -98,10 +99,10 @@ export function Inquiry({
|
|||||||
const value = values[field.key];
|
const value = values[field.key];
|
||||||
const stringValue = typeof value === "string" ? value : "";
|
const stringValue = typeof value === "string" ? value : "";
|
||||||
const chips =
|
const chips =
|
||||||
food && field.key === "type" && ["select", "radio"].includes(field.type);
|
compactForm && field.key === "type" && ["select", "radio"].includes(field.type);
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
|
className={`form-field ${compactForm && compactFieldKeys.has(field.key) ? "half-field" : ""}`}
|
||||||
key={field.key}
|
key={field.key}
|
||||||
data-editor-target={preview ? `inquiry-field:${field.key}` : undefined}
|
data-editor-target={preview ? `inquiry-field:${field.key}` : undefined}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export interface TemplateMethods {
|
|||||||
templateContent: AdminTemplateContent | null;
|
templateContent: AdminTemplateContent | null;
|
||||||
}>;
|
}>;
|
||||||
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
||||||
installAdminTemplate(templateKey: "personal" | "food" | "doors"): Promise<unknown>;
|
installAdminTemplate(templateKey: BrandTemplateKey): Promise<unknown>;
|
||||||
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
||||||
updateAdminCapability(
|
updateAdminCapability(
|
||||||
key: string,
|
key: string,
|
||||||
@@ -111,8 +111,7 @@ export function templateMethods({ request }: { request: RequestFn }): TemplateMe
|
|||||||
description: String(visual.description ?? ""),
|
description: String(visual.description ?? ""),
|
||||||
supportedIndustryTemplates: Array.isArray(visual.supportedIndustryTemplates)
|
supportedIndustryTemplates: Array.isArray(visual.supportedIndustryTemplates)
|
||||||
? visual.supportedIndustryTemplates.filter(
|
? visual.supportedIndustryTemplates.filter(
|
||||||
(item): item is BrandTemplateKey =>
|
(item): item is BrandTemplateKey => typeof item === "string",
|
||||||
item === "personal" || item === "food" || item === "doors",
|
|
||||||
)
|
)
|
||||||
: [],
|
: [],
|
||||||
variants:
|
variants:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface BrandTemplateDefinition {
|
export interface BrandTemplateDefinition {
|
||||||
key: "personal" | "food" | "doors";
|
key: string;
|
||||||
version: string;
|
version: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
@@ -135,5 +135,9 @@ export function isBrandTemplateKey(value: string): value is BrandTemplateKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined {
|
export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined {
|
||||||
return isBrandTemplateKey(key) ? brandTemplates[key] : undefined;
|
return isBrandTemplateKey(key) ? brandTemplates[key as keyof typeof brandTemplates] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultBrandTemplateKey = "personal" satisfies BrandTemplateKey;
|
||||||
|
|
||||||
|
export const brandTemplateKeys = Object.keys(brandTemplates);
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
export type BrandTemplateKey = "personal" | "food" | "doors";
|
export type BrandTemplateKey = string;
|
||||||
export type VisualTemplateKey = "linjing-editorial" | "acheng-campus-food";
|
export type VisualTemplateKey = string;
|
||||||
export type CapabilityKey = "offerings" | "inquiry" | "booking" | "quote-request";
|
export type CapabilityKey = "offerings" | "inquiry" | "booking" | "quote-request";
|
||||||
@@ -130,15 +130,15 @@ const personalSampleContent: TemplateSampleContent = {
|
|||||||
capabilityKey: "inquiry",
|
capabilityKey: "inquiry",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const templateSampleContent: Record<BrandTemplateKey, TemplateSampleContent> = {
|
export const templateSampleContent = {
|
||||||
personal: personalSampleContent,
|
personal: personalSampleContent,
|
||||||
food: foodSampleContent,
|
food: foodSampleContent,
|
||||||
doors: doorsSampleContent,
|
doors: doorsSampleContent,
|
||||||
};
|
} as const;
|
||||||
|
|
||||||
export function getTemplateSampleContent(templateKey: string): TemplateSampleContent | undefined {
|
export function getTemplateSampleContent(templateKey: string): TemplateSampleContent | undefined {
|
||||||
const packageSample = templatePackageRegistry.find((item) =>
|
const packageSample = templatePackageRegistry.find((item) =>
|
||||||
item.supportedIndustryTemplates.includes(templateKey as BrandTemplateKey),
|
item.supportedIndustryTemplates.includes(templateKey),
|
||||||
)?.sampleContent?.[templateKey as BrandTemplateKey];
|
)?.sampleContent?.[templateKey];
|
||||||
return packageSample ?? templateSampleContent[templateKey as keyof typeof templateSampleContent];
|
return packageSample ?? templateSampleContent[templateKey as keyof typeof templateSampleContent];
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { BrandTemplateKey } from "./template-keys.js";
|
|
||||||
import type { VisualTemplateKey } from "./template-keys.js";
|
import type { VisualTemplateKey } from "./template-keys.js";
|
||||||
import type { VisualTemplateDefinition, VisualTemplateManifest } from "./brand-contracts.js";
|
import type { VisualTemplateDefinition, VisualTemplateManifest } from "./brand-contracts.js";
|
||||||
|
|
||||||
@@ -269,14 +268,12 @@ export const visualTemplateManifests: Record<VisualTemplateKey, VisualTemplateMa
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function getVisualTemplateManifest(key: string): VisualTemplateManifest | undefined {
|
export function getVisualTemplateManifest(key: string): VisualTemplateManifest | undefined {
|
||||||
return visualTemplateManifests[key as VisualTemplateKey];
|
return visualTemplateManifests[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isVisualTemplateCompatible(
|
export function isVisualTemplateCompatible(
|
||||||
visualTemplate: VisualTemplateDefinition | VisualTemplateManifest,
|
visualTemplate: VisualTemplateDefinition | VisualTemplateManifest,
|
||||||
industryTemplateKey: string,
|
industryTemplateKey: string,
|
||||||
): boolean {
|
): boolean {
|
||||||
return visualTemplate.supportedIndustryTemplates.includes(
|
return visualTemplate.supportedIndustryTemplates.includes(industryTemplateKey);
|
||||||
industryTemplateKey as BrandTemplateKey,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { BrandTemplateKey } from "./template-keys.js";
|
|
||||||
import type { VisualTemplateKey } from "./template-keys.js";
|
import type { VisualTemplateKey } from "./template-keys.js";
|
||||||
import type { VisualTemplateDefinition } from "./brand-contracts.js";
|
import type { VisualTemplateDefinition } from "./brand-contracts.js";
|
||||||
|
|
||||||
@@ -42,19 +41,21 @@ export const visualTemplates: Record<VisualTemplateKey, VisualTemplateDefinition
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function listVisualTemplateKeys(): VisualTemplateKey[] {
|
export function listVisualTemplateKeys(): VisualTemplateKey[] {
|
||||||
return Object.keys(visualTemplates) as VisualTemplateKey[];
|
return Object.keys(visualTemplates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const visualTemplateKeys = listVisualTemplateKeys();
|
||||||
|
|
||||||
export function getVisualTemplate(key: string): VisualTemplateDefinition | undefined {
|
export function getVisualTemplate(key: string): VisualTemplateDefinition | undefined {
|
||||||
return visualTemplates[key as VisualTemplateKey];
|
return visualTemplates[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultVisualTemplateKey(industryTemplateKey: string): VisualTemplateKey {
|
export function getDefaultVisualTemplateKey(industryTemplateKey: string): VisualTemplateKey {
|
||||||
return (
|
return (
|
||||||
listVisualTemplateKeys().find((key) =>
|
listVisualTemplateKeys().find((key) =>
|
||||||
visualTemplates[key].supportedIndustryTemplates.includes(
|
getVisualTemplate(key)?.supportedIndustryTemplates.includes(industryTemplateKey),
|
||||||
industryTemplateKey as BrandTemplateKey,
|
) ?? defaultVisualTemplateKey
|
||||||
),
|
|
||||||
) ?? "linjing-editorial"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultVisualTemplateKey = "linjing-editorial" satisfies VisualTemplateKey;
|
||||||
@@ -3,12 +3,7 @@ export type BookingRequestType = "package" | "private_chef" | "inquiry";
|
|||||||
export type ContactPreference = "wechat" | "phone" | "none";
|
export type ContactPreference = "wechat" | "phone" | "none";
|
||||||
export type FulfillmentType = "pickup" | "delivery";
|
export type FulfillmentType = "pickup" | "delivery";
|
||||||
export type OrderStatus = BookingStatus;
|
export type OrderStatus = BookingStatus;
|
||||||
export type BrandTemplateKey = "food" | "personal" | "doors";
|
export type BrandTemplateKey = string;
|
||||||
export const BRAND_TEMPLATE = {
|
|
||||||
FOOD: "food",
|
|
||||||
PERSONAL: "personal",
|
|
||||||
DOORS: "doors",
|
|
||||||
} as const satisfies Record<Uppercase<BrandTemplateKey>, BrandTemplateKey>;
|
|
||||||
|
|
||||||
export const HTTP_STATUS = {
|
export const HTTP_STATUS = {
|
||||||
OK: 200,
|
OK: 200,
|
||||||
|
|||||||
Reference in new issue
Block a user