unify Semi UI query metric rails

This commit is contained in:
lingniu
2026-07-18 09:02:54 +08:00
parent fb7cb4c6d6
commit 1688ba1b50
7 changed files with 345 additions and 342 deletions

View File

@@ -11,6 +11,7 @@ import { InlineError, PanelEmpty, PanelLoading } from '../shared/AsyncState';
import { MonitorReturnBar } from '../shared/MonitorReturnBar';
import { TablePagination } from '../shared/TablePagination';
import { WorkspaceFilterPanel } from '../shared/WorkspaceFilterPanel';
import { WorkspaceMetricRail } from '../shared/WorkspaceMetricRail';
import { WorkspacePanelHeader } from '../shared/WorkspacePanelHeader';
import { detailTriggerRow } from '../shared/detailTriggerRow';
import { LIVE_QUERY_POLICY, QUERY_MEMORY, retainPreviousPageWithinScope } from '../queryPolicy';
@@ -327,6 +328,32 @@ export default function HistoryPage() {
const totalPages = Math.max(1, Math.ceil((result?.total ?? 0) / limit));
const page = Math.floor(offset / limit) + 1;
const summarySources = resultSummary?.sources?.join('、') || '—';
const summaryLoading = keywords.length > 0 && dataQuery.isFetching && !result;
const summaryPrimary = {
label: '结果行数',
value: summaryLoading ? '—' : (result?.total ?? 0).toLocaleString('zh-CN'),
note: summaryLoading ? '正在读取当前筛选范围' : `${resultSummary?.vehicleCount ?? 0} 辆车辆`
};
const summarySecondary = [
{
label: '车辆数',
value: summaryLoading ? '—' : String(resultSummary?.vehicleCount ?? 0),
note: `当前筛选 ${keywords.length} 个车辆标识`,
className: 'is-vehicles'
},
{
label: '数据来源',
value: summaryLoading ? '—' : `${resultSummary?.sources?.length ?? 0} 个来源`,
note: summarySources,
className: 'is-sources'
},
{
label: '查询耗时',
value: summaryLoading ? '—' : resultSummary ? `${resultSummary.queryDurationMs} ms` : '—',
note: `${visibleMetrics.length} / ${allMetrics.length} 个业务字段`,
className: 'is-duration'
}
];
return <div className="v2-history-page">
<MonitorReturnBar />
@@ -348,31 +375,15 @@ export default function HistoryPage() {
<div className="v2-history-toolbar-actions"><Button className="v2-primary-button" theme="solid" htmlType="submit" disabled={!parseHistoryKeywords(draft.keywords).length}></Button><Button className="v2-secondary-button" theme="light" onClick={reset}></Button>{exportAllowed ? <CreateExportButton disabled={!resultRows.length} request={{ keywords, category: criteria.category, protocol: criteria.protocol || undefined, dateFrom: criteria.dateFrom, dateTo: criteria.dateTo, metrics: visibleKeys, format: 'csv' }} /> : <Tag className="v2-history-permission-tag" color="grey" type="light" size="large"></Tag>}</div>
</form>
</WorkspaceFilterPanel>
<Card className="v2-history-context-card" bodyStyle={{ padding: 0 }}>
<div className="v2-history-context">
<div className="v2-history-metrics">
<div className="v2-history-metrics-heading">
<strong></strong>
<small>{visibleMetrics.length} / {allMetrics.length}</small>
</div>
<div
className="v2-history-metric-scroll"
tabIndex={mobileLayout ? 0 : undefined}
aria-label={mobileLayout ? '当前显示字段,可左右滑动' : '当前显示字段'}
>
{visibleMetrics.map((metric) => <Tag className="v2-history-metric-tag" color="blue" type="light" size="large" closable tabIndex={0} aria-label={`已选字段 ${metric.label}${metric.unit ? ` ${metric.unit}` : ''},点击取消显示`} onClick={() => toggleMetric(metric.key)} onKeyDown={(event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); toggleMetric(metric.key); } }} onClose={(_, event) => { event.stopPropagation(); toggleMetric(metric.key); }} key={metric.key}>{metric.label}{metric.unit ? ` (${metric.unit})` : ''}</Tag>)}
{allMetrics.length > visibleMetrics.length ? <span> {allMetrics.length - visibleMetrics.length} </span> : !allMetrics.length ? <span></span> : null}
</div>
<Button className="v2-history-metrics-manage" theme="borderless" icon={<IconSetting />} aria-label="管理字段" onClick={() => setColumnSettingsOpen(true)} disabled={!allMetrics.length}></Button>
</div>
<div className="v2-history-summary" aria-label="当前查询摘要">
<div className="is-primary"><small></small><strong>{result?.total?.toLocaleString('zh-CN') ?? '—'}</strong></div>
<div><small></small><strong>{resultSummary?.vehicleCount ?? '—'}</strong></div>
<div><small></small><strong className="is-source" title={summarySources}>{summarySources}</strong></div>
<div><small></small><strong>{resultSummary ? `${resultSummary.queryDurationMs} ms` : '—'}</strong></div>
</div>
</div>
</Card>
{keywords.length ? <WorkspaceMetricRail
className="v2-history-summary-rail"
cardClassName="v2-history-summary-card"
secondaryClassName="v2-history-summary-secondary"
primaryValueClassName="v2-history-summary-value"
ariaLabel="历史数据查询统计信息"
primary={summaryPrimary}
secondary={summarySecondary}
/> : null}
{dataQuery.isError ? <InlineError message={dataQuery.error instanceof Error ? dataQuery.error.message : '历史查询失败'} onRetry={() => dataQuery.refetch()} /> : null}
<div className={`v2-history-workspace${selectedRow && !mobileLayout ? ' is-inspector-open' : ''}`}>
<div className={`v2-history-main${trendExpanded ? ' has-expanded-trend' : ''}`}>
@@ -381,7 +392,7 @@ export default function HistoryPage() {
<WorkspacePanelHeader
title="历史明细"
description={keywords.length ? `${(result?.total ?? 0).toLocaleString('zh-CN')} 条记录 · ${resultSummary?.vehicleCount ?? 0} 辆车辆 · ${summarySources}` : '选择车辆和时间范围后查询'}
meta={resultSummary ? `${resultSummary.queryDurationMs} ms` : undefined}
meta={<span className="v2-history-result-meta"><Tag color="blue" type="light" size="small">{visibleMetrics.length} / {allMetrics.length} </Tag>{resultSummary ? <span>{resultSummary.queryDurationMs} ms</span> : null}</span>}
actionsClassName={`v2-history-result-actions${mobileLayout ? ' is-mobile-actions' : ''}`}
actions={<>
<Button className={`v2-history-table-trend${trendExpanded ? ' is-expanded' : ''}`} theme="borderless" aria-label={trendExpanded ? '收起趋势' : '展开趋势'} aria-expanded={trendExpanded} icon={<IconChevronRight />} onClick={() => setTrendExpanded((value) => !value)}>{trendExpanded ? '收起趋势' : '聚合趋势'}</Button>