refactor: 拆分品牌业务类型与页面方案
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
This commit is contained in:
1 parent
f02e2cafbb
commit
0d9f4a7d6f
86 files changed
+4111
-1543
No files matched your search
@@ -0,0 +1,375 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Alert, Button, Card, Collapse, Descriptions, Empty, List, Modal, Space, Tag } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { adminMessage as message } from "../../components/AdminMessage.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
export function PageSchemePage() {
|
||||
const queryClient = useQueryClient();
|
||||
const [selectedVersionId, setSelectedVersionId] = useState<string>();
|
||||
const [samplePreview, setSamplePreview] = useState<Awaited<
|
||||
ReturnType<typeof client.previewAdminSampleContent>
|
||||
> | null>(null);
|
||||
const workspace = useQuery({
|
||||
queryKey: ["page-scheme-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const options = useQuery({
|
||||
queryKey: ["admin-page-scheme-options"],
|
||||
queryFn: () => client.getAdminPageSchemeOptions(),
|
||||
});
|
||||
const upgradePreview = useQuery({
|
||||
queryKey: ["page-scheme-upgrade-preview"],
|
||||
queryFn: () => client.getAdminTemplateUpgradePreview(),
|
||||
});
|
||||
const installation = workspace.data?.installations[0];
|
||||
const currentVersionId = installation?.templatePackageVersionId;
|
||||
const currentScheme = options.data?.pageSchemes.find(
|
||||
(scheme) => scheme.templatePackageVersionId === currentVersionId,
|
||||
);
|
||||
const business = options.data?.business;
|
||||
const compatibleSchemes = options.data?.pageSchemes ?? [];
|
||||
|
||||
useEffect(() => {
|
||||
if (currentVersionId) setSelectedVersionId(currentVersionId);
|
||||
}, [currentVersionId]);
|
||||
|
||||
const refresh = () => {
|
||||
for (const queryKey of [
|
||||
"page-scheme-workspace",
|
||||
"page-scheme-upgrade-preview",
|
||||
"admin-workspace",
|
||||
"admin-preview-workspace",
|
||||
"admin-overview-workspace",
|
||||
"publication-workspace",
|
||||
"publication-readiness",
|
||||
]) {
|
||||
void queryClient.invalidateQueries({ queryKey: [queryKey] });
|
||||
}
|
||||
};
|
||||
|
||||
const selectVersion = useMutation({
|
||||
mutationFn: (templatePackageVersionId: string) =>
|
||||
client.selectAdminTemplateVersion({
|
||||
templatePackageVersionId,
|
||||
expectedCurrentPackageVersionId: currentVersionId ?? null,
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("页面方案版本已切换");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const upgrade = useMutation({
|
||||
mutationFn: async () => {
|
||||
const preview = upgradePreview.data;
|
||||
if (
|
||||
!preview?.canUpgrade ||
|
||||
!preview.targetPackageVersionId ||
|
||||
!preview.targetContentChecksum
|
||||
) {
|
||||
throw new Error("当前没有可升级的页面方案版本,请刷新后重试");
|
||||
}
|
||||
return client.upgradeAdminTemplate({
|
||||
templatePackageVersionId: preview.targetPackageVersionId,
|
||||
expectedContentChecksum: preview.targetContentChecksum,
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
expectedCurrentPackageVersionId: preview.currentPackageVersionId,
|
||||
confirm: true,
|
||||
preservedBindings: preview.conflicts.map(({ key, binding }) => ({
|
||||
key,
|
||||
binding,
|
||||
action: "preserve",
|
||||
})),
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面方案已升级,现有内容已全部保留");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: () => {
|
||||
const preview = upgradePreview.data;
|
||||
if (!preview?.canRollback) throw new Error("当前没有可恢复的上一版配置基线");
|
||||
return client.rollbackAdminTemplate({
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
confirm: true,
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("已恢复上一版页面方案配置基线");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const previewSample = useMutation({
|
||||
mutationFn: () =>
|
||||
client.previewAdminSampleContent({
|
||||
...(currentVersionId ? { templatePackageVersionId: currentVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
}),
|
||||
onSuccess: (data) => setSamplePreview(data),
|
||||
});
|
||||
const importSample = useMutation({
|
||||
mutationFn: () =>
|
||||
client.importAdminSampleContent({
|
||||
...(currentVersionId ? { templatePackageVersionId: currentVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("示例内容已按缺失项导入,现有内容未被覆盖");
|
||||
setSamplePreview(null);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
|
||||
const confirmSelect = (templatePackageVersionId: string) => {
|
||||
const target = compatibleSchemes.find(
|
||||
(scheme) => scheme.templatePackageVersionId === templatePackageVersionId,
|
||||
);
|
||||
Modal.confirm({
|
||||
title: "切换页面方案版本",
|
||||
content: target
|
||||
? `将当前品牌切换到「${target.name}」版本 ${target.version}。现有品牌内容会保留。`
|
||||
: "将切换当前品牌使用的页面方案版本。现有品牌内容会保留。",
|
||||
okText: "确认切换",
|
||||
cancelText: "取消",
|
||||
onOk: () => selectVersion.mutateAsync(templatePackageVersionId),
|
||||
});
|
||||
};
|
||||
const confirmUpgrade = () => {
|
||||
const preview = upgradePreview.data;
|
||||
Modal.confirm({
|
||||
title: "升级页面方案",
|
||||
content:
|
||||
preview && preview.conflicts.length
|
||||
? `将升级到版本 ${preview.latestVersion},并全部保留 ${preview.conflicts.length} 项现有内容。`
|
||||
: `将升级到版本 ${preview?.latestVersion ?? "最新版"},现有品牌内容会保留。`,
|
||||
okText: "确认升级",
|
||||
cancelText: "取消",
|
||||
onOk: () => upgrade.mutateAsync(),
|
||||
});
|
||||
};
|
||||
const confirmRollback = () => {
|
||||
Modal.confirm({
|
||||
title: "恢复上一版配置基线",
|
||||
content: "此操作只恢复上一版页面方案配置,不会删除品牌内容、业务提供项或咨询记录。",
|
||||
okText: "确认恢复",
|
||||
cancelText: "取消",
|
||||
onOk: () => rollback.mutateAsync(),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={workspace.isLoading || options.isLoading || upgradePreview.isLoading}
|
||||
error={workspace.error || options.error || upgradePreview.error}
|
||||
onRetry={() => {
|
||||
void workspace.refetch();
|
||||
void options.refetch();
|
||||
void upgradePreview.refetch();
|
||||
}}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="页面方案"
|
||||
description="页面方案决定小程序有哪些页面、页面结构、视觉和资源位。它可以独立于内容发布进行升级或版本切换。"
|
||||
/>
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="当前方案"
|
||||
description="业务类型创建后固定;页面方案和版本可以继续调整。"
|
||||
>
|
||||
<Descriptions column={{ xs: 1, md: 2 }} bordered>
|
||||
<Descriptions.Item label="业务类型">{business?.name ?? "未识别"}</Descriptions.Item>
|
||||
<Descriptions.Item label="页面方案">
|
||||
{currentScheme?.name ?? workspace.data?.templateContent?.displayName ?? "尚未安装"}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="当前状态">
|
||||
<StatusTag
|
||||
tone={installation ? "info" : "neutral"}
|
||||
label={
|
||||
installation ? `正在使用版本 ${installation.templateVersion}` : "尚未安装页面方案"
|
||||
}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{business?.description ? (
|
||||
<p className="admin-section-description admin-offset-top">{business.description}</p>
|
||||
) : null}
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="升级预览"
|
||||
description="升级前先查看页面、模块、资源和绑定的变化;冲突项默认保留现有内容。"
|
||||
>
|
||||
<Card>
|
||||
{upgradePreview.data?.canUpgrade ? (
|
||||
<Space direction="vertical" size={12} className="admin-full-width">
|
||||
<div className="admin-row-line">
|
||||
<strong>可升级到版本 {upgradePreview.data.latestVersion}</strong>
|
||||
<Tag color="blue">建议先预览</Tag>
|
||||
</div>
|
||||
<Descriptions column={{ xs: 1, md: 2 }} size="small">
|
||||
<Descriptions.Item label="新增页面">
|
||||
{upgradePreview.data.changes.pages.added.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="变更页面">
|
||||
{upgradePreview.data.changes.pages.changed.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="新增字段绑定">
|
||||
{upgradePreview.data.changes.templateBindings.added.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="需要保留的冲突">
|
||||
{upgradePreview.data.conflicts.length}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{upgradePreview.data.conflicts.length ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`发现 ${upgradePreview.data.conflicts.length} 项自定义内容与新版布局存在差异`}
|
||||
description="升级时会全部保留现有内容,不会逐项覆盖。请确认后再执行升级。"
|
||||
/>
|
||||
) : (
|
||||
<Alert type="success" showIcon message="未发现内容绑定冲突" />
|
||||
)}
|
||||
<Button type="primary" onClick={confirmUpgrade} loading={upgrade.isPending}>
|
||||
升级到 {upgradePreview.data.latestVersion}
|
||||
</Button>
|
||||
</Space>
|
||||
) : (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description="当前已是可用的最新页面方案版本,暂无可升级版本。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={upgrade.error} />
|
||||
</Card>
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="选择版本"
|
||||
description="可切换到同一业务类型下的其他已发布版本。切换会保留品牌内容。"
|
||||
>
|
||||
<List
|
||||
dataSource={compatibleSchemes}
|
||||
locale={{ emptyText: "没有可切换的页面方案版本" }}
|
||||
renderItem={(scheme) => {
|
||||
const isCurrent = scheme.templatePackageVersionId === currentVersionId;
|
||||
return (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button
|
||||
key="select"
|
||||
type={isCurrent ? "default" : "primary"}
|
||||
disabled={isCurrent}
|
||||
loading={
|
||||
selectVersion.isPending &&
|
||||
selectedVersionId === scheme.templatePackageVersionId
|
||||
}
|
||||
onClick={() => {
|
||||
setSelectedVersionId(scheme.templatePackageVersionId);
|
||||
confirmSelect(scheme.templatePackageVersionId);
|
||||
}}
|
||||
>
|
||||
{isCurrent ? "当前版本" : "切换到此版本"}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<List.Item.Meta
|
||||
title={
|
||||
<Space>
|
||||
<span>{scheme.name}</span>
|
||||
<Tag color={scheme.isLatestForPackage ? "green" : "default"}>
|
||||
{scheme.isLatestForPackage ? "最新版" : `版本 ${scheme.version}`}
|
||||
</Tag>
|
||||
</Space>
|
||||
}
|
||||
description={`${scheme.description} · 版本 ${scheme.version}`}
|
||||
/>
|
||||
</List.Item>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<MutationError error={selectVersion.error} />
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="配置恢复"
|
||||
description="恢复上一版页面方案配置基线,仅用于升级后出现配置问题时回退。"
|
||||
>
|
||||
<Button danger onClick={confirmRollback} disabled={!upgradePreview.data?.canRollback}>
|
||||
恢复上一版配置
|
||||
</Button>
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
|
||||
<Collapse
|
||||
items={[
|
||||
{
|
||||
key: "sample-content",
|
||||
label: "高级:导入示例内容",
|
||||
children: (
|
||||
<Space direction="vertical" size={12} className="admin-full-width">
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="此操作会写入当前品牌内容"
|
||||
description="仅导入当前缺失的内容,不会覆盖已有品牌资料。创建品牌时不会自动执行。"
|
||||
/>
|
||||
<Space>
|
||||
<Button
|
||||
onClick={() => previewSample.mutate()}
|
||||
loading={previewSample.isPending}
|
||||
>
|
||||
预览将导入的内容
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
danger
|
||||
disabled={!samplePreview}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate()}
|
||||
>
|
||||
确认导入缺失内容
|
||||
</Button>
|
||||
</Space>
|
||||
<MutationError error={previewSample.error || importSample.error} />
|
||||
{samplePreview ? (
|
||||
<Descriptions bordered size="small" column={{ xs: 1, md: 2 }}>
|
||||
<Descriptions.Item label="品牌资料">
|
||||
{samplePreview.counts.brandConfig}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="业务提供项">
|
||||
{samplePreview.counts.offerings}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="信任内容">
|
||||
{samplePreview.counts.trustContent}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="字段">
|
||||
{samplePreview.counts.fields}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="咨询表单">
|
||||
{samplePreview.counts.inquiryForms}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="是否已导入">
|
||||
{samplePreview.alreadyImported ? "是" : "否"}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user