refactor: 模板注册与默认模板收敛到目录驱动

This commit is contained in:
que01 committed 2026-10-12 10:00:46 +08:00
1 parent f87b26b201
commit 89fdfd7d83
25 files changed
+122 -96

No files matched your search

+8 -4
View File
@@ -48,6 +48,10 @@ export function BrandPage() {
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
enabled: Boolean(brand.data?.templateKey),
});
const templateCatalog = useQuery({
queryKey: ["template-catalog"],
queryFn: () => client.listPublicTemplates(),
});
const save = useMutation({
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
onSuccess: () => {
@@ -190,10 +194,10 @@ export function BrandPage() {
>
<Select
disabled
options={[
{ value: "personal", label: "个人品牌" },
{ value: "food", label: "餐饮模板" },
]}
options={(templateCatalog.data?.industries ?? []).map((item) => ({
value: item.key,
label: item.name,
}))}
/>
</Form.Item>
<Row gutter={16}>
@@ -3,8 +3,6 @@ import type { RuntimeWorkspace } from "@personal-brand/api-client";
import { Alert } from "antd";
import { resolveTemplateRenderer } from "./component-renderers.jsx";
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";
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 { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
import { Records } from "../../../../taro/src/components/Records.tsx";
import { Success } from "../../../../taro/src/components/Success.tsx";
import { TemplateAssetContext } from "./taro-web-components.jsx";
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
eager: true,
});
function pageContent({ workspace, page }) {
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
if (page === "records") return <Records workspace={workspace} preview />;
@@ -13,28 +15,22 @@ function pageContent({ workspace, page }) {
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) {
const config = workspace?.brand?.config;
const key =
config && typeof config === "object" && !Array.isArray(config)
? config.visualTemplateKey
: undefined;
if (key === "acheng-campus-food") return FoodPreview;
if (key === "linjing-editorial") return EditorialPreview;
return null;
if (typeof key !== "string") return null;
const suffix = `/template-${key}/taro/index.tsx`;
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>
);
};
}