feat: 增加模板版本独立预览入口

This commit is contained in:
que01 committed 2026-10-16 17:28:07 +08:00
1 parent 413413efda
commit 6edde5a8d6
15 files changed
+781 -14

No files matched your search

@@ -1,13 +1,14 @@
import { useRef, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Alert, Button, List, Modal, Table, Tag, Typography, message } from "antd";
import { ReloadOutlined, UploadOutlined } from "@ant-design/icons";
import { EyeOutlined, ReloadOutlined, UploadOutlined } from "@ant-design/icons";
import type { TemplatePackageVersion } from "@personal-brand/api-client";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { AdminSection } from "../../components/AdminSection.js";
import { EmptyState } from "../../components/EmptyState.js";
import { ErrorNote, QueryState } from "../../components/QueryState.js";
import { TemplatePackagePreviewModal } from "./TemplatePackagePreviewModal.js";
const client = createApiClient();
@@ -23,6 +24,7 @@ export function TemplateManagementPage() {
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(20);
const [auditId, setAuditId] = useState<string | null>(null);
const [previewVersion, setPreviewVersion] = useState<TemplatePackageVersion | null>(null);
const queryClient = useQueryClient();
const packages = useQuery({
queryKey: ["admin-template-packages", page, pageSize],
@@ -167,7 +169,7 @@ export function TemplateManagementPage() {
key: "report",
render: (_, item) => {
const report = item.validationReport;
return `${String(report.fileCount ?? "-")} 个,${formatBytes(report.extractedBytes)}`;
return `${typeof report.fileCount === "number" ? report.fileCount : "-"} 个,${formatBytes(report.extractedBytes)}`;
},
},
{
@@ -188,6 +190,14 @@ export function TemplateManagementPage() {
key: "actions",
render: (_, item) => (
<span>
<Button
type="link"
icon={<EyeOutlined />}
onClick={() => setPreviewVersion(item)}
disabled={!item.manifestSummary?.supportedIndustryTemplates?.length}
>
预览
</Button>
<Button
type="link"
loading={lifecycle.isPending && lifecycle.variables?.id === item.id}
@@ -247,6 +257,12 @@ export function TemplateManagementPage() {
/>
</QueryState>
</Modal>
{previewVersion ? (
<TemplatePackagePreviewModal
version={previewVersion}
onClose={() => setPreviewVersion(null)}
/>
) : null}
</div>
);
}
@@ -0,0 +1,123 @@
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>
);
}