优化:完善分类规则与Excel配置维护并加速查询翻页
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Alert, App, Button, Drawer, Empty, Progress, Select, Spin, Tabs, Tag } from 'antd';
|
||||
import { ReloadOutlined, SettingOutlined } from '@ant-design/icons';
|
||||
import { ManagementSections } from './ManagementSections';
|
||||
import { useCallback, useEffect, useState, useRef } from 'react';
|
||||
import { Alert, App, Button, Drawer, Empty, Progress, Select, Spin, Tag } from 'antd';
|
||||
import { ReloadOutlined } from '@ant-design/icons';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { api } from './api';
|
||||
import { usePageCache } from './pageCache';
|
||||
import { usePageCache, useMaintenanceRefresh } from './pageCache';
|
||||
import type { AuthUser } from './types';
|
||||
import { BackupOperationsPanel, OperationsMonitorPanel } from './GovernanceCompletion';
|
||||
import { configurationDateTime } from './configurationName';
|
||||
@@ -12,12 +13,14 @@ import { backupSummary, isActive, isFailed, monitorLabel, orderedTasks, taskFail
|
||||
|
||||
export function TasksMonitorPage({user,onUnauthorized}:{user:AuthUser;onUnauthorized:(error:unknown)=>boolean}) {
|
||||
const {message}=App.useApp();
|
||||
const {active,refreshKey}=usePageCache();
|
||||
const {active}=usePageCache();
|
||||
const [busy,setBusy]=useState(false);
|
||||
const [items,setItems]=useState<MonitorRow[]>([]);
|
||||
const [backup,setBackup]=useState<MonitorRow>({});
|
||||
const [taskError,setTaskError]=useState(''); const [backupError,setBackupError]=useState('');
|
||||
const [loading,setLoading]=useState(true); const [advanced,setAdvanced]=useState(false);
|
||||
const [loading,setLoading]=useState(true);
|
||||
const loaded = useRef(false);
|
||||
const [section,setSection] = useState('tasks');
|
||||
const [filter,setFilter]=useState('all'); const [selected,setSelected]=useState<MonitorRow|null>(null);
|
||||
const canManage=user.roles.some(role=>['SYSTEM_ADMIN','SYSTEM_OPERATOR'].includes(role));
|
||||
const load=useCallback(async()=>{
|
||||
@@ -27,8 +30,9 @@ export function TasksMonitorPage({user,onUnauthorized}:{user:AuthUser;onUnauthor
|
||||
api.latestBackup().then(value=>{setBackup(value);setBackupError('');}).catch(error=>{if(!onUnauthorized(error))setBackupError(error instanceof Error?error.message:'备份状态读取失败');}),
|
||||
]);setLoading(false);
|
||||
},[onUnauthorized]);
|
||||
useEffect(()=>{if(active)void load();},[load,active,refreshKey]);
|
||||
useEffect(()=>{if(!active)return;const timer=window.setInterval(()=>{if(document.visibilityState==='visible')void load();},15000);return()=>window.clearInterval(timer);},[load,active]);
|
||||
useEffect(()=>{if(!loaded.current){loaded.current=true;void load();}},[load]);
|
||||
useMaintenanceRefresh(load);
|
||||
useEffect(()=>{if(!active || !['tasks','latestBackup'].includes(section))return;const timer=window.setInterval(()=>{if(document.visibilityState==='visible')void load();},15000);return()=>window.clearInterval(timer);},[load,active,section]);
|
||||
const runAction=async(row:MonitorRow,action:'retry'|'cancel')=>{
|
||||
setBusy(true);
|
||||
try {
|
||||
@@ -47,16 +51,20 @@ export function TasksMonitorPage({user,onUnauthorized}:{user:AuthUser;onUnauthor
|
||||
{title:'',key:'action',width:75,render:(_,row)=><Button type="link" onClick={()=>setSelected(row)}>详情</Button>},
|
||||
];
|
||||
return <>
|
||||
<section className="panel section-panel">
|
||||
<ManagementSections onSelect={setSection} items={[
|
||||
{ key:'tasks', label:'任务进度', children: <> <section className="panel section-panel">
|
||||
<div className="completion-panel-heading"><strong>任务进度</strong><div className="completion-actions"><Select aria-label="筛选任务" value={filter} onChange={setFilter} options={[{value:'all',label:'全部任务'},{value:'active',label:'进行中'},{value:'failed',label:'失败 / 未完成'},{value:'completed',label:'已完成'}]}/><Button icon={<ReloadOutlined/>} loading={loading} onClick={()=>void load()}>刷新</Button></div></div>
|
||||
{taskError&&<Alert showIcon type="error" message="任务暂不可用" description={taskError}/>}
|
||||
{loading&&!items.length?<Spin/>:!taskError&&<Table size="small" bordered columns={columns} dataSource={orderedTasks(items,filter)} rowKey={row=>`${row.sourceKind}-${row.id}`} pagination={{pageSize:8,showSizeChanger:false}} scroll={{x:1000}} locale={{emptyText:<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无符合条件的任务"/>}}/>}
|
||||
{loading&&!items.length?<Spin/>:!taskError&&<Table size="small" bordered columns={columns} dataSource={orderedTasks(items,filter)} rowKey={row=>`${row.sourceKind}-${row.id}`} pagination={{pageSize:15,showSizeChanger:false}} scroll={{x:1000}} locale={{emptyText:<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无符合条件的任务"/>}}/>}
|
||||
<p className="completion-note">每类最多显示 50 条记录,进行中及失败任务优先。智能分析仅显示本人任务。</p>
|
||||
</section>
|
||||
<section className="panel section-panel"><div className="completion-panel-heading"><strong>最近备份状态</strong></div>
|
||||
</> },
|
||||
{ key:'latestBackup', label:'最近备份', children: <> <section className="panel section-panel"><div className="completion-panel-heading"><strong>最近备份状态</strong></div>
|
||||
{backupError?<Alert showIcon type="error" message="备份状态暂不可用" description={backupError}/>:loading&&!latest.createdAt?<Spin/>:<div className="governance-monitor-grid"><div><small>最近备份</small><strong>{backupSummary(latest)}</strong></div><div><small>备份时间</small><strong>{configurationDateTime(latest.createdAt)||'—'}</strong></div><div><small>恢复验证时间</small><strong>{configurationDateTime(latest.restoreVerifiedAt)||'—'}</strong></div><div><small>自动备份</small><strong>{backup.planActive===true?'已启用':'未启用'}</strong></div></div>}
|
||||
</section>
|
||||
{canManage&&<><Button icon={<SettingOutlined/>} aria-expanded={advanced} onClick={()=>setAdvanced(!advanced)}>{advanced?'收起高级设置':'管理员高级设置'}</Button>{advanced&&<Tabs items={[{key:'monitor',label:'运行监控与告警',children:<OperationsMonitorPanel user={user} onUnauthorized={onUnauthorized}/>},{key:'backups',label:'备份管理',children:<BackupOperationsPanel user={user} onUnauthorized={onUnauthorized}/>} ]}/>}</>}
|
||||
</> },
|
||||
...(canManage ? [{ key:'monitor', label:'运行监控与告警', children:<OperationsMonitorPanel user={user} onUnauthorized={onUnauthorized}/> },{ key:'backups', label:'备份管理', children:<BackupOperationsPanel user={user} onUnauthorized={onUnauthorized}/> }] : []),
|
||||
]} />
|
||||
<Drawer open={!!selected} title="任务详情" width={Math.min(620,window.innerWidth)} onClose={()=>setSelected(null)}>{selected&&<dl className="nc-form-grid"><dt>任务</dt><dd>{monitorLabel(selected.type,'后台任务')}</dd><dt>状态</dt><dd>{monitorLabel(selected.status)}</dd><dt>阶段</dt><dd>{monitorLabel(selected.stage,monitorLabel(selected.status))}</dd>{Number(selected.total)>0&&<><dt>已处理 / 总数</dt><dd>{String(selected.processed??0)} / {String(selected.total)}</dd></>}<dt>提交时间</dt><dd>{configurationDateTime(selected.createdAt)}</dd>{isFailed(selected)&&<><dt>失败原因</dt><dd style={{whiteSpace:'pre-wrap',overflowWrap:'anywhere'}}>{taskFailure(selected)}</dd></>}<dt>任务编号</dt><dd style={{overflowWrap:'anywhere'}}>{String(selected.id)}</dd></dl>}{selected?.sourceKind==='TASK'&&<div className="completion-actions">{selected.status==='FAILED'&&!!selected.importRunId&&user.roles.some(role=>['SYSTEM_ADMIN','DATA_MAINTAINER'].includes(role))&&<Button loading={busy} onClick={()=>void runAction(selected,'retry')}>重试导入</Button>}{selected.status==='QUEUED'&&user.roles.some(role=>['SYSTEM_ADMIN','SYSTEM_OPERATOR','DATA_MAINTAINER'].includes(role))&&<Button danger loading={busy} onClick={()=>void runAction(selected,'cancel')}>取消排队任务</Button>}</div>}{selected?.sourceKind==='ANALYSIS'&&!!selected.sessionId&&<Button href={`?page=analysis&sessionId=${encodeURIComponent(String(selected.sessionId))}&turnId=${encodeURIComponent(String(selected.id))}`}>查看分析记录</Button>}</Drawer>
|
||||
</>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user