feat: 建立组件化模板预览基线并规划可视化编辑

This commit is contained in:
que01 committed 2026-10-09 12:32:24 +08:00
1 parent c5af790554
commit 0b14b5a814
46 files changed
+1880 -427

No files matched your search

+31 -9
View File
@@ -8,19 +8,22 @@ const Context = createContext<{
error: string;
loading: boolean;
setBrandDraft: (brand: Partial<RuntimeWorkspace["brand"]>) => void;
setWorkspaceDraft: (workspace: RuntimeWorkspace) => void;
reload: () => void;
}>({ error: "", loading: true, setBrandDraft() {}, reload() {} });
}>({ error: "", loading: true, setBrandDraft() {}, setWorkspaceDraft() {}, reload() {} });
export function WorkspaceProvider({ children }: PropsWithChildren) {
const [baseWorkspace, setBaseWorkspace] = useState<RuntimeWorkspace>();
const [brandDraft, setBrandDraft] = useState<Partial<RuntimeWorkspace["brand"]>>({});
const workspace = baseWorkspace
const [workspaceDraft, setWorkspaceDraft] = useState<RuntimeWorkspace>();
const workspace = workspaceDraft ?? baseWorkspace;
const resolvedWorkspace = workspace
? {
...baseWorkspace,
...workspace,
brand: projectBrandAliases(
{ ...baseWorkspace.brand, ...brandDraft },
{ ...workspace.brand, ...brandDraft },
brandDraft.config && typeof brandDraft.config === "object"
? (brandDraft.config as Record<string, unknown>)
: ((baseWorkspace.brand.config as Record<string, unknown> | undefined) ?? {}),
: ((workspace.brand.config as Record<string, unknown> | undefined) ?? {}),
),
}
: undefined;
@@ -29,16 +32,35 @@ export function WorkspaceProvider({ children }: PropsWithChildren) {
const reload = useCallback(() => {
setLoading(true);
setError("");
void loadWorkspace()
.then(setBaseWorkspace)
const editorPreview =
process.env.TARO_ENV === "h5" &&
new URLSearchParams(window.location.search).get("editor") === "1";
const workspacePromise = editorPreview ? Promise.resolve(undefined) : loadWorkspace();
void workspacePromise
.then((value) => {
if (value) setBaseWorkspace(value);
})
.catch((error: unknown) =>
setError(error instanceof Error ? error.message : "加载失败,请重试"),
)
.finally(() => setLoading(false));
.finally(() => setLoading(!editorPreview));
}, []);
useEffect(reload, [reload]);
return (
<Context.Provider value={{ workspace, error, loading, setBrandDraft, reload }}>
<Context.Provider
value={{
workspace: resolvedWorkspace,
error,
loading:
process.env.TARO_ENV === "h5" &&
new URLSearchParams(window.location.search).get("editor") === "1"
? !workspace
: loading,
setBrandDraft,
setWorkspaceDraft,
reload,
}}
>
{children}
</Context.Provider>
);