Jelajahi Sumber

将定时任务执行记录改为居中对话框

sy 2 jam lalu
induk
melakukan
b84d182c8c

+ 46 - 4
web-scaffold/src/components/OperationsKit.tsx

@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState, type ReactNode } from "react";
+import { useEffect, useId, useRef, useState, type ReactNode } from "react";
 import { createPortal } from "react-dom";
 import { Check, ChevronDown, ChevronUp, X } from "lucide-react";
 import { Button } from "./ui/button";
@@ -7,8 +7,50 @@ import type { StatusTone } from "../domain/statuses";
 
 export type OpsTone = StatusTone | "brand";
 
-/** 管理页通用右侧抽屉;视觉与工单/每日任务页保持一致。wide=66% 宽(册10 执行记录抽屉契约)。 */
-export function OpsDrawer({ title, subtitle, onClose, wide = false, children }: { title: string; subtitle: string; onClose: () => void; wide?: boolean; children: ReactNode }) {
+export function OpsDialog({ title, subtitle, onClose, className, children }: {
+  title: string;
+  subtitle?: string;
+  onClose: () => void;
+  className?: string;
+  children: ReactNode;
+}) {
+  const ref = useRef<HTMLDialogElement>(null);
+  const titleId = useId();
+
+  useEffect(() => {
+    const dialog = ref.current;
+    if (!dialog) return;
+    dialog.showModal();
+    return () => dialog.close();
+  }, []);
+
+  return (
+    <dialog
+      ref={ref}
+      className={className ? `ops-dialog ops-content-dialog ${className}` : "ops-dialog ops-content-dialog"}
+      aria-labelledby={titleId}
+      onCancel={(event) => {
+        event.preventDefault();
+        event.stopPropagation();
+        onClose();
+      }}
+      onClick={(event) => {
+        if (event.target === event.currentTarget) onClose();
+      }}
+    >
+      <header>
+        <div>
+          {subtitle && <p>{subtitle}</p>}
+          <h2 id={titleId}>{title}</h2>
+        </div>
+        <Button type="button" variant="ghost" size="icon" aria-label="关闭对话框" onClick={onClose}><X size={19} /></Button>
+      </header>
+      {children}
+    </dialog>
+  );
+}
+
+export function OpsDrawer({ title, subtitle, onClose, children }: { title: string; subtitle: string; onClose: () => void; children: ReactNode }) {
   const ref = useRef<HTMLDialogElement>(null);
   useEffect(() => {
     const dialog = ref.current;
@@ -19,7 +61,7 @@ export function OpsDrawer({ title, subtitle, onClose, wide = false, children }:
     dialog.showModal();
     return () => { dialog.close(); document.body.style.overflow = overflow; previous?.focus(); };
   }, []);
-  return <dialog ref={ref} className={`ops-drawer${wide ? " ops-drawer--wide" : ""}`} aria-labelledby="ops-drawer-title" onCancel={onClose} onClick={(event) => { if (event.target === event.currentTarget) onClose(); }}>
+  return <dialog ref={ref} className="ops-drawer" aria-labelledby="ops-drawer-title" onCancel={onClose} onClick={(event) => { if (event.target === event.currentTarget) onClose(); }}>
     <header><div><p>{subtitle}</p><h2 id="ops-drawer-title">{title}</h2></div><Button variant="ghost" size="icon" aria-label="关闭抽屉" onClick={onClose}><X size={19} /></Button></header>
     {children}
   </dialog>;

+ 44 - 0
web-scaffold/src/components/__tests__/operations-dialog.test.tsx

@@ -0,0 +1,44 @@
+import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
+import { useState } from "react";
+import { expect, it } from "vitest";
+import { OpsDialog } from "../OperationsKit";
+
+function RunHistory() {
+  const [historyOpen, setHistoryOpen] = useState(true);
+  const [roundOpen, setRoundOpen] = useState(false);
+
+  if (!historyOpen) return null;
+
+  return (
+    <OpsDialog title="执行记录" onClose={() => setHistoryOpen(false)}>
+      <button onClick={() => setRoundOpen(true)}>查看轮次</button>
+      {roundOpen && <OpsDialog title="轮次详情" onClose={() => setRoundOpen(false)}><p>执行结果</p></OpsDialog>}
+    </OpsDialog>
+  );
+}
+
+it("按 Esc 关闭轮次详情后仍可查看执行记录", () => {
+  const dialogPrototype = HTMLDialogElement.prototype;
+  const { showModal, close } = dialogPrototype;
+  Object.assign(dialogPrototype, {
+    showModal(this: HTMLDialogElement) { this.open = true; },
+    close(this: HTMLDialogElement) { this.open = false; },
+  });
+
+  try {
+    render(<RunHistory />);
+    const history = screen.getByRole("dialog", { name: "执行记录" });
+    fireEvent.click(within(history).getByRole("button", { name: "查看轮次" }));
+    const round = screen.getByRole("dialog", { name: "轮次详情" });
+
+    fireEvent(round, new Event("cancel", { bubbles: true, cancelable: true }));
+
+    expect(screen.queryByRole("dialog", { name: "轮次详情" })).toBeNull();
+    expect(screen.getByRole("dialog", { name: "执行记录" })).toBe(history);
+    fireEvent.click(within(history).getByRole("button", { name: "关闭对话框" }));
+    expect(screen.queryByRole("dialog", { name: "执行记录" })).toBeNull();
+  } finally {
+    cleanup();
+    Object.assign(dialogPrototype, { showModal, close });
+  }
+});

+ 42 - 41
web-scaffold/src/pages/JobRunsDrawer.tsx → web-scaffold/src/pages/JobRunsDialog.tsx

@@ -1,5 +1,5 @@
 /**
- * 册10 SC-03 执行记录抽屉+轮次弹窗。
+ * 册10 SC-03 执行记录与轮次详情。
  * 契约:docs/.../10-第10册-定时任务与审计视图/14-页面契约本册逐页.md §14.2、作业§4.4/§4.5。
  * 接线现状:`/jobs/runs@v1` [实]——五件筛选(关键字/任务/触发方式/结果/日期区间)、
  * `page` 0 基翻页、留存期总数 N 与命中数 M 分列下发;标注行返回空流水说明(⛔ 显 0)。
@@ -7,7 +7,7 @@
  */
 import { useMemo, useState } from "react";
 import { Search, X } from "lucide-react";
-import { OpsDrawer, OpsStatus } from "../components/OperationsKit";
+import { OpsDialog, OpsStatus } from "../components/OperationsKit";
 import { Button } from "../components/ui/button";
 import { FilterSelect } from "../components/ui/filter-select";
 import { Input } from "../components/ui/input";
@@ -49,15 +49,15 @@ import {
 import type { JobRunRow } from "../lib/api/types";
 import { useNavigate } from "react-router";
 
-export interface DrawerPreset {
+export interface JobRunsPreset {
   jobKey: string;
   jobName: string;
 }
 
-export function JobRunsDrawer({ preset, rows, onClose }: { preset: DrawerPreset | null; rows: JobListRow[]; onClose: () => void }) {
+export function JobRunsDialog({ preset, rows, onClose }: { preset: JobRunsPreset; rows: JobListRow[]; onClose: () => void }) {
   const navigate = useNavigate();
-  const [filter, setFilter] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset?.jobKey ?? "" });
-  const [applied, setApplied] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset?.jobKey ?? "" });
+  const [filter, setFilter] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset.jobKey });
+  const [applied, setApplied] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset.jobKey });
   const [detail, setDetail] = useState<JobRunRow | null>(null);
   const state = useJobRuns(applied);
 
@@ -68,13 +68,13 @@ export function JobRunsDrawer({ preset, rows, onClose }: { preset: DrawerPreset
     setApplied(next);
   };
 
-  // 抽屉标题=W16(N=服务端留存期总数,M=当前已装载轮次)
+  // W16:N 为服务端留存期总数,M 为当前已装载轮次。
   const title = w16(state.retentionTotal === null ? "—" : String(state.retentionTotal), state.runs.length);
 
   return (
-    <OpsDrawer title={title} subtitle="按轮次查看执行流水" wide onClose={onClose}>
-      <div className="ops-drawer-body">
-        {preset && <p className="ops-import-note">{w17(preset.jobName)}</p>}
+    <OpsDialog title={title} subtitle="按轮次查看执行流水" className="job-runs-dialog" onClose={onClose}>
+      <div className="job-runs-body">
+        <p className="ops-import-note">{w17(preset.jobName)}</p>
         <div className="ops-toolbar scheduled-jobs-filters">
           <label className="ops-search">
             <Search size={16} />
@@ -142,29 +142,31 @@ export function JobRunsDrawer({ preset, rows, onClose }: { preset: DrawerPreset
           <div className="ops-empty">{RUNS_EMPTY}</div>
         ) : (
           <div className="ops-list-shell">
-            <table className="ops-table">
-              <thead>
-                <tr>
-                  <th>执行编号</th>
-                  <th>任务</th>
-                  <th>触发方式</th>
-                  <th>开始时间</th>
-                  <th>耗时</th>
-                  <th>扫描/命中</th>
-                  <th>成功</th>
-                  <th>跳过</th>
-                  <th>失败</th>
-                  <th>结果/处置</th>
-                  <th>执行人</th>
-                  <th>操作</th>
-                </tr>
-              </thead>
-              <tbody>
-                {state.runs.map((run) => (
-                  <RunRow key={run.run_id} run={run} rows={rows} onDetail={() => setDetail(run)} onGoto={(page) => { onClose(); navigate(page); }} />
-                ))}
-              </tbody>
-            </table>
+            <div className="job-runs-table" role="region" aria-label="执行流水,可横向滚动" tabIndex={0}>
+              <table className="ops-table">
+                <thead>
+                  <tr>
+                    <th>执行编号</th>
+                    <th>任务</th>
+                    <th>触发方式</th>
+                    <th>开始时间</th>
+                    <th>耗时</th>
+                    <th>扫描/命中</th>
+                    <th>成功</th>
+                    <th>跳过</th>
+                    <th>失败</th>
+                    <th>结果/处置</th>
+                    <th>执行人</th>
+                    <th>操作</th>
+                  </tr>
+                </thead>
+                <tbody>
+                  {state.runs.map((run) => (
+                    <RunRow key={run.run_id} run={run} rows={rows} onDetail={() => setDetail(run)} onGoto={(page) => { onClose(); navigate(page); }} />
+                  ))}
+                </tbody>
+              </table>
+            </div>
             {state.hasMore && (
               <div className="ops-toolbar" style={{ justifyContent: "center" }}>
                 <Button size="sm" type="button" variant="outline" disabled={state.loadingMore} onClick={state.loadMore}>
@@ -176,7 +178,7 @@ export function JobRunsDrawer({ preset, rows, onClose }: { preset: DrawerPreset
         )}
       </div>
       {detail && <RoundDialog run={detail} rows={rows} onClose={() => setDetail(null)} />}
-    </OpsDrawer>
+    </OpsDialog>
   );
 }
 
@@ -237,9 +239,8 @@ function RoundDialog({ run, rows, onClose }: { run: JobRunRow; rows: JobListRow[
   const detail = run.detail ?? [];
   const violations = run.violations ?? [];
   return (
-    <div className="ops-confirm-backdrop" role="presentation" onMouseDown={onClose}>
-      <div className="ops-confirm ops-round-dialog" role="dialog" aria-modal="true" aria-labelledby="round-title" onMouseDown={(event) => event.stopPropagation()}>
-        <h2 id="round-title">{w26(run.run_id)}</h2>
+    <OpsDialog title={w26(run.run_id)} className="job-round-dialog" onClose={onClose}>
+      <div className="job-runs-body">
         <p className="ops-import-note">
           {run.job_name ?? meta?.displayName ?? run.job_key}
           {interrupted ? W28 : W27}
@@ -258,7 +259,7 @@ function RoundDialog({ run, rows, onClose }: { run: JobRunRow; rows: JobListRow[
         {detail.length === 0 ? (
           <p className="ops-import-note">{ROUND_DETAIL_EMPTY}</p>
         ) : (
-          <div className="ops-list-shell" style={{ maxHeight: 260, overflow: "auto" }}>
+          <div className="ops-list-shell job-round-table" role="region" aria-label="轮次对象明细,可滚动" tabIndex={0}>
             <table className="ops-table">
               <thead>
                 <tr>
@@ -294,12 +295,12 @@ function RoundDialog({ run, rows, onClose }: { run: JobRunRow; rows: JobListRow[
             </ul>
           </>
         )}
-        <div>
+        <footer className="job-round-actions">
           <Button type="button" variant="outline" onClick={onClose}>
             关闭
           </Button>
-        </div>
+        </footer>
       </div>
-    </div>
+    </OpsDialog>
   );
 }

+ 5 - 8
web-scaffold/src/pages/ScheduledJobManagementPage.tsx

@@ -68,7 +68,7 @@ import {
   w24,
   w9,
 } from "../lib/copy-jobs";
-import { JobRunsDrawer } from "./JobRunsDrawer";
+import { JobRunsDialog, type JobRunsPreset } from "./JobRunsDialog";
 import { ListPager } from "../components/ListPager";
 import { slicePage, useLocalPage } from "../lib/list-paging";
 import "../styles/operations.css";
@@ -355,8 +355,7 @@ export function ScheduledJobManagementPage() {
   const [notice, setNotice] = useState<string | null>(null);
   const [toggleTarget, setToggleTarget] = useState<{ row: JobListRow; enable: boolean } | null>(null);
   const [defRow, setDefRow] = useState<JobListRow | null>(null);
-  const [drawerPreset, setDrawerPreset] = useState<{ jobKey: string; jobName: string } | null>(null);
-  const [drawerOpen, setDrawerOpen] = useState(false);
+  const [runsPreset, setRunsPreset] = useState<JobRunsPreset | null>(null);
   const [maintOpen, setMaintOpen] = useState(false);
   const scroll = useHorizontalOverflow();
 
@@ -370,10 +369,8 @@ export function ScheduledJobManagementPage() {
   const pageRows = slicePage(businessRows, paging.safePage);
 
   const openRuns = (row: JobListRow) => {
-    // 执行记录抽屉为全高右侧浮层:先收起系统维护弹窗,避免两层遮罩叠在一起
     setMaintOpen(false);
-    setDrawerPreset({ jobKey: row.key, jobName: row.displayName });
-    setDrawerOpen(true);
+    setRunsPreset({ jobKey: row.key, jobName: row.displayName });
   };
 
   const widths = [9, 12, 11, 11, 7, 8, 12, 8, 10, 12];
@@ -615,8 +612,8 @@ export function ScheduledJobManagementPage() {
           }}
         />
       )}
-      {drawerOpen && (
-        <JobRunsDrawer preset={drawerPreset} rows={center.rows} onClose={() => { setDrawerOpen(false); setDrawerPreset(null); }} />
+      {runsPreset && (
+        <JobRunsDialog preset={runsPreset} rows={center.rows} onClose={() => setRunsPreset(null)} />
       )}
       {notice && <OpsNotice message={notice} onClose={() => setNotice(null)} />}
     </section>

+ 8 - 4
web-scaffold/src/styles/operations.css

@@ -404,6 +404,12 @@ button.ops-contract-exit.is-active svg { opacity: .7; }
 /* 通用对话框(原生 dialog):分账号编辑等轻量表单。 */
 .ops-dialog { width: min(560px, calc(100vw - 32px)); max-height: min(88vh, 820px); margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--foreground); box-shadow: var(--shadow-dialog); overflow: auto; }
 .ops-dialog::backdrop { background: var(--overlay); }
+body:has(.ops-content-dialog[open]) { overflow: hidden; }
+.ops-content-dialog { max-height: min(88dvh, 900px); }
+.ops-content-dialog > header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px clamp(14px, 3vw, 24px); border-bottom: 1px solid var(--border); background: var(--card); }
+.ops-content-dialog > header p { margin-bottom: 4px; color: var(--muted-foreground); font-size: var(--type-meta); }
+.ops-content-dialog > header h2 { font-size: 21px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
+.ops-content-dialog > header button { flex: none; }
 .ops-dialog > form { padding: 22px 24px; margin-top: 0; }
 @media (max-width: 700px) {
   .ops-page-hero { flex-direction: column; padding: 17px; }
@@ -997,16 +1003,14 @@ button.ops-contract-exit.is-active svg { opacity: .7; }
 .ops-page--customers .customer-list-filters .customer-id-search { flex:1 1 148px; min-width:0; width:auto; max-width:min(260px,100%); height:38px; }
 .ops-page--customers .customer-list-filters .customer-filter-reset { flex:none; height:38px; white-space:nowrap; }
 
-/* ── 册10:执行记录抽屉(契约 66% 宽)/作业定义弹窗/轮次弹窗 ── */
-.ops-drawer--wide { width: min(66vw, calc(100vw - 24px)); }
-.ops-drawer-body { padding: 18px 25px 28px; display: grid; gap: 12px; align-content: start; }
+/* ── 定时任务表格与作业定义弹窗 ── */
 .ops-group-row td { padding: 7px 14px; background: var(--surface-subtle); color: var(--muted-foreground); font-size: var(--type-support); font-weight: 650; }
 .ops-table-actions { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 2px; }
 .job-cell-pending { color: var(--muted-foreground); }
 .job-cell-pending small { display: block; font-size: var(--type-meta); font-weight: 400; }
 .job-cell-note { color: var(--muted-foreground); font-size: var(--type-support); }
 .job-kpi-pending { color: var(--muted-foreground); }
-.ops-jobdef-dialog, .ops-round-dialog { width: min(640px, calc(100vw - 32px)); text-align: left; }
+.ops-jobdef-dialog { width: min(640px, calc(100vw - 32px)); text-align: left; }
 .ops-jobdef-list { display: grid; gap: 8px; margin: 14px 0; }
 .ops-jobdef-list > div { display: grid; grid-template-columns: 132px 1fr; gap: 10px; align-items: start; }
 .ops-jobdef-list dt { color: var(--muted-foreground); font-size: var(--type-support); }

+ 9 - 0
web-scaffold/src/styles/scheduled-jobs.css

@@ -28,6 +28,15 @@
 .scheduled-jobs-pill.warn{background:var(--warning-soft);border-color:var(--warning-border);color:var(--warning)}
 .scheduled-jobs-pill.off{background:var(--surface-subtle);border-color:var(--border);color:var(--text-secondary)}
 .scheduled-jobs-filters .ops-search{flex:1;max-width:390px}
+.job-runs-dialog { width: min(1200px, calc(100vw - 24px)); }
+.job-round-dialog { width: min(680px, calc(100vw - 24px)); }
+.job-runs-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px clamp(14px, 3vw, 24px) 22px; }
+.job-runs-table { overflow-x: auto; }
+.job-runs-body > .ops-toolbar { padding: 0; }
+.job-runs-body .scheduled-jobs-filters input[type="date"] { width: auto; min-width: 0; }
+.job-round-table { max-height: 260px; overflow: auto; }
+.job-round-table .ops-table { min-width: 0; overflow-wrap: anywhere; }
+.job-round-actions { display: flex; justify-content: flex-end; }
 .scheduled-jobs-run-list{border-top:1px solid var(--border-subtle)}
 .scheduled-jobs-run-group h3{padding:10px 22px;background:var(--surface-subtle);color:var(--text-secondary);font-size:var(--type-support);font-weight:650;text-align:left}
 .scheduled-jobs-run{display:flex;align-items:flex-start;gap:11px;width:100%;padding:15px 22px;border:0;border-bottom:1px solid var(--border-subtle);background:transparent;color:var(--foreground);font:inherit;text-align:left;cursor:pointer;transition:background .18s}