fix: 修复模板画布点选与保存切页回归
This commit is contained in:
1 parent
e6d843b4a7
commit
cd2992c00a
15 files changed
+98
-40
No files matched your search
@@ -168,6 +168,6 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
.component-template-preview__overlay-host > * {
|
||||
.component-template-preview__overlay-host > .component-template-preview__composite-select {
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -2,11 +2,7 @@ import { Alert, Button, Grid, Select, Segmented, Space, Typography } from "antd"
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { AdminTemplateContent, RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import { RecordContentEditor } from "../../components/RecordContentEditor.js";
|
||||
@@ -18,10 +14,7 @@ import {
|
||||
type PreviewSelection,
|
||||
type PreviewTarget,
|
||||
} from "./preview-selection.js";
|
||||
import {
|
||||
filterSectionsForPreviewTarget,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import { filterSectionsForPreviewTarget } from "../../lib/presentation/presentation-bindings.js";
|
||||
import "./PresentationEditor.css";
|
||||
import { useEditorDraft } from "./use-editor-draft.js";
|
||||
import {
|
||||
@@ -213,7 +206,14 @@ export function PresentationEditor({
|
||||
: pageLinks;
|
||||
const formState = useBrandPresentationForm({ brand, config, sections });
|
||||
const { form, initialValues } = formState;
|
||||
const save = useBrandSaveMutation({ ...formState, brand, config, sections, queryClient });
|
||||
const save = useBrandSaveMutation({
|
||||
...formState,
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
queryClient,
|
||||
onSaved: () => setBrandDirty(false),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const initialPage =
|
||||
|
||||
@@ -7,6 +7,7 @@ import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
|
||||
eager: true,
|
||||
});
|
||||
const resolvedRenderers = new Map();
|
||||
|
||||
function pageContent({ workspace, page }) {
|
||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||
@@ -22,15 +23,18 @@ export function resolveTemplateRenderer(workspace) {
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
if (typeof key !== "string") return null;
|
||||
if (resolvedRenderers.has(key)) return resolvedRenderers.get(key);
|
||||
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) {
|
||||
function TemplatePreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value={key}>
|
||||
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
};
|
||||
}
|
||||
resolvedRenderers.set(key, TemplatePreview);
|
||||
return TemplatePreview;
|
||||
}
|
||||
@@ -98,6 +98,7 @@ interface BrandSaveMutationOptions extends BrandPresentationFormState {
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
sections: TemplateAdminSection[];
|
||||
queryClient: QueryClient;
|
||||
onSaved: () => void;
|
||||
}
|
||||
|
||||
export function useBrandSaveMutation({
|
||||
@@ -105,6 +106,7 @@ export function useBrandSaveMutation({
|
||||
config,
|
||||
sections,
|
||||
queryClient,
|
||||
onSaved,
|
||||
}: BrandSaveMutationOptions) {
|
||||
return useMutation({
|
||||
mutationFn: (values: PresentationValues) => {
|
||||
@@ -125,6 +127,7 @@ export function useBrandSaveMutation({
|
||||
return createApiClient().updateAdminBrand({ ...changed, config: contentConfig });
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSaved();
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
window.dispatchEvent(new Event("template-preview-refresh"));
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
|
||||
Reference in new issue
Block a user