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
@@ -1,26 +1,11 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
Divider,
|
||||
Input,
|
||||
Popconfirm,
|
||||
Modal,
|
||||
Form,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Tabs,
|
||||
Typography,
|
||||
} from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { Alert, Button, Divider, Form, Input, Modal, Space, Tabs, Typography } from "antd";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { ErrorNote, MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag, statusLabel } from "../../components/StatusTag.js";
|
||||
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||
import { MiniAppSettingsTab, type MiniAppSettingsValues } from "./MiniAppSettingsTab.js";
|
||||
@@ -30,34 +15,28 @@ import { usePublicationMutations } from "./use-publication-mutations.js";
|
||||
const destinations: Record<string, string> = {
|
||||
brand: "/admin/brand",
|
||||
positioning: "/admin/brand",
|
||||
template: "/admin/publication",
|
||||
visual: "/admin/publication",
|
||||
template: "/admin/page-scheme",
|
||||
visual: "/admin/page-scheme",
|
||||
offerings: "/admin/services",
|
||||
forms: "/admin/workspace",
|
||||
trust: "/admin/trust",
|
||||
};
|
||||
|
||||
export function PublicationPage({ canManageTemplate }: { canManageTemplate: boolean }) {
|
||||
export function PublicationPage() {
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
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>();
|
||||
const queries = usePublicationQueries(miniAppSettingsForm);
|
||||
const {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
@@ -66,11 +45,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
"publication-workspace",
|
||||
"publication-sample",
|
||||
"publication-readiness",
|
||||
"publication-template-preview",
|
||||
"publication-releases",
|
||||
"publication-miniapp-releases",
|
||||
"publication-miniapp-settings",
|
||||
"admin-shell-brand",
|
||||
"admin-workspace",
|
||||
"public-runtime-workspace",
|
||||
@@ -80,18 +58,11 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
};
|
||||
const mutations = usePublicationMutations({
|
||||
refresh,
|
||||
currentTemplatePackageVersionId: workspace.data?.installations[0]?.templatePackageVersionId,
|
||||
onInstallClose: () => setIndustryTarget(null),
|
||||
onPublishClose: () => setConfirmAction(null),
|
||||
onNoteClear: () => setNote(""),
|
||||
onRollbackClose: () => setRollbackVersion(null),
|
||||
});
|
||||
const {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
@@ -100,18 +71,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
uploadMiniAppRelease,
|
||||
updateMiniAppStatus,
|
||||
} = mutations;
|
||||
const industryKey =
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
workspace.data?.brand?.templateKey ??
|
||||
brand.data?.templateKey ??
|
||||
null;
|
||||
const selectablePackageVersions = (queries.packages.data?.items ?? []).filter(
|
||||
(item) =>
|
||||
item.status === "published" &&
|
||||
typeof industryKey === "string" &&
|
||||
item.manifestSummary?.supportedIndustryTemplates.includes(industryKey),
|
||||
);
|
||||
const visualKey = workspace.data?.installations[0]?.visualTemplateKey ?? null;
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
@@ -123,12 +82,12 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
isEnabled: boolean;
|
||||
}>;
|
||||
|
||||
const contentTab = null;
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
<AdminPageHeader
|
||||
title="配置与发布"
|
||||
description="编辑内容不会立即影响小程序;确认后统一发布当前品牌。"
|
||||
title="内容与发布"
|
||||
description="检查当前草稿并发布品牌内容;页面方案与内容发布互不混用。"
|
||||
extra={<Button onClick={() => navigate("/admin/page-scheme")}>管理页面方案</Button>}
|
||||
/>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
@@ -137,418 +96,175 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
{
|
||||
key: "content",
|
||||
label: "内容发布",
|
||||
children: contentTab,
|
||||
children: (
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="发布前检查"
|
||||
description="请先处理未完成的检查项,再发布当前草稿。发布不会自动修改页面方案。"
|
||||
>
|
||||
{draftOfferings.length || draftForms.length ? (
|
||||
<p className="admin-section-description">
|
||||
当前草稿包含 {draftOfferings.length} 个启用中的业务提供项和{" "}
|
||||
{draftForms.length} 个咨询表单。
|
||||
</p>
|
||||
) : null}
|
||||
<ul className="admin-list">
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<li key={check.key} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={check.passed ? "success" : "warning"}
|
||||
label={check.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{check.label}</span>
|
||||
{!check.passed && check.help ? (
|
||||
<span className="admin-row-meta">{check.help}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{!check.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() =>
|
||||
navigate(
|
||||
check.destination ?? destinations[check.key] ?? "/admin/overview",
|
||||
)
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!readiness.data?.ready}
|
||||
onClick={() => setConfirmAction("publish")}
|
||||
>
|
||||
发布当前草稿
|
||||
</Button>
|
||||
{currentRelease && (
|
||||
<Button danger onClick={() => setConfirmAction("revoke")}>
|
||||
撤回当前版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={publish.error || revoke.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<h3 className="admin-section-title">发布记录</h3>
|
||||
{releases.data?.length ? (
|
||||
<ul className="admin-list admin-offset-top-xs">
|
||||
{releases.data.map((item) => (
|
||||
<li key={item.id} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">v{item.version}</span>
|
||||
<StatusTag
|
||||
tone={item.status === "published" ? "success" : "neutral"}
|
||||
label={statusLabel(item.status)}
|
||||
/>
|
||||
<span className="admin-row-meta">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
{item.note ? (
|
||||
<span className="admin-row-meta">{item.note}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{item.status === "superseded" && publishedHistory.length > 1 ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => setRollbackVersion(item.version)}
|
||||
>
|
||||
恢复此版本
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无发布记录"
|
||||
description="完成检查并发布后,这里会保留每个版本的记录。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "miniapp",
|
||||
label: "小程序发布",
|
||||
children: (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序代码发布"
|
||||
description="使用微信官方工具上传代码;审核与发布状态需按微信平台结果人工确认。"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已配置上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传凭据" />
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{miniAppReleases.data?.length ? (
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status })
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无小程序发布任务"
|
||||
description="先发布品牌内容,再上传当前版本到微信。"
|
||||
/>
|
||||
)}
|
||||
</AdminSection>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{ key: "miniapp", label: "小程序发布", children: null },
|
||||
{
|
||||
key: "settings",
|
||||
label: "小程序配置",
|
||||
children:
|
||||
activeTab === "settings" ? (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
onSave={(values) => saveMiniAppSettings.mutate(values)}
|
||||
/>
|
||||
) : null,
|
||||
children: (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
onSave={(values) => saveMiniAppSettings.mutate(values)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{activeTab === "content" && (
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="选择表达方式"
|
||||
description="行业模板决定内容结构,视觉模板决定小程序的排版风格。"
|
||||
>
|
||||
<Space wrap>
|
||||
<Select
|
||||
aria-label="行业模板"
|
||||
className="admin-field-w-xl"
|
||||
value={industryKey}
|
||||
disabled={!canManageTemplate || Boolean(workspace.data?.installations.length)}
|
||||
options={(catalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
onChange={(key: BrandTemplateKey) => setIndustryTarget(key)}
|
||||
/>
|
||||
<Select
|
||||
aria-label="视觉模板"
|
||||
className="admin-field-w-xl"
|
||||
value={visualKey}
|
||||
disabled={!canManageTemplate}
|
||||
loading={selectVisual.isPending}
|
||||
options={selectablePackageVersions.map((item) => ({
|
||||
value: item.id,
|
||||
label: `${item.displayName} · ${item.version}`,
|
||||
}))}
|
||||
onChange={(versionId) => selectVisual.mutate(versionId)}
|
||||
/>
|
||||
</Space>
|
||||
{industryKey ? (
|
||||
<div className="admin-offset-top-sm">
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone="neutral"
|
||||
label={`当前版本 ${templatePreview.data?.currentVersion ?? "加载中"}`}
|
||||
/>
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={`最新版本 ${templatePreview.data?.latestVersion ?? "加载中"}`}
|
||||
/>
|
||||
{templatePreview.data?.canUpgrade ? (
|
||||
<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
|
||||
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 ? (
|
||||
<Popconfirm
|
||||
title="确认恢复上一版模板配置基线?"
|
||||
description="不会删除品牌字段、业务内容、历史发布或客户咨询记录。"
|
||||
okText="确认回滚"
|
||||
cancelText="取消"
|
||||
onConfirm={() => {
|
||||
const currentVersion = templatePreview.data?.currentVersion;
|
||||
if (!currentVersion) return;
|
||||
rollbackTemplate.mutate({
|
||||
expectedCurrentVersion: currentVersion,
|
||||
confirm: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<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}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<MutationError error={install.error || selectVisual.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<Space wrap>
|
||||
<Typography.Text>示例内容</Typography.Text>
|
||||
{sample.isLoading && <Spin size="small" />}
|
||||
{sample.data && (
|
||||
<StatusTag
|
||||
tone={sample.data.alreadyImported ? "success" : "info"}
|
||||
label={sample.data.alreadyImported ? "已导入" : "可导入"}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
disabled={!canManageTemplate || !sample.data || sample.data.alreadyImported}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate(sample.data?.source.templatePackageVersionId)}
|
||||
>
|
||||
导入示例内容
|
||||
</Button>
|
||||
{sample.isError && <Button onClick={() => void sample.refetch()}>重试</Button>}
|
||||
</Space>
|
||||
{sample.isError && (
|
||||
<div className="admin-offset-top-sm">
|
||||
<ErrorNote error={sample.error} onRetry={() => void sample.refetch()} />
|
||||
</div>
|
||||
)}
|
||||
{sample.data && !sample.data.alreadyImported && (
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
来源:{sample.data.source.packageKey}@{sample.data.source.version}
|
||||
(checksum {(sample.data.source.contentChecksum ?? "").slice(0, 12)})
|
||||
。将向草稿添加{" "}
|
||||
{Object.entries(sample.data.counts)
|
||||
.map(([key, count]) => `${key} ${count} 项`)
|
||||
.join("、")}
|
||||
;同时补齐当前模板缺失的页面初始配置,保留已有配置和已启用表单。发布前请替换示例文案和图片。
|
||||
</p>
|
||||
)}
|
||||
<MutationError error={importSample.error} />
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="核对草稿内容"
|
||||
description="此处核对的是待发布内容,不是小程序视觉预览。"
|
||||
>
|
||||
<ul className="admin-list">
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">{brand.data?.name || "未命名品牌"}</span>
|
||||
<span className="admin-row-meta">
|
||||
{brand.data?.tagline || "尚未填写品牌定位"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用业务项</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftOfferings.map((item) => item.name).join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用咨询表单</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftForms
|
||||
.filter((item) => item.isEnabled)
|
||||
.map((item) => item.name)
|
||||
.join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑小程序页面</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务展示和详情</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任证明</Button>
|
||||
</Space>
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="检查并发布"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone={currentRelease ? "success" : "neutral"}
|
||||
label={currentRelease ? `已发布 v${currentRelease.version}` : "尚未发布"}
|
||||
/>
|
||||
<Button onClick={() => void readiness.refetch()}>重新检查</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<ul className="admin-list">
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<li key={check.key} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={check.passed ? "success" : "warning"}
|
||||
label={check.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{check.label}</span>
|
||||
{!check.passed && check.help ? (
|
||||
<span className="admin-row-meta">{check.help}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{!check.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() =>
|
||||
navigate(check.destination ?? destinations[check.key] ?? "/admin/overview")
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!readiness.data?.ready}
|
||||
onClick={() => setConfirmAction("publish")}
|
||||
>
|
||||
发布当前草稿
|
||||
</Button>
|
||||
{currentRelease && (
|
||||
<Button danger onClick={() => setConfirmAction("revoke")}>
|
||||
撤回当前版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={publish.error || revoke.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<h3 className="admin-section-title">发布记录</h3>
|
||||
{releases.data?.length ? (
|
||||
<ul className="admin-list admin-offset-top-xs">
|
||||
{releases.data.map((item) => (
|
||||
<li key={item.id} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">v{item.version}</span>
|
||||
<StatusTag
|
||||
tone={item.status === "published" ? "success" : "neutral"}
|
||||
label={statusLabel(item.status)}
|
||||
/>
|
||||
<span className="admin-row-meta">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
{item.note ? <span className="admin-row-meta">{item.note}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
{item.status === "superseded" && publishedHistory.length > 1 ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => setRollbackVersion(item.version)}
|
||||
>
|
||||
恢复此版本
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无发布记录"
|
||||
description="完成检查并发布后,这里会保留每个版本的记录。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === "miniapp" && (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序代码发布"
|
||||
description="使用微信官方工具上传代码;审核与发布状态需按微信平台结果人工确认。"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已配置上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传凭据" />
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{miniAppReleases.data?.length ? (
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) => updateMiniAppStatus.mutate({ id: task.id, status })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无小程序发布任务"
|
||||
description="先发布品牌内容,再上传当前版本到微信。"
|
||||
/>
|
||||
)}
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
<Modal
|
||||
title={confirmAction === "revoke" ? "确认撤回品牌" : "确认发布品牌"}
|
||||
open={confirmAction !== null}
|
||||
@@ -584,23 +300,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
>
|
||||
将 v{rollbackVersion} 重新发布为新版本;当前草稿不会被覆盖。
|
||||
</Modal>
|
||||
<Modal
|
||||
title="确认安装行业模板"
|
||||
open={industryTarget !== null}
|
||||
onCancel={() => setIndustryTarget(null)}
|
||||
okButtonProps={{ disabled: !templatePreview.data?.targetPackageVersionId }}
|
||||
onOk={() =>
|
||||
industryTarget &&
|
||||
templatePreview.data?.targetPackageVersionId &&
|
||||
install.mutate({
|
||||
key: industryTarget,
|
||||
versionId: templatePreview.data.targetPackageVersionId,
|
||||
})
|
||||
}
|
||||
confirmLoading={install.isPending}
|
||||
>
|
||||
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
||||
</Modal>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
interface MutationOptions {
|
||||
refresh: () => void;
|
||||
currentTemplatePackageVersionId: string | null | undefined;
|
||||
onInstallClose: () => void;
|
||||
onPublishClose: () => void;
|
||||
onNoteClear: () => void;
|
||||
onRollbackClose: () => void;
|
||||
@@ -16,83 +13,11 @@ interface MutationOptions {
|
||||
|
||||
export function usePublicationMutations({
|
||||
refresh,
|
||||
onInstallClose,
|
||||
onPublishClose,
|
||||
onNoteClear,
|
||||
onRollbackClose,
|
||||
currentTemplatePackageVersionId,
|
||||
}: MutationOptions) {
|
||||
const queryClient = useQueryClient();
|
||||
const install = useMutation({
|
||||
mutationFn: ({ key, versionId }: { key: BrandTemplateKey; versionId: string }) =>
|
||||
client.installAdminTemplate(key, versionId),
|
||||
onSuccess: () => {
|
||||
onInstallClose();
|
||||
message.success("行业模板已安装");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const upgradeTemplate = useMutation({
|
||||
mutationFn: (input: {
|
||||
templatePackageVersionId: string;
|
||||
expectedContentChecksum: string;
|
||||
expectedCurrentVersion: string;
|
||||
expectedCurrentPackageVersionId: string | null;
|
||||
confirm: true;
|
||||
preservedBindings: Array<{ key: string; binding: string; action: "preserve" }>;
|
||||
}) => client.upgradeAdminTemplate(input),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板已升级,现有内容未被覆盖");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollbackTemplate = useMutation({
|
||||
mutationFn: (input: { expectedCurrentVersion: string; confirm: true }) =>
|
||||
client.rollbackAdminTemplate(input),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板配置基线已回滚");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const selectVisual = useMutation({
|
||||
mutationFn: (templatePackageVersionId: string) =>
|
||||
client.selectAdminTemplateVersion({
|
||||
templatePackageVersionId,
|
||||
...(currentTemplatePackageVersionId !== undefined
|
||||
? { expectedCurrentPackageVersionId: currentTemplatePackageVersionId }
|
||||
: {}),
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("模板版本已切换");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const importSample = useMutation<
|
||||
Awaited<ReturnType<typeof client.importAdminSampleContent>>,
|
||||
Error,
|
||||
string | undefined
|
||||
>({
|
||||
mutationFn: (templatePackageVersionId) =>
|
||||
client.importAdminSampleContent({
|
||||
...(templatePackageVersionId ? { templatePackageVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: ({ counts, alreadyImported }) => {
|
||||
if (alreadyImported) {
|
||||
message.info("该模板包版本的示例内容已导入,未重复创建");
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
message.success(
|
||||
counts.inquiryForms
|
||||
? "示例内容和客户咨询表单已导入草稿"
|
||||
: "示例内容已导入草稿,现有客户咨询表单已保留",
|
||||
);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const publish = useMutation({
|
||||
mutationFn: (note: string) => client.publishAdminRelease(note || undefined),
|
||||
onSuccess: () => {
|
||||
@@ -163,11 +88,6 @@ export function usePublicationMutations({
|
||||
});
|
||||
|
||||
return {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
|
||||
@@ -20,25 +20,6 @@ export function usePublicationQueries(
|
||||
queryKey: ["publication-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const catalog = useQuery<Awaited<ReturnType<typeof client.listPublicTemplates>>>({
|
||||
queryKey: ["publication-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const packages = useQuery<Awaited<ReturnType<typeof client.listAdminTemplatePackages>>>({
|
||||
queryKey: ["publication-template-packages"],
|
||||
queryFn: () => client.listAdminTemplatePackages({ page: 1, pageSize: 100 }),
|
||||
});
|
||||
const sample = useQuery<Awaited<ReturnType<typeof client.previewAdminSampleContent>>>({
|
||||
queryKey: ["publication-sample", workspace.data?.installations[0]?.templatePackageVersionId],
|
||||
queryFn: () =>
|
||||
client.previewAdminSampleContent({
|
||||
...(workspace.data?.installations[0]?.templatePackageVersionId
|
||||
? { templatePackageVersionId: workspace.data.installations[0].templatePackageVersionId }
|
||||
: {}),
|
||||
strategy: "missing_only",
|
||||
}),
|
||||
enabled: Boolean(workspace.data),
|
||||
});
|
||||
const readiness = useQuery<Awaited<ReturnType<typeof client.getAdminReleaseReadiness>>>({
|
||||
queryKey: ["publication-readiness"],
|
||||
queryFn: () => client.getAdminReleaseReadiness(),
|
||||
@@ -55,12 +36,6 @@ export function usePublicationQueries(
|
||||
queryKey: ["publication-miniapp-settings"],
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
const templatePreview = useQuery<
|
||||
Awaited<ReturnType<typeof client.getAdminTemplateUpgradePreview>>
|
||||
>({
|
||||
queryKey: ["publication-template-preview"],
|
||||
queryFn: () => client.getAdminTemplateUpgradePreview(),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
@@ -82,31 +57,15 @@ export function usePublicationQueries(
|
||||
return () => clearInterval(timer);
|
||||
}, [miniAppReleases]);
|
||||
|
||||
const loading = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].some((query) => query.isLoading);
|
||||
const error = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].find((query) => query.isError)?.error;
|
||||
const loading = [brand, workspace, readiness, releases, miniAppReleases, miniAppSettings].some(
|
||||
(query) => query.isLoading,
|
||||
);
|
||||
const error = [brand, workspace, readiness, releases, miniAppReleases, miniAppSettings].find(
|
||||
(query) => query.isError,
|
||||
)?.error;
|
||||
const retry = () => {
|
||||
void brand.refetch();
|
||||
void workspace.refetch();
|
||||
void catalog.refetch();
|
||||
void packages.refetch();
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
void miniAppReleases.refetch();
|
||||
@@ -116,14 +75,10 @@ export function usePublicationQueries(
|
||||
return {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
|
||||
Reference in new issue
Block a user