fix(desktop): 补回报告页剥离时漏搬的 PDF 导出与完成系统通知

759483b 把报告页剥成纯启动器时,Word/Markdown 导出搬去了运行页,但漏了两个:
printReportHtml(前端打印出 PDF,CJK 零字体依赖)和 notify(完成弹系统通知)
外部调用点归零,成了被孤立的活功能。

- 运行页报告正文面板补 PDF 按钮:previewRef 抓已渲染 DOM 送打印视图,
  与剥离前同一条路径。
- 完成通知挪进 attachRun 的 token 流 done 回调并加 label 参数:原先只有
  报告会通知,但「跑几分钟、人早切走了」对编排任务一样成立,且 attachRun
  是所有运行的唯一汇合点,放这儿不会再漂移。恢复的待审任务也带主题。

验证:tsc 干净、68 个 vitest 全过、两函数调用点恢复非零。
⚠️ 未实机点验(需登录态):PDF 按钮实际点击出打印视图、通知实际弹出,
下次起服务后补验。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-16 16:28:28 +08:00
parent 027ccc0ccc
commit d14a10479e
2 changed files with 33 additions and 9 deletions
+12 -5
View File
@@ -18,6 +18,7 @@ import { Login } from "./views/Login";
import { submitTask, generateReport, streamTokens, streamExec, taskStatus, listRuns, authMe, logout, tenantCurrent, myTenants, switchTenant, spaceCurrent, mySpaces, switchSpace, createSpace, type Identity, type AuthUser, type TenantCtx, type MyTenant, type SpaceCtx, type MySpace } from "./lib/api";
import type { TaskDsl } from "./lib/dsl";
import { emptyRun, type RunState } from "./lib/run";
import { notify } from "./lib/desktop";
import { ToastProvider } from "./ui";
// 会话标识:本地持久化生成一次(多轮历史用,与鉴权身份分离)。
@@ -178,7 +179,8 @@ export default function App() {
// attachRun:给一个 task 挂上「状态轮询 + 执行轨迹流 + token 流」。新发起与恢复待审任务共用,
// 故页面刷新/重开后能重新挂回在途任务(HITL 审批可能等数小时,必须可恢复,否则待审任务点不到批准)。
const attachRun = useCallback((taskId: string, t0: number) => {
// label 用于完成时的系统通知文案(报告用主题,编排用泛称)。
const attachRun = useCallback((taskId: string, t0: number, label: string) => {
let first = true;
// 轮询后端任务状态:可靠捕获 waiting(审批中断)—— exec 实时事件会抢跑,状态落 PG 不会丢。
const terminal = new Set(["done", "failed", "timeout", "rejected"]);
@@ -217,7 +219,12 @@ export default function App() {
first = false;
return { ...r, output: r.output + tok, events: ev };
}),
() => setRun((r) => (r.taskId === taskId ? { ...r, phase: "done", events: [...r.events, { t: Date.now() - t0, label: "完成" }] } : r)),
() => {
// 系统通知:跑一次动辄几分钟,用户多半已经切走干别的了——不通知就只能自己回来刷。
// 浏览器预览下 notify 是空操作,桌面壳里才弹。
notify("运行完成", label);
setRun((r) => (r.taskId === taskId ? { ...r, phase: "done", events: [...r.events, { t: Date.now() - t0, label: "完成" }] } : r));
},
() => setRun((r) => (r.taskId === taskId ? { ...r, phase: "error", error: "连接中断" } : r)),
);
}, []);
@@ -238,7 +245,7 @@ export default function App() {
taskId,
events: [...r.events, { t: Date.now() - t0, label: `已发布 ${taskId}` }],
}));
attachRun(taskId, t0);
attachRun(taskId, t0, "编排任务已跑完");
} catch (e) {
setRun((r) => ({ ...r, phase: "error", error: (e as Error).message }));
}
@@ -266,7 +273,7 @@ export default function App() {
taskId,
events: [...r.events, { t: Date.now() - t0, label: `已发布 ${taskId}` }],
}));
attachRun(taskId, t0);
attachRun(taskId, t0, `报告已生成:${topic}`);
} catch (e) {
setRun((r) => ({ ...r, phase: "error", error: (e as Error).message }));
}
@@ -291,7 +298,7 @@ export default function App() {
? r // 已有 live run,不覆盖
: { phase: "streaming", taskId: waiting.task_id, output: "", events: [{ t: 0, label: "恢复待审任务" }], exec: [], lifecycle: "waiting" },
);
attachRun(waiting.task_id, t0);
attachRun(waiting.task_id, t0, waiting.topic || "待审任务已跑完");
} catch {
/* 列表拉取失败则跳过恢复,不影响正常使用 */
}