import { useEffect, useRef } from "react"; import { Button, Card, Collapse, Flex, Space, Tooltip, Typography } from "antd"; import type { MiniAppReleaseTask } from "@personal-brand/api-client"; import { ErrorNote } from "../../components/QueryState.js"; import { StatusTag } from "../../components/StatusTag.js"; import type { StatusTone } from "../../components/StatusTag.js"; type ReleaseStatus = MiniAppReleaseTask["status"]; const STALE_BUILDING_MS = 30 * 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 = { built: { label: "待上传", tone: "neutral", hint: "代码已构建,可上传到微信。" }, uploaded: { label: "已上传微信", tone: "info", hint: "请在微信后台上传体验版并提交审核。" }, under_review: { label: "审核中", tone: "warning", hint: "等待微信审核结果,通过后回到本页标记。", }, approved: { label: "审核通过", tone: "success", hint: "审核已通过,确认无误后标记为已发布。" }, published: { label: "已发布", tone: "success", hint: "该版本已发布,可继续编辑内容后再次上传。" }, rejected: { label: "已驳回", tone: "error", hint: "微信驳回后需修改内容并重新构建上传。" }, failed: { label: "失败", tone: "error", hint: "上次构建或上传失败,可直接重试。" }, }; const uploadStatusView: Record< NonNullable, { label: string; tone: StatusTone } > = { idle: { label: "未上传", tone: "neutral" }, uploading: { label: "上传中", tone: "warning" }, uploaded: { label: "上传完成", tone: "success" }, failed: { label: "上传失败", tone: "error" }, timed_out: { label: "上传超时", tone: "error" }, }; const reviewStatusView: Record< NonNullable, { label: string; tone: StatusTone } > = { not_submitted: { label: "未提交审核", tone: "neutral" }, under_review: { label: "审核中", tone: "warning" }, approved: { label: "审核通过", tone: "success" }, rejected: { label: "审核驳回", tone: "error" }, }; 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 logRef = useRef(null); const logs = task.buildLogs ?? []; const status = statusView[task.status]; const uploadStatus = task.uploadStatus ? uploadStatusView[task.uploadStatus] : null; const reviewStatus = task.reviewStatus ? reviewStatusView[task.reviewStatus] : null; 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 = ( {(task.status === "built" || task.status === "failed" || staleBuilding) && ( )} {task.status === "uploaded" && ( )} {task.status === "under_review" && ( <> )} {task.status === "approved" && ( )} ); return ( 品牌内容 v{task.version} {building && ( )} {!building && task.buildStatus === "success" && ( )} {uploadStatus && } {reviewStatus && reviewStatusView[task.reviewStatus ?? "not_submitted"] && ( )} {task.weappUploadId && ( 微信版本 {task.weappUploadId} )} {staleBuilding ? "超过 30 分钟没有新的构建输出,可能已中断;可直接重试。" : status.hint} 更新于 {formatTime(task.updatedAt)} {actions} {task.error && (
)} {logs.length > 0 && ( 构建日志({logs.length} 行), children: (
                  {logs.map((log, index) => (
                    
{formatLogTime(log.at)} {" "} {log.message}
))}
), }, ]} /> )}
); }