feat: 重做小程序发布任务卡片并支持配置请求地址
- 发布任务卡片拆为 MiniAppReleaseCard,状态用中文映射并附下一步说明,构建日志收进折叠面板,构建中自动滚动到底部 - 小程序配置增加“小程序请求地址”字段,展示当前生效域名,未配置时直接提示原因与修复位置 - 顶部上传按钮在无任务时自动创建发布任务,不再报“还没有可发布的内容版本” - 构建轮询在任务被判定为中断后停止,避免页面空转请求
This commit is contained in:
1 parent
44fe7a0142
commit
ac3f433ee6
2 files changed
+248
-111
No files matched your search
@@ -0,0 +1,185 @@
|
|||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
import { Alert, Button, Card, Collapse, Flex, Space, Tag, Tooltip, Typography, theme } from "antd";
|
||||||
|
import { LoadingOutlined } from "@ant-design/icons";
|
||||||
|
import type { MiniAppReleaseTask } from "@personal-brand/api-client";
|
||||||
|
|
||||||
|
type ReleaseStatus = MiniAppReleaseTask["status"];
|
||||||
|
|
||||||
|
const STALE_BUILDING_MS = 15 * 60 * 1000;
|
||||||
|
|
||||||
|
function isStaleBuilding(task: MiniAppReleaseTask): boolean {
|
||||||
|
if (task.buildStatus !== "building") return false;
|
||||||
|
const updatedAt = new Date(task.updatedAt).getTime();
|
||||||
|
return !Number.isNaN(updatedAt) && Date.now() - updatedAt >= STALE_BUILDING_MS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusView: Record<ReleaseStatus, { label: string; color: string; hint: string }> = {
|
||||||
|
built: { label: "待上传", color: "default", hint: "代码已构建,可上传到微信。" },
|
||||||
|
uploaded: { label: "已上传微信", color: "blue", hint: "请在微信后台上传体验版并提交审核。" },
|
||||||
|
under_review: {
|
||||||
|
label: "审核中",
|
||||||
|
color: "processing",
|
||||||
|
hint: "等待微信审核结果,通过后回到本页标记。",
|
||||||
|
},
|
||||||
|
approved: { label: "审核通过", color: "cyan", hint: "审核已通过,确认无误后标记为已发布。" },
|
||||||
|
published: { label: "已发布", color: "green", hint: "该版本已发布,可继续编辑内容后再次上传。" },
|
||||||
|
rejected: { label: "已驳回", color: "volcano", hint: "微信驳回后需修改内容并重新构建上传。" },
|
||||||
|
failed: { label: "失败", color: "red", hint: "上次构建或上传失败,可直接重试。" },
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatTime(value: string): string {
|
||||||
|
const date = new Date(value);
|
||||||
|
if (Number.isNaN(date.getTime())) return value;
|
||||||
|
return date.toLocaleString("zh-CN", { hour12: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatLogTime(value: string): string {
|
||||||
|
const date = new Date(value);
|
||||||
|
if (Number.isNaN(date.getTime())) return "";
|
||||||
|
return date.toLocaleTimeString("zh-CN", { hour12: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MiniAppReleaseCard({
|
||||||
|
task,
|
||||||
|
uploading,
|
||||||
|
onUpload,
|
||||||
|
onStatusChange,
|
||||||
|
}: {
|
||||||
|
task: MiniAppReleaseTask;
|
||||||
|
uploading: boolean;
|
||||||
|
onUpload: () => void;
|
||||||
|
onStatusChange: (status: ReleaseStatus) => void;
|
||||||
|
}) {
|
||||||
|
const { token } = theme.useToken();
|
||||||
|
const logRef = useRef<HTMLPreElement>(null);
|
||||||
|
const logs = task.buildLogs ?? [];
|
||||||
|
const status = statusView[task.status];
|
||||||
|
const building = task.buildStatus === "building";
|
||||||
|
const staleBuilding = isStaleBuilding(task);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!building) return;
|
||||||
|
const node = logRef.current;
|
||||||
|
if (node) node.scrollTop = node.scrollHeight;
|
||||||
|
}, [building, logs.length]);
|
||||||
|
|
||||||
|
const actions = (
|
||||||
|
<Space wrap>
|
||||||
|
{(task.status === "built" || task.status === "failed" || staleBuilding) && (
|
||||||
|
<Button
|
||||||
|
type={task.status === "built" && !staleBuilding ? "primary" : "default"}
|
||||||
|
size="small"
|
||||||
|
loading={uploading}
|
||||||
|
onClick={onUpload}
|
||||||
|
>
|
||||||
|
{task.status === "built" && !staleBuilding ? "上传微信" : "重试上传微信"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{task.status === "uploaded" && (
|
||||||
|
<Button size="small" onClick={() => onStatusChange("under_review")}>
|
||||||
|
标记提交审核
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{task.status === "under_review" && (
|
||||||
|
<>
|
||||||
|
<Button size="small" onClick={() => onStatusChange("approved")}>
|
||||||
|
审核通过
|
||||||
|
</Button>
|
||||||
|
<Button size="small" danger onClick={() => onStatusChange("rejected")}>
|
||||||
|
审核驳回
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{task.status === "approved" && (
|
||||||
|
<Button size="small" type="primary" onClick={() => onStatusChange("published")}>
|
||||||
|
标记已发布
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card size="small" styles={{ body: { padding: 16 } }}>
|
||||||
|
<Flex justify="space-between" align="flex-start" gap={12} wrap>
|
||||||
|
<Space direction="vertical" size={4}>
|
||||||
|
<Space wrap size={8} align="center">
|
||||||
|
<Typography.Text strong>品牌内容 v{task.version}</Typography.Text>
|
||||||
|
<Tag color={status.color}>{status.label}</Tag>
|
||||||
|
{building && (
|
||||||
|
<Tag icon={<LoadingOutlined />} color="orange">
|
||||||
|
{staleBuilding ? "构建已中断" : "构建中"}
|
||||||
|
</Tag>
|
||||||
|
)}
|
||||||
|
{task.weappUploadId && (
|
||||||
|
<Typography.Text type="secondary">微信版本 {task.weappUploadId}</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{staleBuilding ? "超过 15 分钟没有新的构建输出,可能已中断;可直接重试。" : status.hint}
|
||||||
|
</Typography.Text>
|
||||||
|
<Tooltip title={`创建于 ${formatTime(task.createdAt)}`}>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
更新于 {formatTime(task.updatedAt)}
|
||||||
|
</Typography.Text>
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
{actions}
|
||||||
|
</Flex>
|
||||||
|
|
||||||
|
{task.error && <Alert type="error" showIcon message={task.error} style={{ marginTop: 12 }} />}
|
||||||
|
|
||||||
|
{logs.length > 0 && (
|
||||||
|
<Collapse
|
||||||
|
ghost
|
||||||
|
size="small"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
{...(building || task.buildStatus === "failed" ? { defaultActiveKey: ["logs"] } : {})}
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: "logs",
|
||||||
|
label: (
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
构建日志({logs.length} 行)
|
||||||
|
</Typography.Text>
|
||||||
|
),
|
||||||
|
children: (
|
||||||
|
<pre
|
||||||
|
ref={logRef}
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
padding: 12,
|
||||||
|
maxHeight: 220,
|
||||||
|
overflow: "auto",
|
||||||
|
fontSize: 12,
|
||||||
|
lineHeight: 1.7,
|
||||||
|
borderRadius: token.borderRadius,
|
||||||
|
border: `1px solid ${token.colorBorderSecondary}`,
|
||||||
|
background: token.colorFillQuaternary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{logs.map((log, index) => (
|
||||||
|
<div
|
||||||
|
key={`${log.at}-${index}`}
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
log.stream === "stderr" ? token.colorError : token.colorTextSecondary,
|
||||||
|
whiteSpace: "pre-wrap",
|
||||||
|
wordBreak: "break-all",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{formatLogTime(log.at)}
|
||||||
|
</Typography.Text>
|
||||||
|
{" "}
|
||||||
|
{log.message}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</pre>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import type { BrandTemplateKey } from "@personal-brand/api-client";
|
|||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||||
|
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||||
|
|
||||||
const client = createApiClient();
|
const client = createApiClient();
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
const [activeTab, setActiveTab] = useState("content");
|
const [activeTab, setActiveTab] = useState("content");
|
||||||
const [miniAppSettingsForm] = Form.useForm<{
|
const [miniAppSettingsForm] = Form.useForm<{
|
||||||
appId: string;
|
appId: string;
|
||||||
|
apiBaseUrl: string;
|
||||||
artifactPath: string;
|
artifactPath: string;
|
||||||
privateKey?: string;
|
privateKey?: string;
|
||||||
}>();
|
}>();
|
||||||
@@ -85,12 +87,17 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
if (!miniAppSettings.data) return;
|
if (!miniAppSettings.data) return;
|
||||||
miniAppSettingsForm.setFieldsValue({
|
miniAppSettingsForm.setFieldsValue({
|
||||||
appId: miniAppSettings.data.appId,
|
appId: miniAppSettings.data.appId,
|
||||||
|
apiBaseUrl: miniAppSettings.data.apiBaseUrl,
|
||||||
artifactPath: miniAppSettings.data.artifactPath,
|
artifactPath: miniAppSettings.data.artifactPath,
|
||||||
privateKey: "",
|
privateKey: "",
|
||||||
});
|
});
|
||||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const building = miniAppReleases.data?.find((task) => task.buildStatus === "building");
|
const building = miniAppReleases.data?.find(
|
||||||
|
(task) =>
|
||||||
|
task.buildStatus === "building" &&
|
||||||
|
Date.now() - new Date(task.updatedAt).getTime() < 15 * 60 * 1000,
|
||||||
|
);
|
||||||
if (!building) return;
|
if (!building) return;
|
||||||
const timer = setInterval(() => void miniAppReleases.refetch(), 1500);
|
const timer = setInterval(() => void miniAppReleases.refetch(), 1500);
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
@@ -167,8 +174,8 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
const uploadLatestMiniAppRelease = useMutation({
|
const uploadLatestMiniAppRelease = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const latest = await client.getLatestAdminMiniAppRelease();
|
const latest = await client.getLatestAdminMiniAppRelease();
|
||||||
if (!latest) throw new Error("还没有可发布的内容版本");
|
const task = latest ?? (await client.createAdminMiniAppRelease());
|
||||||
return client.uploadAdminMiniAppRelease(latest.id);
|
return client.uploadAdminMiniAppRelease(task.id);
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("小程序代码已上传");
|
message.success("小程序代码已上传");
|
||||||
@@ -267,6 +274,23 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM
|
AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM
|
||||||
加密。小程序产物目录由系统构建流程决定,不需要手动修改。
|
加密。小程序产物目录由系统构建流程决定,不需要手动修改。
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
|
{miniAppSettings.data?.buildError ? (
|
||||||
|
<Alert
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
message="小程序构建参数未就绪"
|
||||||
|
description={miniAppSettings.data.buildError}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
message={`请求域名 ${miniAppSettings.data?.requestDomain ?? "未确认"}`}
|
||||||
|
description="该域名在构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致;不一致会导致小程序打开即加载失败。"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Form
|
<Form
|
||||||
form={miniAppSettingsForm}
|
form={miniAppSettingsForm}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
@@ -279,16 +303,42 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
>
|
>
|
||||||
<Input maxLength={100} />
|
<Input maxLength={100} />
|
||||||
</Form.Item>
|
</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
|
<Form.Item
|
||||||
name="privateKey"
|
name="privateKey"
|
||||||
label="上传私钥"
|
label="上传私钥"
|
||||||
help={
|
help={
|
||||||
miniAppSettings.data?.hasStoredCredentials
|
miniAppSettings.data?.hasStoredCredentials
|
||||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||||
: "粘贴以 -----BEGIN 开头的微信上传私钥。"
|
: "粘贴微信开发者工具导出的 private.<appid>.key 全文,必须保留换行。"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Input.Password autoComplete="new-password" />
|
<Input.TextArea
|
||||||
|
rows={5}
|
||||||
|
autoComplete="off"
|
||||||
|
spellCheck={false}
|
||||||
|
placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
|
||||||
|
style={{ fontFamily: "monospace", fontSize: 12 }}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
||||||
@@ -529,113 +579,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
|||||||
</Space>
|
</Space>
|
||||||
<Divider />
|
<Divider />
|
||||||
{miniAppReleases.data?.length ? (
|
{miniAppReleases.data?.length ? (
|
||||||
<Space direction="vertical" style={{ width: "100%" }}>
|
<Space direction="vertical" size={12} style={{ width: "100%" }}>
|
||||||
{miniAppReleases.data.map((task) => (
|
{miniAppReleases.data.map((task) => (
|
||||||
<Card key={task.id} size="small">
|
<MiniAppReleaseCard
|
||||||
<Space wrap>
|
key={task.id}
|
||||||
<Typography.Text>品牌 v{task.version}</Typography.Text>
|
task={task}
|
||||||
<Tag
|
uploading={uploadMiniAppRelease.isPending}
|
||||||
color={
|
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||||
task.status === "published"
|
onStatusChange={(status) => updateMiniAppStatus.mutate({ id: task.id, status })}
|
||||||
? "green"
|
/>
|
||||||
: task.status === "failed" || task.buildStatus === "failed"
|
|
||||||
? "red"
|
|
||||||
: task.buildStatus === "building"
|
|
||||||
? "orange"
|
|
||||||
: "blue"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{task.status}
|
|
||||||
</Tag>
|
|
||||||
{task.weappUploadId && (
|
|
||||||
<Typography.Text type="secondary">
|
|
||||||
微信版本 {task.weappUploadId}
|
|
||||||
</Typography.Text>
|
|
||||||
)}
|
|
||||||
{task.error && <Typography.Text type="danger">{task.error}</Typography.Text>}
|
|
||||||
{task.buildStatus === "building" && (
|
|
||||||
<Typography.Text type="secondary">正在构建微信小程序...</Typography.Text>
|
|
||||||
)}
|
|
||||||
{task.buildStatus === "failed" && (
|
|
||||||
<Typography.Text type="secondary">微信小程序构建失败</Typography.Text>
|
|
||||||
)}
|
|
||||||
{task.buildLogs?.length ? (
|
|
||||||
<Space direction="vertical" style={{ width: "100%" }}>
|
|
||||||
{task.buildLogs.slice(-8).map((log, index) => (
|
|
||||||
<Typography.Paragraph
|
|
||||||
key={`${log.at}-${index}`}
|
|
||||||
type={log.stream === "stderr" ? "danger" : "secondary"}
|
|
||||||
style={{ marginBottom: 0, whiteSpace: "pre-wrap", fontSize: 12 }}
|
|
||||||
code
|
|
||||||
>
|
|
||||||
{log.message}
|
|
||||||
</Typography.Paragraph>
|
|
||||||
))}
|
|
||||||
</Space>
|
|
||||||
) : null}
|
|
||||||
{(task.status === "built" || task.buildStatus === "failed") && (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
loading={uploadMiniAppRelease.isPending}
|
|
||||||
onClick={() => uploadMiniAppRelease.mutate(task.id)}
|
|
||||||
>
|
|
||||||
上传微信
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{task.status === "uploaded" && (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
updateMiniAppStatus.mutate({ id: task.id, status: "under_review" })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
标记提交审核
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{task.status === "under_review" && (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
updateMiniAppStatus.mutate({ id: task.id, status: "approved" })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
审核通过
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
danger
|
|
||||||
onClick={() =>
|
|
||||||
updateMiniAppStatus.mutate({ id: task.id, status: "rejected" })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
审核驳回
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{task.status === "approved" && (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
type="primary"
|
|
||||||
onClick={() =>
|
|
||||||
updateMiniAppStatus.mutate({ id: task.id, status: "published" })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
标记已发布
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{task.status === "failed" && (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
updateMiniAppStatus.mutate({ id: task.id, status: "built" })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
重置可上传
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
))}
|
))}
|
||||||
</Space>
|
</Space>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in new issue
Block a user