101 lines
3.7 KiB
TypeScript
101 lines
3.7 KiB
TypeScript
import { Alert, Grid, Segmented, Select, Space } from "antd";
|
|
import type {
|
|
AdminTemplateContent,
|
|
BrandProfile,
|
|
RuntimeWorkspace,
|
|
} from "@personal-brand/api-client";
|
|
import { StatusTag } from "../../components/StatusTag.js";
|
|
import "./PresentationEditor.css";
|
|
import type { PreviewSelection } from "./preview-selection.js";
|
|
import { usePresentationEditorController } from "./presentation-editor-controller.js";
|
|
import { PresentationEditorInspector } from "./PresentationEditorInspector.js";
|
|
import { PresentationEditorPreview } from "./PresentationEditorPreview.js";
|
|
|
|
interface PresentationEditorProps {
|
|
templateContent: AdminTemplateContent | null | undefined;
|
|
previewWorkspace?: RuntimeWorkspace | undefined;
|
|
config: Record<string, unknown> | null | undefined;
|
|
brand: BrandProfile;
|
|
loading?: boolean;
|
|
error?: unknown;
|
|
initialSelection?: PreviewSelection;
|
|
}
|
|
|
|
export function PresentationEditor({
|
|
templateContent,
|
|
previewWorkspace,
|
|
config,
|
|
brand,
|
|
loading,
|
|
error,
|
|
initialSelection,
|
|
}: PresentationEditorProps) {
|
|
const breakpoints = Grid.useBreakpoint();
|
|
const controller = usePresentationEditorController({
|
|
templateContent,
|
|
previewWorkspace,
|
|
config,
|
|
brand,
|
|
...(initialSelection ? { initialSelection } : {}),
|
|
});
|
|
|
|
return (
|
|
<section className="presentation-editor" aria-labelledby="presentation-editor-title">
|
|
<div className="presentation-editor__header">
|
|
<div>
|
|
<h2 id="presentation-editor-title" className="admin-section-title">
|
|
小程序页面配置
|
|
</h2>
|
|
<p className="admin-section-description">
|
|
按页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
|
|
</p>
|
|
</div>
|
|
{templateContent ? <StatusTag tone="info" label={templateContent.displayName} /> : null}
|
|
</div>
|
|
{loading ? <Alert type="info" showIcon title="正在读取当前页面方案的编辑项目" /> : null}
|
|
{error ? (
|
|
<Alert type="warning" showIcon title="页面方案编辑项目读取失败,请刷新后重试。" />
|
|
) : null}
|
|
{!loading && !error && !templateContent ? (
|
|
<Alert type="warning" showIcon title="当前页面方案暂未提供可编辑的页面内容。" />
|
|
) : null}
|
|
{templateContent ? (
|
|
<>
|
|
<Space className="presentation-editor__navigation" wrap>
|
|
{breakpoints.xs ? (
|
|
<Select
|
|
aria-label="选择小程序页面"
|
|
value={controller.selectedPage ?? null}
|
|
options={controller.pageOptions}
|
|
onChange={controller.selectPage}
|
|
className="admin-field-w-2xl"
|
|
/>
|
|
) : (
|
|
<Segmented
|
|
value={controller.selectedPage ?? null}
|
|
options={controller.pageOptions}
|
|
onChange={(value) => controller.selectPage(String(value))}
|
|
/>
|
|
)}
|
|
</Space>
|
|
<div className="presentation-editor__workspace">
|
|
<PresentationEditorPreview
|
|
previewBrand={controller.previewBrand}
|
|
draftWorkspace={controller.draftWorkspace}
|
|
selectedPage={controller.selectedPage}
|
|
selectedDetailOfferingId={controller.selectedDetailOfferingId}
|
|
activeTarget={controller.activeTarget}
|
|
selection={controller.selection}
|
|
visibleTargets={controller.visibleTargets}
|
|
onSelectDetailOffering={controller.selectDetailOffering}
|
|
onTargetSelected={controller.handleTargetSelected}
|
|
onSelectPreviewTarget={controller.selectPreviewTarget}
|
|
/>
|
|
<PresentationEditorInspector controller={controller} />
|
|
</div>
|
|
</>
|
|
) : null}
|
|
</section>
|
|
);
|
|
}
|