feat: 统一业务内容双入口编辑预览
This commit is contained in:
1 parent
bfbcee45bb
commit
91322fa9a0
5 files changed
+338
-77
No files matched your search
@@ -183,6 +183,7 @@ export function PresentationEditor({
|
||||
const breakpoints = Grid.useBreakpoint();
|
||||
const [activePage, setActivePage] = useState<string>();
|
||||
const [selection, setSelection] = useState<PreviewSelection | undefined>(initialSelection);
|
||||
const [hasInitializedSelection, setHasInitializedSelection] = useState(Boolean(initialSelection));
|
||||
const [detailOfferingId, setDetailOfferingId] = useState<string>();
|
||||
const [recordDraft, setRecordDraft] = useState<{
|
||||
source: "offering" | "trust";
|
||||
@@ -292,6 +293,7 @@ export function PresentationEditor({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => createApiClient().listAdminOfferings(),
|
||||
enabled: selectedRecordSource === "offering",
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
const trustQuery = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
@@ -435,10 +437,46 @@ export function PresentationEditor({
|
||||
}, [form, initialValues]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pageOptions.some((item) => item.value === activePage))
|
||||
setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, pageOptions]);
|
||||
useEffect(() => setSelection(undefined), [selectedPage, templateContent?.displayName]);
|
||||
const initialPage =
|
||||
typeof initialSelection === "object" && "page" in initialSelection
|
||||
? String(initialSelection.page)
|
||||
: undefined;
|
||||
if (initialPage) {
|
||||
setActivePage(
|
||||
pageOptions.some((item) => item.value === initialPage)
|
||||
? initialPage
|
||||
: pageOptions[0]?.value,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!activePage && pageOptions.length) setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, initialSelection, pageOptions]);
|
||||
useEffect(() => {
|
||||
if (hasInitializedSelection) return;
|
||||
if (!pageOptions.length) return;
|
||||
if (!initialSelection) return;
|
||||
const requestedPage =
|
||||
typeof initialSelection === "object" && "page" in initialSelection
|
||||
? String(initialSelection.page)
|
||||
: undefined;
|
||||
const resolvedPage =
|
||||
requestedPage && pageOptions.some((item) => item.value === requestedPage)
|
||||
? requestedPage
|
||||
: (pageOptions[0]?.value ?? "home");
|
||||
setSelection(
|
||||
resolvePreviewSelection(
|
||||
initialSelection.targetKey,
|
||||
initialSelection.recordId,
|
||||
visibleTargets,
|
||||
resolvedPage,
|
||||
),
|
||||
);
|
||||
setActivePage(resolvedPage);
|
||||
setHasInitializedSelection(true);
|
||||
}, [hasInitializedSelection, initialSelection, pageOptions, selectedPage, visibleTargets]);
|
||||
useEffect(() => {
|
||||
if (!initialSelection) setSelection(undefined);
|
||||
}, [initialSelection, selectedPage, templateContent?.displayName]);
|
||||
useEffect(() => {
|
||||
if (!selection?.recordId) return;
|
||||
const records =
|
||||
@@ -565,6 +603,12 @@ export function PresentationEditor({
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
...(typeof config.categoryLabel === "string"
|
||||
? { categoryLabel: config.categoryLabel }
|
||||
: {}),
|
||||
...(typeof config.area === "string" ? { area: config.area } : {}),
|
||||
...(typeof config.series === "string" ? { series: config.series } : {}),
|
||||
...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
@@ -573,8 +617,10 @@ export function PresentationEditor({
|
||||
: null,
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details && typeof config.details === "object"
|
||||
? (config.details as Record<string, unknown>)
|
||||
...(config.details &&
|
||||
typeof config.details === "object" &&
|
||||
"background" in config.details
|
||||
? (config.details as RuntimeWorkspace["offerings"][number]["presentation"]["details"])
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user