// 同人确认发布弹窗(T3.3)。 // // 发布点击后打开本弹窗:并发拉「影响摘要」(fetchImpact) + 本地算「节点级 diff」(diffSummary, // 打开时源 XML vs 当前 saveXML) → 展示流程 key / 当前版本→新版本 / 运行中实例数(灰字提示旧版本 // 不受影响)/ 办理人·会签等变更节点清单 → 用户确认 → deployModel。 // - 成功:toast「已发布 vN」(用后端返回的真实 newVersion) + onPublished + 关闭。 // - 422 校验失败:按 errors 渲染节点错误清单,**不关弹窗**让用户回去改。 // - 通用失败:toast 报错,不关弹窗。 import { useEffect, useState } from 'react'; import { Dialog } from '../components/ui'; import { toast } from '../components/ui'; import { deployModel, fetchImpact, type DeployImpact, type DeployValidationError } from '../api/processModeler'; import { diffSummary, type NodeDiff } from './diffSummary'; interface PublishConfirmProps { /** 草稿 modelId(必须已存草稿才可发布)。 */ modelId: string; /** 打开流程时保存的源 XML(diff 基线)。 */ openSourceXml: string; /** 当前编辑器 saveXML 结果(diff 对比方;由父页在打开弹窗前算好)。 */ currentXml: string; /** impact 未回来 / 不可用时兜底显示的流程 key(loadedKey)。 */ processKeyHint?: string; onClose: () => void; /** 发布成功回调(带后端返回的真实新版本号)。 */ onPublished: (newVersion?: number) => void; } /** 单条校验错误的展示文案:activityId + 问题描述(defaultDescription 优先,回退 problem/message)。 */ function errorText(e: DeployValidationError): string { const desc = e.defaultDescription || e.problem || e.message || '校验未通过'; return e.activityId ? `[${e.activityId}] ${desc}` : desc; } export function PublishConfirm({ modelId, openSourceXml, currentXml, processKeyHint, onClose, onPublished, }: PublishConfirmProps) { // 节点级 diff 是纯本地同步计算,初始化即得。 const [diff] = useState(() => diffSummary(openSourceXml, currentXml)); const [impact, setImpact] = useState(null); const [impactLoaded, setImpactLoaded] = useState(false); const [deploying, setDeploying] = useState(false); const [errors, setErrors] = useState(null); useEffect(() => { let alive = true; fetchImpact(modelId) .then((r) => { if (!alive) return; setImpact(r); setImpactLoaded(true); }) .catch(() => { if (!alive) return; setImpact({ found: false }); setImpactLoaded(true); }); return () => { alive = false; }; }, [modelId]); async function handleConfirm() { if (deploying) return; setDeploying(true); setErrors(null); try { const r = await deployModel(modelId); if (r.ok) { toast('已发布 v' + (r.newVersion ?? '?'), 'ok'); onPublished(r.newVersion); onClose(); return; } if (r.validationErrors && r.validationErrors.length) { setErrors(r.validationErrors); // 校验清单 → 不关窗,让用户回去改 } else { toast(r.message ?? '发布失败', 'err'); } } finally { setDeploying(false); } } // M3:发布进行中拦截关闭(遮罩点击 / X 按钮),避免中途关窗留下不确定态。 const guardedClose = () => { if (!deploying) onClose(); }; const key = impact?.processKey || processKeyHint || '(未知)'; const cur = impact?.currentVersion ?? 0; const versionText = !impactLoaded ? '版本加载中…' : impact?.found ? cur > 0 ? `v${cur} → v${cur + 1}` : `首次发布 → v1` : '(版本信息暂不可用)'; const running = impact?.found ? (impact.runningInstances ?? 0) : undefined; const foot = ( <> ); return (
{/* 影响摘要 */}
{key} {versionText} {running === undefined ? '—' : running} (留在旧版本,不受本次发布影响)
{/* 节点级变更清单 */}
办理人 / 会签等变更节点
{diff.length === 0 ? (
未检测到办理人 / 会签 / 表单等关键属性变化(可能仅调整了布局或其他节点)。
) : (
    {diff.map((d, i) => (
  • {d.nodeName}:{d.changes.join('、')}
  • ))}
)}
{/* 校验错误清单(422,不关窗) */} {errors && errors.length ? (
校验未通过,请修正后重试:
    {errors.map((e, i) => (
  • {errorText(e)}
  • ))}
) : null}
); } function Row({ label, children }: { label: string; children: React.ReactNode }) { return (
{label} {children}
); }