124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import { useState } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { Alert, Modal, Select, Typography } from "antd";
|
|
import type { TemplatePackageVersion } from "@personal-brand/api-client";
|
|
import { createApiClient } from "../../lib/api.js";
|
|
import { QueryState } from "../../components/QueryState.js";
|
|
import { EmptyState } from "../../components/EmptyState.js";
|
|
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
|
|
|
const pageLabels: Record<string, string> = {
|
|
home: "首页",
|
|
offerings: "业务列表",
|
|
service: "服务",
|
|
profile: "我的 / 主理人",
|
|
detail: "业务详情",
|
|
inquiry: "咨询表单",
|
|
records: "咨询记录",
|
|
success: "提交结果",
|
|
};
|
|
|
|
export function TemplatePackagePreviewModal({
|
|
version,
|
|
onClose,
|
|
}: {
|
|
version: TemplatePackageVersion;
|
|
onClose: () => void;
|
|
}) {
|
|
const [industry, setIndustry] = useState(version.manifestSummary?.supportedIndustryTemplates[0]);
|
|
const [page, setPage] = useState("home");
|
|
const [offeringId, setOfferingId] = useState<string>();
|
|
const client = createApiClient();
|
|
const preview = useQuery({
|
|
queryKey: ["admin-template-package-preview", version.id, industry],
|
|
queryFn: () => client.previewAdminTemplatePackage(version.id, industry!),
|
|
enabled: Boolean(industry),
|
|
retry: false,
|
|
gcTime: 0,
|
|
});
|
|
const data = preview.data;
|
|
return (
|
|
<Modal
|
|
title={`${version.displayName} · ${version.version} 版本预览`}
|
|
open
|
|
footer={null}
|
|
width={960}
|
|
onCancel={onClose}
|
|
>
|
|
<div className="admin-stack">
|
|
<Select
|
|
aria-label="预览行业"
|
|
value={industry}
|
|
placeholder="选择行业"
|
|
options={(version.manifestSummary?.supportedIndustryTemplates ?? []).map((value) => ({
|
|
label: value,
|
|
value,
|
|
}))}
|
|
onChange={(value) => {
|
|
setIndustry(value);
|
|
setPage("home");
|
|
setOfferingId(undefined);
|
|
}}
|
|
/>
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
message="模板演示预览"
|
|
description="演示内容不属于真实品牌,咨询提交和客户记录读取已禁用。"
|
|
/>
|
|
{!industry ? (
|
|
<EmptyState title="没有可预览的行业" description="请检查模板包的行业兼容声明。" />
|
|
) : (
|
|
<QueryState
|
|
loading={preview.isLoading}
|
|
error={preview.error}
|
|
onRetry={() => void preview.refetch()}
|
|
>
|
|
{data ? (
|
|
<>
|
|
<Typography.Paragraph type="secondary">
|
|
{data.industry.name} · Runtime {data.compatibility.runtimeContract} · renderer{" "}
|
|
{data.compatibility.renderer.key}@{data.compatibility.renderer.version}
|
|
</Typography.Paragraph>
|
|
<Select
|
|
aria-label="预览页面"
|
|
value={page}
|
|
options={data.template.pages.map((value) => ({
|
|
value,
|
|
label:
|
|
data.template.navigation.find((tab) => tab.page === value)?.label ??
|
|
pageLabels[value] ??
|
|
value,
|
|
}))}
|
|
onChange={setPage}
|
|
/>
|
|
{page === "detail" ? (
|
|
<Select
|
|
aria-label="预览业务记录"
|
|
value={offeringId ?? data.workspace.offerings[0]?.id}
|
|
options={data.workspace.offerings.map((item) => ({
|
|
label: item.name,
|
|
value: item.id,
|
|
}))}
|
|
onChange={setOfferingId}
|
|
/>
|
|
) : null}
|
|
<ComponentTemplatePreview
|
|
key={`${version.id}:${industry}:${page}`}
|
|
workspace={data.workspace}
|
|
page={page}
|
|
{...((offeringId ?? data.workspace.offerings[0]?.id)
|
|
? { offeringId: offeringId ?? data.workspace.offerings[0]!.id }
|
|
: {})}
|
|
targets={[]}
|
|
onTargetSelected={() => undefined}
|
|
/>
|
|
</>
|
|
) : null}
|
|
</QueryState>
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|