refactor: 统一模板契约并修复预览版本

This commit is contained in:
que01 committed 2026-10-18 17:09:09 +08:00
1 parent cd2992c00a
commit 50b87e48de
56 files changed
+7849 -5756

No files matched your search

+6 -3
View File
@@ -1,9 +1,12 @@
export function resolvePreviewRenderer<T>(
modules: Record<string, T>,
config: unknown,
workspace: unknown,
): T | undefined {
if (!config || typeof config !== "object" || Array.isArray(config)) return undefined;
const key = (config as Record<string, unknown>).visualTemplateKey;
if (!workspace || typeof workspace !== "object" || Array.isArray(workspace)) return undefined;
const visualTemplate = (workspace as Record<string, unknown>).visualTemplate;
if (!visualTemplate || typeof visualTemplate !== "object" || Array.isArray(visualTemplate))
return undefined;
const key = (visualTemplate as Record<string, unknown>).key;
if (typeof key !== "string" || !key) return undefined;
const suffix = `/template-${key}/taro/index.tsx`;
return Object.entries(modules).find(([path]) => path.endsWith(suffix))?.[1];
@@ -9,7 +9,7 @@ const renderers = import.meta.glob<{
}>("../../../../packages/template-*/taro/index.tsx", { eager: true });
export function TemplatePage(props: TemplateProps) {
const rendererModule = resolvePreviewRenderer(renderers, props.workspace.brand.config);
const rendererModule = resolvePreviewRenderer(renderers, props.workspace);
if (!rendererModule)
return <div className="runtime-state">当前模板没有可用的 H5 预览 renderer</div>;
const Renderer = rendererModule.TemplatePage;