ScheduledJobManagementPage.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. * 册10 SC-01/SC-02 任务清单页(路由 /daily-tasks,契约路由 /bos/job/list)。
  3. * 契约:docs/.../10-第10册-定时任务与审计视图/14-页面契约本册逐页.md §14.1、作业§3。
  4. * 接线状态:
  5. * - 行集=`/jobs/get_list@v1` 真实下发(13 行=注册位 11 +标注行 2);
  6. * - 主表只呈现业务组 9 行;系统维护组 4 行移入标题栏右侧「系统维护任务」弹窗(2026-11-15 页面分区调整),
  7. * 避免业务用户把系统维护任务与业务任务混淆;分组、可操作性位与统计口径不变;
  8. * - 状态列、可操作性位、五格计数、最近执行与累计轮次均由服务端兜底调度器实时聚合;
  9. * - KPI 五卡与页顶告警条同源同数(`kpi`/`pending_reruns`)。
  10. */
  11. import { useMemo, useState } from "react";
  12. import { PageIntro } from "../components/PageIntro";
  13. import { CalendarClock, ChevronDown, History, Info, TriangleAlert, Wrench, X } from "lucide-react";
  14. import { Button } from "../components/ui/button";
  15. import { OpsDialog, OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
  16. import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
  17. import { useDemoIdentity } from "../lib/demo-session";
  18. import {
  19. fmtDateTime,
  20. fmtDateTimeParts,
  21. fmtDurationMs,
  22. submitJobToggle,
  23. useJobCenter,
  24. type JobListRow,
  25. } from "../lib/scheduled-jobs";
  26. import {
  27. ANNOTATION_SUBMIT,
  28. BTN_CANCEL,
  29. BTN_CONFIRM_DISABLE,
  30. BTN_CONFIRM_ENABLE,
  31. CONFIRM_DISABLE_TITLE,
  32. CONFIRM_ENABLE_TITLE,
  33. KPI_ABNORMAL_TODAY,
  34. KPI_OBJECTS_TODAY,
  35. KPI_PENDING_RERUN,
  36. KPI_RUNS_TODAY,
  37. MAINT_CLOSE,
  38. MAINT_DIALOG_TITLE,
  39. MAINT_TRIGGER,
  40. NEVER_RUN,
  41. PLAN_DISABLED,
  42. PLAN_NOT_WIRED,
  43. RUNTIME_PENDING,
  44. STATE_DISABLED,
  45. STATE_ENABLED,
  46. STATE_NOT_WIRED,
  47. STATE_NO_SWITCH,
  48. W1,
  49. W2P,
  50. W2PP,
  51. W4,
  52. W5,
  53. W6,
  54. W7,
  55. W7P_DISABLED,
  56. W7P_LOCAL,
  57. W7P_PLATFORM,
  58. W8,
  59. W20,
  60. W23_DETAIL,
  61. W23_DISABLE,
  62. W23_ENABLE,
  63. W23_RUNS,
  64. W23_VIEW_RUNS,
  65. W25,
  66. maintSubtitle,
  67. w24,
  68. w9,
  69. } from "../lib/copy-jobs";
  70. import { JobRunsDialog, type JobRunsPreset } from "./JobRunsDialog";
  71. import { ListPager } from "../components/ListPager";
  72. import { slicePage, useLocalPage } from "../lib/list-paging";
  73. import "../styles/operations.css";
  74. import "../styles/scheduled-jobs.css";
  75. /* ── 单元格渲染 ────────────────────────────────────────────────── */
  76. function RuntimePendingCell() {
  77. return (
  78. <span className="job-cell-pending">
  79. —<small>{RUNTIME_PENDING}</small>
  80. </span>
  81. );
  82. }
  83. /** 任务状态由服务端决定。 */
  84. function StateCell({ row }: { row: JobListRow }) {
  85. if (row.annotation) return <OpsStatus tone="neutral">{STATE_NO_SWITCH}</OpsStatus>;
  86. if (!row.wired) return <OpsStatus tone="warning">{STATE_NOT_WIRED}</OpsStatus>;
  87. if (row.enabled === true) return <OpsStatus tone="success">{STATE_ENABLED}</OpsStatus>;
  88. if (row.enabled === false) return <OpsStatus tone="neutral">{STATE_DISABLED}</OpsStatus>;
  89. // 后端取数失败 ⇒ 诚实「未取到」,⛔ 猜启用态
  90. return <RuntimePendingCell />;
  91. }
  92. /** 启停权限由服务端返回的 toggleable 和 reason_code 决定。 */
  93. function ToggleCell({ row, isAdmin, onToggle }: { row: JobListRow; isAdmin: boolean; onToggle: (row: JobListRow, enable: boolean) => void }) {
  94. if (row.annotation) return null; // 格⑤:无操作标记
  95. if (row.reasonCode === "NOT_WIRED") return <small className="job-cell-note">{W5}</small>;
  96. if (row.toggleable === true && isAdmin) {
  97. const enabled = row.enabled === true;
  98. return (
  99. <button className={enabled ? "ops-table-action job-toggle-danger" : "ops-table-action"} type="button" aria-haspopup="dialog" onClick={() => onToggle(row, !enabled)}>
  100. {enabled ? W23_DISABLE : W23_ENABLE}
  101. </button>
  102. );
  103. }
  104. if (row.reasonCode === "ROLE_READONLY") return <small className="job-cell-note">{W6}</small>;
  105. if (row.toggleable === false && row.reasonCode === "NO_SWITCH") return null; // 无开关 ⇒ 无操作标记
  106. if (!isAdmin && row.wired) return <small className="job-cell-note">{W6}</small>;
  107. if (row.toggleable === false) return <small className="job-cell-note">{W5}</small>;
  108. // 运行态未取到:不渲启停位(总则§16.9)
  109. return null;
  110. }
  111. /* ── 启停确认弹窗(SC-02) ────────────────────────────────────────── */
  112. function ToggleConfirmDialog({
  113. row,
  114. enable,
  115. onCancel,
  116. onDone,
  117. }: {
  118. row: JobListRow;
  119. enable: boolean;
  120. onCancel: () => void;
  121. onDone: (message: string, refresh: boolean) => void;
  122. }) {
  123. const [pending, setPending] = useState(false);
  124. const [error, setError] = useState<string | null>(null);
  125. const name = row.displayName;
  126. const schedule = row.cronHint || row.meta?.scheduleText || "";
  127. const submit = async () => {
  128. setPending(true);
  129. setError(null);
  130. const outcome = await submitJobToggle(row, enable);
  131. setPending(false);
  132. if (outcome.kind === "error") {
  133. setError(outcome.message); // 失败:弹窗保持,⛔ 关窗吞错
  134. return;
  135. }
  136. onDone(outcome.message, true); // 成功/部分成功/并发:统一重拉清单(并发态恒 W12+刷新)
  137. };
  138. return (
  139. <div className="ops-confirm-backdrop" role="presentation" onMouseDown={onCancel}>
  140. <div className="ops-confirm" role="dialog" aria-modal="true" aria-labelledby="job-toggle-title" onMouseDown={(event) => event.stopPropagation()}>
  141. <h2 id="job-toggle-title">{enable ? CONFIRM_ENABLE_TITLE(name) : CONFIRM_DISABLE_TITLE(name)}</h2>
  142. <p>
  143. {enable ? w9(schedule) : W8}
  144. {!enable && row.stopImpactNote ? ` ${row.stopImpactNote}` : ""}
  145. </p>
  146. {error && (
  147. <p className="ops-form-error" role="alert">
  148. {error}
  149. </p>
  150. )}
  151. <div>
  152. <Button type="button" variant="ghost" disabled={pending} onClick={onCancel}>
  153. {BTN_CANCEL}
  154. </Button>
  155. <Button type="button" disabled={pending} onClick={submit}>
  156. {pending ? "提交中…" : enable ? BTN_CONFIRM_ENABLE : BTN_CONFIRM_DISABLE}
  157. </Button>
  158. </div>
  159. </div>
  160. </div>
  161. );
  162. }
  163. function RunStatus({ row }: { row: JobListRow }) {
  164. return <OpsStatus tone={row.lastStatusTone === "success" ? "success" : row.lastStatusTone === "failed" ? "danger" : "warning"}>{row.lastStatus}</OpsStatus>;
  165. }
  166. /* ── 作业定义弹窗 ────────────────────────────────────────────────── */
  167. function JobDefinitionDialog({ row, onClose, onViewRuns }: { row: JobListRow; onClose: () => void; onViewRuns: () => void }) {
  168. const planText = row.annotation
  169. ? "—"
  170. : !row.wired
  171. ? PLAN_NOT_WIRED
  172. : row.enabled === false
  173. ? PLAN_DISABLED
  174. : row.enabled === true
  175. ? row.cronHint
  176. : "—";
  177. return (
  178. <OpsDialog title={row.displayName} subtitle={w24(row.key)} className="job-definition-dialog" onClose={onClose}>
  179. <div className="job-definition-body">
  180. <dl className="job-definition-overview">
  181. <div>
  182. <dt>当前状态</dt>
  183. <dd><StateCell row={row} /></dd>
  184. </div>
  185. <div>
  186. <dt>累计执行轮次</dt>
  187. <dd className="job-definition-total">{row.runCount?.toLocaleString("zh-CN") ?? "—"}</dd>
  188. </div>
  189. <div>
  190. <dt>最近一次执行</dt>
  191. <dd className="job-definition-latest">
  192. {row.lastRunAt ? (
  193. <>
  194. <time dateTime={row.lastRunAt}>{fmtDateTime(row.lastRunAt)}</time>
  195. {row.lastStatus && <RunStatus row={row} />}
  196. </>
  197. ) : row.annotation ? "不适用" : NEVER_RUN}
  198. </dd>
  199. </div>
  200. </dl>
  201. <div className="job-definition-sections">
  202. <section className="job-definition-panel">
  203. <h3>调度配置</h3>
  204. <dl>
  205. <div><dt>任务名称(注册契约)</dt><dd>{row.registryName}</dd></div>
  206. <div><dt>触发方式</dt><dd>{row.triggerText}</dd></div>
  207. <div><dt>调度时点</dt><dd>{row.annotation ? ANNOTATION_SUBMIT : row.cronHint}</dd></div>
  208. <div><dt>下轮计划</dt><dd>{planText}</dd></div>
  209. </dl>
  210. </section>
  211. <section className="job-definition-panel">
  212. <h3>执行规则</h3>
  213. <dl>
  214. <div><dt>处理对象</dt><dd>{row.objectScope ?? "—"}</dd></div>
  215. <div><dt>执行动作</dt><dd>{row.actionText ?? "—"}</dd></div>
  216. <div><dt>幂等口径</dt><dd>{row.idempotencyText ?? "—"}</dd></div>
  217. </dl>
  218. </section>
  219. </div>
  220. <p className="job-definition-note">{W25}</p>
  221. </div>
  222. <footer className="job-definition-footer">
  223. <Button type="button" variant="outline" onClick={onClose}>关闭</Button>
  224. <Button type="button" onClick={onViewRuns}><History size={16} aria-hidden="true" />{W23_VIEW_RUNS}</Button>
  225. </footer>
  226. </OpsDialog>
  227. );
  228. }
  229. /* ── 系统维护任务弹窗(2026-11-15:系统维护组不进主表,改由标题栏右侧图标进入) ── */
  230. function MaintRow({
  231. row,
  232. isAdmin,
  233. onDetail,
  234. onRuns,
  235. onToggle,
  236. }: {
  237. row: JobListRow;
  238. isAdmin: boolean;
  239. onDetail: (row: JobListRow) => void;
  240. onRuns: (row: JobListRow) => void;
  241. onToggle: (row: JobListRow, enable: boolean) => void;
  242. }) {
  243. const parts = row.lastRunAt ? fmtDateTimeParts(row.lastRunAt) : null;
  244. return (
  245. <tr>
  246. <td className="ops-mono">{row.key}</td>
  247. <td>
  248. <span className="table-cell-title">{row.displayName}</span>
  249. </td>
  250. <td>
  251. <span>{row.cronHint}</span>
  252. <small>{row.triggerText}</small>
  253. </td>
  254. <td>
  255. {parts ? (
  256. <span className="ops-mono">
  257. {parts.date} {parts.time}
  258. </span>
  259. ) : (
  260. NEVER_RUN
  261. )}
  262. </td>
  263. <td>
  264. <StateCell row={row} />
  265. </td>
  266. <td>
  267. <div className="ops-table-actions">
  268. <button className="ops-table-action" type="button" onClick={() => onDetail(row)}>
  269. <Info size={14} /> {W23_DETAIL}
  270. </button>
  271. <button className="ops-table-action" type="button" onClick={() => onRuns(row)}>
  272. <History size={14} /> {W23_RUNS}
  273. </button>
  274. <ToggleCell row={row} isAdmin={isAdmin} onToggle={onToggle} />
  275. </div>
  276. </td>
  277. </tr>
  278. );
  279. }
  280. function SystemJobsDialog({
  281. rows,
  282. isAdmin,
  283. onClose,
  284. onDetail,
  285. onRuns,
  286. onToggle,
  287. }: {
  288. rows: JobListRow[];
  289. isAdmin: boolean;
  290. onClose: () => void;
  291. onDetail: (row: JobListRow) => void;
  292. onRuns: (row: JobListRow) => void;
  293. onToggle: (row: JobListRow, enable: boolean) => void;
  294. }) {
  295. const enabled = rows.filter((row) => row.enabled === true).length;
  296. return (
  297. <div className="ops-confirm-backdrop" role="presentation" onMouseDown={onClose}>
  298. <div
  299. className="ops-confirm ops-maint-dialog"
  300. role="dialog"
  301. aria-modal="true"
  302. aria-labelledby="maint-title"
  303. onMouseDown={(event) => event.stopPropagation()}
  304. >
  305. <div className="ops-maint-head">
  306. <div>
  307. <h2 id="maint-title">{MAINT_DIALOG_TITLE}</h2>
  308. <p className="ops-maint-meta">{maintSubtitle(rows.length, enabled)}</p>
  309. </div>
  310. <button className="ops-maint-close" type="button" aria-label={MAINT_CLOSE} onClick={onClose}>
  311. <X size={16} />
  312. </button>
  313. </div>
  314. {/* W2″:原为页顶第三句横幅;系统维护组离开主表后,该说明随组进入本弹窗 */}
  315. <p className="ops-import-note ops-maint-note">{W2PP}</p>
  316. <div className="ops-maint-body">
  317. <table className="ops-maint-table">
  318. <thead>
  319. <tr>
  320. <th>任务编码</th>
  321. <th>任务名称</th>
  322. <th>调度与触发</th>
  323. <th>上次执行</th>
  324. <th>状态</th>
  325. <th className="ops-maint-actions-head">操作</th>
  326. </tr>
  327. </thead>
  328. <tbody>
  329. {rows.map((row) => (
  330. <MaintRow
  331. key={row.key}
  332. row={row}
  333. isAdmin={isAdmin}
  334. onDetail={onDetail}
  335. onRuns={onRuns}
  336. onToggle={onToggle}
  337. />
  338. ))}
  339. </tbody>
  340. </table>
  341. </div>
  342. <div className="ops-maint-foot">
  343. <Button type="button" variant="ghost" onClick={onClose}>
  344. {MAINT_CLOSE}
  345. </Button>
  346. </div>
  347. </div>
  348. </div>
  349. );
  350. }
  351. /* ── 页面本体 ─────────────────────────────────────────────────────── */
  352. export function ScheduledJobManagementPage() {
  353. const identity = useDemoIdentity();
  354. const isAdmin = identity?.role === "admin";
  355. const center = useJobCenter();
  356. const [notice, setNotice] = useState<string | null>(null);
  357. const [toggleTarget, setToggleTarget] = useState<{ row: JobListRow; enable: boolean } | null>(null);
  358. const [defRow, setDefRow] = useState<JobListRow | null>(null);
  359. const [runsPreset, setRunsPreset] = useState<JobRunsPreset | null>(null);
  360. const [maintOpen, setMaintOpen] = useState(false);
  361. const scroll = useHorizontalOverflow();
  362. // 2026-11-15:系统维护组不再进主表(避免与业务任务混淆),改由标题栏右侧入口弹窗查看。
  363. const businessRows = useMemo(() => center.rows.filter((row) => row.group === "business"), [center.rows]);
  364. const systemRows = useMemo(() => center.rows.filter((row) => row.group === "system"), [center.rows]);
  365. const hasAnnotation = center.rows.some((row) => row.annotation);
  366. // 分页只覆盖主表(业务组);系统维护组走弹窗,不参与分页与「共 N 行」。
  367. const paging = useLocalPage(businessRows.length);
  368. const pageRows = slicePage(businessRows, paging.safePage);
  369. const openRuns = (row: JobListRow) => {
  370. setMaintOpen(false);
  371. setRunsPreset({ jobKey: row.key, jobName: row.displayName });
  372. };
  373. const widths = [18, 15, 12, 12, 14, 10, 19];
  374. const { kpi, scheduler } = center;
  375. const schedulerLabel = scheduler?.source === "platform" ? "平台调度" : scheduler?.source === "local" ? "进程内调度" : "调度已关闭";
  376. const schedulerNote = scheduler?.source === "platform" ? W7P_PLATFORM : scheduler?.source === "local" ? W7P_LOCAL : W7P_DISABLED;
  377. const metrics = [
  378. {
  379. title: "启用/全部",
  380. value: kpi?.tasks_enabled ?? "—",
  381. total: kpi?.tasks_enabled == null ? undefined : kpi.tasks_total,
  382. icon: CalendarClock,
  383. note: kpi ? `系统维护任务 ${kpi.system_enabled ?? "—"} / ${kpi.system_total},单独统计` : undefined,
  384. },
  385. { title: KPI_RUNS_TODAY, value: kpi?.runs_today ?? "—" },
  386. { title: KPI_OBJECTS_TODAY, value: kpi?.objects_today ?? "—" },
  387. { title: KPI_ABNORMAL_TODAY, value: kpi?.abnormal_today ?? "—", attention: (kpi?.abnormal_today ?? 0) > 0 },
  388. { title: KPI_PENDING_RERUN, value: kpi?.pending_rerun ?? "—", attention: (kpi?.pending_rerun ?? 0) > 0 },
  389. ];
  390. const renderRow = (row: JobListRow) => {
  391. const lastRun = fmtDateTimeParts(row.lastRunAt);
  392. const counts = row.lastCounts;
  393. return (
  394. <tr key={row.key}>
  395. <td>
  396. <span className="table-cell-title">{row.displayName}</span>
  397. <code className="ops-mono">{row.key}</code>
  398. </td>
  399. <td>
  400. {row.annotation ? <span className="job-ledger-trigger">{ANNOTATION_SUBMIT}</span> : (
  401. <>
  402. <span className="job-ledger-trigger">{row.cronHint}</span>
  403. <small>{row.triggerText}</small>
  404. </>
  405. )}
  406. </td>
  407. <td>
  408. {row.annotation ? "—" : row.lastRunAt ? (
  409. <>
  410. <time dateTime={row.lastRunAt} className="job-ledger-time">{lastRun.date} {lastRun.time}</time>
  411. <small>耗时 {fmtDurationMs(row.lastDurationMs)}</small>
  412. </>
  413. ) : NEVER_RUN}
  414. </td>
  415. <td>{row.lastStatus && !row.annotation ? <RunStatus row={row} /> : "—"}</td>
  416. <td>
  417. {row.annotation ? "—" : counts ? (
  418. <span className="job-ledger-counts ops-mono table-number">
  419. {counts.scanned}{" / "}{counts.matched}{" / "}{counts.succeeded}{" / "}{counts.skipped}{" / "}
  420. <span className={counts.failed > 0 ? "is-failed" : undefined}>{counts.failed}</span>
  421. </span>
  422. ) : <RuntimePendingCell />}
  423. </td>
  424. <td><StateCell row={row} /></td>
  425. <td>
  426. <div className="ops-table-actions job-ledger-actions">
  427. <button className="ops-table-action job-ledger-history" type="button" aria-haspopup="dialog" onClick={() => openRuns(row)}>
  428. <History size={14} /> {W23_RUNS}
  429. </button>
  430. <button className="ops-table-action" type="button" aria-haspopup="dialog" onClick={() => setDefRow(row)}>{W23_DETAIL}</button>
  431. <ToggleCell row={row} isAdmin={isAdmin} onToggle={(target, enable) => setToggleTarget({ row: target, enable })} />
  432. </div>
  433. </td>
  434. </tr>
  435. );
  436. };
  437. return (
  438. <section className="ops-page scheduled-jobs-page">
  439. <header className="ops-heading scheduled-jobs-head">
  440. <div>
  441. <h1>定时任务</h1>
  442. <PageIntro>跟踪后台作业的调度与执行,发现异常后可回查每轮记录。</PageIntro>
  443. </div>
  444. {systemRows.length > 0 && (
  445. <button
  446. className="scheduled-jobs-maint-trigger"
  447. type="button"
  448. aria-haspopup="dialog"
  449. aria-label={`${MAINT_TRIGGER}(共 ${systemRows.length} 个)`}
  450. onClick={() => setMaintOpen(true)}
  451. >
  452. <Wrench size={16} aria-hidden="true" />
  453. <span>{MAINT_TRIGGER}</span>
  454. <span className="scheduled-jobs-maint-count">{systemRows.length}</span>
  455. </button>
  456. )}
  457. </header>
  458. <section className="scheduled-jobs-overview" aria-label="运行概览">
  459. <dl className="scheduled-jobs-metrics">
  460. {metrics.map(({ title, value, total, icon: Icon, note, attention }) => (
  461. <div className={Icon ? "scheduled-jobs-metric scheduled-jobs-metric--lead" : "scheduled-jobs-metric"} key={title}>
  462. <dt>
  463. {Icon && <span className="scheduled-jobs-metric-icon"><Icon size={21} aria-hidden="true" /></span>}
  464. {title}
  465. </dt>
  466. <dd className={center.runtimeAvailable && attention ? "is-attention" : undefined}>
  467. {center.runtimeAvailable ? (typeof value === "number" ? value.toLocaleString("zh-CN") : value) : "—"}
  468. {center.runtimeAvailable && total !== undefined && <small> / {total.toLocaleString("zh-CN")}</small>}
  469. </dd>
  470. {center.runtimeAvailable && note && <dd className="scheduled-jobs-metric-note">{note}</dd>}
  471. </div>
  472. ))}
  473. </dl>
  474. {!center.runtimeAvailable && !center.loading && !center.error && (
  475. <p className="scheduled-jobs-runtime-note" role="status">{W7}{center.runtimeError ? ` · ${center.runtimeError}` : ""}</p>
  476. )}
  477. </section>
  478. {center.pendingReruns.length > 0 && (
  479. <details className="scheduled-jobs-reruns">
  480. <summary>
  481. <TriangleAlert size={17} aria-hidden="true" />
  482. <strong>待人工补跑</strong>
  483. <span>{center.pendingReruns.length} 轮</span>
  484. <ChevronDown size={16} aria-hidden="true" />
  485. </summary>
  486. <ul>
  487. {center.pendingReruns.map((run) => {
  488. const row = center.rows.find((job) => job.key === run.job_key);
  489. return (
  490. <li key={run.run_id}>
  491. <span><strong>{run.job_name}</strong><small>{fmtDateTime(run.started_at)} · {run.run_id}</small></span>
  492. {row && <button className="ops-table-action" type="button" aria-haspopup="dialog" onClick={() => openRuns(row)}>{W23_RUNS}</button>}
  493. </li>
  494. );
  495. })}
  496. </ul>
  497. </details>
  498. )}
  499. <section className="ops-list-shell scheduled-jobs-panel" aria-label="业务任务">
  500. {center.error && (
  501. <div className="scheduled-jobs-load-error" role="alert">
  502. <p>{W20}:{center.error}</p>
  503. <Button size="sm" type="button" variant="outline" onClick={center.reload}>重试</Button>
  504. </div>
  505. )}
  506. <div
  507. ref={scroll.ref}
  508. className={scroll.overflow ? "measured-table-scroll ops-table-wrap has-horizontal-overflow" : "measured-table-scroll ops-table-wrap"}
  509. role="region"
  510. aria-label="业务任务清单,可横向滚动查看"
  511. tabIndex={0}
  512. >
  513. <table className="ops-table job-ledger">
  514. <OpsTableColumns widths={widths} />
  515. <thead>
  516. <tr>
  517. <th scope="col">任务</th>
  518. <th scope="col">调度与触发</th>
  519. <th scope="col">最近执行</th>
  520. <th scope="col">执行结果</th>
  521. <th scope="col">对象处理<small>扫描 / 命中 / 成功 / 跳过 / 失败</small></th>
  522. <th scope="col">状态</th>
  523. <th scope="col">操作</th>
  524. </tr>
  525. </thead>
  526. <tbody>
  527. {pageRows.map(renderRow)}
  528. {center.loading && <OpsTableEmpty colSpan={7}>正在加载…</OpsTableEmpty>}
  529. {!center.loading && businessRows.length === 0 && !center.error && (
  530. <OpsTableEmpty colSpan={7}>调度平台注册位为空。</OpsTableEmpty>
  531. )}
  532. </tbody>
  533. </table>
  534. </div>
  535. {scroll.overflow && <p className="scheduled-jobs-scroll-hint">横向滚动查看全部字段</p>}
  536. <ListPager total={businessRows.length} page={paging.safePage} pageSize={paging.pageSize} onPageChange={paging.setPage} unit="项" className="list-pager" />
  537. </section>
  538. <details className="scheduled-jobs-notes">
  539. <summary>
  540. 调度说明
  541. {scheduler && <span className="scheduled-jobs-source" data-scheduler-source={scheduler.source}>{schedulerLabel}</span>}
  542. {center.missingRegistryKeys.length > 0 && " · 注册表有缺位"}
  543. <ChevronDown size={15} aria-hidden="true" />
  544. </summary>
  545. <ul>
  546. {scheduler && <li>{schedulerNote}{scheduler.source === "platform" && scheduler.cmd_topic ? `(命令通道 ${scheduler.cmd_topic})` : ""}</li>}
  547. <li>{W1}</li>
  548. {hasAnnotation && <li>{W2P}</li>}
  549. <li>{W4}</li>
  550. {center.missingRegistryKeys.length > 0 && <li>后端注册表缺位:{center.missingRegistryKeys.join("、")}</li>}
  551. </ul>
  552. </details>
  553. {/* 系统维护任务弹窗(标题栏右侧入口);确认/定义弹窗在其后渲染,同层叠顺序下覆盖其上 */}
  554. {maintOpen && systemRows.length > 0 && (
  555. <SystemJobsDialog
  556. rows={systemRows}
  557. isAdmin={isAdmin}
  558. onClose={() => setMaintOpen(false)}
  559. onDetail={(row) => setDefRow(row)}
  560. onRuns={openRuns}
  561. onToggle={(target, enable) => setToggleTarget({ row: target, enable })}
  562. />
  563. )}
  564. {toggleTarget && (
  565. <ToggleConfirmDialog
  566. row={toggleTarget.row}
  567. enable={toggleTarget.enable}
  568. onCancel={() => setToggleTarget(null)}
  569. onDone={(message, refresh) => {
  570. setToggleTarget(null);
  571. setNotice(message);
  572. if (refresh) center.reload();
  573. }}
  574. />
  575. )}
  576. {defRow && (
  577. <JobDefinitionDialog
  578. row={defRow}
  579. onClose={() => setDefRow(null)}
  580. onViewRuns={() => {
  581. const row = defRow;
  582. setDefRow(null);
  583. openRuns(row);
  584. }}
  585. />
  586. )}
  587. {runsPreset && (
  588. <JobRunsDialog preset={runsPreset} rows={center.rows} onClose={() => setRunsPreset(null)} />
  589. )}
  590. {notice && <OpsNotice message={notice} onClose={() => setNotice(null)} />}
  591. </section>
  592. );
  593. }