feat: 收口模板升级与阶段七持续回归
This commit is contained in:
1 parent
ec16fff70e
commit
71c528de34
29 files changed
+1962
-304
No files matched your search
@@ -4,8 +4,10 @@ import { useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
Divider,
|
||||
Input,
|
||||
Popconfirm,
|
||||
Modal,
|
||||
Form,
|
||||
Select,
|
||||
@@ -13,10 +15,8 @@ import {
|
||||
Spin,
|
||||
Tabs,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import type { BrandTemplateKey } 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";
|
||||
@@ -27,8 +27,6 @@ import { MiniAppSettingsTab, type MiniAppSettingsValues } from "./MiniAppSetting
|
||||
import { usePublicationQueries } from "./use-publication-queries.js";
|
||||
import { usePublicationMutations } from "./use-publication-mutations.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
const destinations: Record<string, string> = {
|
||||
brand: "/admin/brand",
|
||||
positioning: "/admin/brand",
|
||||
@@ -45,6 +43,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const [industryTarget, setIndustryTarget] = useState<BrandTemplateKey | null>(null);
|
||||
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [preservedBindings, setPreservedBindings] = useState<Record<string, boolean>>({});
|
||||
const [note, setNote] = useState("");
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<MiniAppSettingsValues>();
|
||||
@@ -127,94 +126,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
}>;
|
||||
|
||||
const contentTab = null;
|
||||
const miniAppSettingsTab = (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序上传配置"
|
||||
description="AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM 加密。"
|
||||
>
|
||||
{miniAppSettings.data?.buildError ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message="小程序构建参数未就绪"
|
||||
description={miniAppSettings.data.buildError}
|
||||
/>
|
||||
) : (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message={`请求域名 ${miniAppSettings.data?.requestDomain ?? "未确认"}`}
|
||||
description="该域名在构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致;不一致会导致小程序打开即加载失败。"
|
||||
/>
|
||||
)}
|
||||
<Form
|
||||
form={miniAppSettingsForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveMiniAppSettings.mutate(values)}
|
||||
>
|
||||
<Form.Item
|
||||
name="appId"
|
||||
label="微信 AppID"
|
||||
rules={[{ required: true, message: "请输入微信 AppID" }]}
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="apiBaseUrl"
|
||||
label="小程序请求地址"
|
||||
rules={[
|
||||
{ required: true, message: "请输入小程序请求地址" },
|
||||
{
|
||||
validator: (_rule, value: string) =>
|
||||
!value || /^https:\/\/[^/]+/.test(value)
|
||||
? Promise.resolve()
|
||||
: Promise.reject(
|
||||
new Error(
|
||||
"公网地址必须以 https:// 开头,例如 https://wechat.app.que01.top/api",
|
||||
),
|
||||
),
|
||||
},
|
||||
]}
|
||||
extra="构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致。修改后需重新构建并上传代码才生效。"
|
||||
>
|
||||
<Input maxLength={200} placeholder="https://wechat.app.que01.top/api" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="privateKey"
|
||||
label="上传私钥"
|
||||
help={
|
||||
miniAppSettings.data?.hasStoredCredentials
|
||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||
: "粘贴微信开发者工具导出的 private.<appid>.key 全文,必须保留换行。"
|
||||
}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={5}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
|
||||
className="admin-code-input"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
||||
保存上传配置
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已加密保存上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传私钥" />
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={saveMiniAppSettings.error} />
|
||||
</Form>
|
||||
</AdminSection>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
<AdminPageHeader
|
||||
@@ -287,33 +198,125 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
label={`最新版本 ${templatePreview.data?.latestVersion ?? "加载中"}`}
|
||||
/>
|
||||
{templatePreview.data?.canUpgrade ? (
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={upgradeTemplate.isPending}
|
||||
onClick={() => upgradeTemplate.mutate()}
|
||||
<Popconfirm
|
||||
title="确认升级到已发布模板包?"
|
||||
description={`新增 binding ${templatePreview.data.changes.templateBindings.added.length} 项;冲突值需逐项确认保留。升级不会删除字段或业务内容。`}
|
||||
okText="确认升级"
|
||||
cancelText="取消"
|
||||
onConfirm={() => {
|
||||
const preview = templatePreview.data;
|
||||
if (!preview?.targetPackageVersionId || !preview.targetContentChecksum)
|
||||
return;
|
||||
if (
|
||||
!preview.conflicts.every(
|
||||
(item) => preservedBindings[`${item.key}:${item.binding}`],
|
||||
)
|
||||
)
|
||||
return;
|
||||
upgradeTemplate.mutate({
|
||||
templatePackageVersionId: preview.targetPackageVersionId,
|
||||
expectedContentChecksum: preview.targetContentChecksum,
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
expectedCurrentPackageVersionId: preview.currentPackageVersionId,
|
||||
confirm: true,
|
||||
preservedBindings: preview.conflicts.map(({ key, binding }) => ({
|
||||
key,
|
||||
binding,
|
||||
action: "preserve" as const,
|
||||
})),
|
||||
});
|
||||
}}
|
||||
>
|
||||
升级模板
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
disabled={
|
||||
!canManageTemplate ||
|
||||
!templatePreview.data?.targetPackageVersionId ||
|
||||
!templatePreview.data.conflicts.every(
|
||||
(item) => preservedBindings[`${item.key}:${item.binding}`],
|
||||
)
|
||||
}
|
||||
loading={upgradeTemplate.isPending}
|
||||
>
|
||||
升级模板
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
) : (
|
||||
<StatusTag tone="success" label="已是最新版本" />
|
||||
)}
|
||||
{templatePreview.data?.canRollback ? (
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={rollbackTemplate.isPending}
|
||||
onClick={() => rollbackTemplate.mutate()}
|
||||
<Popconfirm
|
||||
title="确认恢复上一版模板配置基线?"
|
||||
description="不会删除品牌字段、业务内容、历史发布或客户咨询记录。"
|
||||
okText="确认回滚"
|
||||
cancelText="取消"
|
||||
onConfirm={() => {
|
||||
const currentVersion = templatePreview.data?.currentVersion;
|
||||
if (!currentVersion) return;
|
||||
rollbackTemplate.mutate({
|
||||
expectedCurrentVersion: currentVersion,
|
||||
confirm: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
回滚到上一版
|
||||
</Button>
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={rollbackTemplate.isPending}
|
||||
>
|
||||
回滚到上一版
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
) : null}
|
||||
</Space>
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
行业模板随品牌身份固定,只能升级版本、不能更换行业;升级只补充字段与模块,不覆盖已有内容。视觉模板只替换排版风格。
|
||||
行业模板随品牌身份固定。升级目标为当前视觉模板最新已发布包,并按包版本与 checksum
|
||||
锁定预览;新增字段会补入,改动冲突和已移除字段不会覆盖或删除。回滚仅恢复配置基线,不删除品牌字段、内容或历史发布。
|
||||
</p>
|
||||
{templatePreview.data?.conflicts.length ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`请逐项确认保留 ${templatePreview.data.conflicts.length} 个现有品牌配置值`}
|
||||
description={
|
||||
<Space direction="vertical">
|
||||
{templatePreview.data.conflicts.map((item) => {
|
||||
const key = `${item.key}:${item.binding}`;
|
||||
return (
|
||||
<Checkbox
|
||||
key={key}
|
||||
checked={Boolean(preservedBindings[key])}
|
||||
onChange={(event) =>
|
||||
setPreservedBindings((current) => ({
|
||||
...current,
|
||||
[key]: event.target.checked,
|
||||
}))
|
||||
}
|
||||
>
|
||||
保留 {item.binding}({item.reason})
|
||||
</Checkbox>
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{templatePreview.data ? (
|
||||
<div className="admin-section-description admin-offset-top-sm">
|
||||
页面入口变更:新增 {templatePreview.data.changes.pages.added.length}、变更{" "}
|
||||
{templatePreview.data.changes.pages.changed.length}、移除{" "}
|
||||
{templatePreview.data.changes.pages.removed.length};资源槽位变更:新增{" "}
|
||||
{templatePreview.data.changes.assets.slots.added.length}、变更{" "}
|
||||
{templatePreview.data.changes.assets.slots.changed.length}、移除{" "}
|
||||
{templatePreview.data.changes.assets.slots.removed.length};
|
||||
{templatePreview.data.changes.assets.files.available
|
||||
? `包内文件变更:新增 ${templatePreview.data.changes.assets.files.added?.length ?? 0}、变更 ${templatePreview.data.changes.assets.files.changed?.length ?? 0}、移除 ${templatePreview.data.changes.assets.files.removed?.length ?? 0}`
|
||||
: templatePreview.data.changes.assets.files.reason}
|
||||
。模块与 renderer 由已部署的平台视觉模板管理,此次包升级不会替换 renderer。
|
||||
</div>
|
||||
) : null}
|
||||
<MutationError
|
||||
error={templatePreview.error || upgradeTemplate.error || rollbackTemplate.error}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user