fix: 完善工坊模板安装预览与详情样例
This commit is contained in:
1 parent
5313fd9d32
commit
50753db79d
16 files changed
+496
-26
No files matched your search
@@ -11,7 +11,8 @@ export const routes = {
|
||||
};
|
||||
export type PageKey = keyof typeof routes;
|
||||
export function navigate(page: PageKey, params: Record<string, string> = {}) {
|
||||
const isTab = TEMPLATE_MANIFEST.navigation.some((tab) => tab.page === page);
|
||||
const isTab =
|
||||
!PREVIEW_ALL_TEMPLATES && TEMPLATE_MANIFEST.navigation.some((tab) => tab.page === page);
|
||||
if (isTab) {
|
||||
Taro.setStorageSync(`routeQuery:${page}`, params);
|
||||
void Taro.switchTab({ url: routes[page] });
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export function resolvePreviewRenderer<T>(
|
||||
modules: Record<string, T>,
|
||||
config: unknown,
|
||||
): T | undefined {
|
||||
if (!config || typeof config !== "object" || Array.isArray(config)) return undefined;
|
||||
const key = (config as Record<string, unknown>).visualTemplateKey;
|
||||
if (typeof key !== "string" || !key) return undefined;
|
||||
const suffix = `/template-${key}/taro/index.tsx`;
|
||||
return Object.entries(modules).find(([path]) => path.endsWith(suffix))?.[1];
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { TemplateProps } from "./template";
|
||||
import { resolvePreviewRenderer } from "./preview-renderer";
|
||||
|
||||
type TemplateRenderer = ComponentType<TemplateProps>;
|
||||
|
||||
@@ -8,8 +9,7 @@ const renderers = import.meta.glob<{
|
||||
}>("../../../../packages/template-*/taro/index.tsx", { eager: true });
|
||||
|
||||
export function TemplatePage(props: TemplateProps) {
|
||||
const suffix = `/template-${TEMPLATE_KEY}/taro/index.tsx`;
|
||||
const rendererModule = Object.entries(renderers).find(([path]) => path.endsWith(suffix))?.[1];
|
||||
const rendererModule = resolvePreviewRenderer(renderers, props.workspace.brand.config);
|
||||
if (!rendererModule)
|
||||
return <div className="runtime-state">当前模板没有可用的 H5 预览 renderer</div>;
|
||||
const Renderer = rendererModule.TemplatePage;
|
||||
|
||||
Reference in new issue
Block a user