新增:查询页面快照并修复筛选选框闪烁

页面快照支持勾选查询条件、指标卡片、趋势、汇总表、不良构成和细分缺陷图,复制PNG或下载;增加取消、分阶段提示和等待超时恢复。

修复公共Select弹层准备帧被opacity覆盖导致的先闪出再展开,并取消查询字段原生label的重复点击转发。

同步已经验收上线的销售订单类型映射、排除筛选及预聚合,以及其线上权限、删除确认配套源码;保留既有公式编辑和名录编码修改。源码范围按发布清单冻结,不纳入本机数据、凭据及未发布工作。

验证:前后端独立源码构建通过;10项前端检查、4项订单分类单元测试通过;实际系统剪贴板粘贴PNG验证通过;线上配置及筛选结果与发布前一致,后端未重启。
This commit is contained in:
2026-11-04 00:15:32 +08:00
parent 54813accaa
commit c3354c1f64
106 changed files with 1678 additions and 353 deletions
+34 -18
View File
@@ -1,3 +1,4 @@
import { QuerySnapshotButton } from './QuerySnapshotButton';
import { loadedQueryScope, queryForLocation, readQueryLocation } from './queryLoadingScope';
import { AnimatedMetricText, SmoothTableFrame, useAnimatedMetricText, useRetainedResult } from './QueryResultMotion';
import { trendBarPalette } from './trendBarPalette';
@@ -432,7 +433,7 @@ export default function QueryPage({ page, onUnauthorized }: {
useEffect(() => {
if (!active) return;
const url = new URL(window.location.href);
if (!['overall', 'department', 'group', 'product'].includes(url.searchParams.get('page') || '')) return;
if (!['overall', 'department', 'group', 'product'].includes(url.searchParams.get('page') || 'overall')) return;
const bytes = new TextEncoder().encode(JSON.stringify({ query: queryForLocation(queryParams, initialQuery.releaseId) }));
let binary = '';
for (const byte of bytes) binary += String.fromCharCode(byte);
@@ -615,7 +616,7 @@ export default function QueryPage({ page, onUnauthorized }: {
const years = (options?.years || []).map(value => { const numeric = Number(String(value).match(/\d{4}/)?.[0]); return { label: `${numeric}年`, value: numeric }; }).filter(item => Number.isFinite(item.value));
const filterSelect = (label: string, value: string[], choices: string[] | undefined, change: (value: string[]) => void, allowUnassigned = true) => (
<label className="query-field query-primary-field" key={label}>
<div role="group" className="query-field query-primary-field" key={label}>
<span>{label}</span>
<Select
maxTagCount="responsive"
@@ -630,7 +631,7 @@ export default function QueryPage({ page, onUnauthorized }: {
onChange={change}
aria-label={label}
/>
</label>
</div>
);
const activeDefectData = trendObject
@@ -706,7 +707,7 @@ export default function QueryPage({ page, onUnauthorized }: {
return (
<div className="query-page">
{optionsError && <Alert showIcon type="error" message="查询选项加载失败" description={optionsError} action={<Button size="small" icon={<ReloadOutlined />} onClick={() => { setOptionsLoading(true); api.options().then(result => { setOptions(result); setOptionsError(''); }).catch(e => { if (!onUnauthorized(e)) setOptionsError(chooseError(e)); }).finally(() => setOptionsLoading(false)); }}>重试</Button>} />}
<section className="query-toolbar panel" aria-label="查询条件">
<section className="query-toolbar panel" data-snapshot-module="filters" aria-label="查询条件">
<Segmented
value={period}
options={[{ label: '年度', value: 'year' }, { label: '季度', value: 'quarter' }, { label: '月度', value: 'month' }]}
@@ -727,15 +728,15 @@ export default function QueryPage({ page, onUnauthorized }: {
}}
aria-label="统计周期"
/>
<label className="query-field query-period-field query-period-year"><span>年份</span><Select aria-label="年份" value={year} options={years.length ? years : [{ label: `${year}年`, value: year }]} onChange={value => { automaticPeriod.current = false; setYear(value); }} loading={optionsLoading} /></label>
{period === 'month' && <label className="query-field query-period-field query-period-month"><span>月份</span><Select aria-label="月份" value={month} options={MONTHS.map((label, index) => ({ label, value: index + 1 }))} onChange={value => { automaticPeriod.current = false; setMonth(value); }} /></label>}
{period === 'quarter' && <label className="query-field query-period-field query-period-quarter"><span>季度</span><Select aria-label="季度" value={quarter} options={[1, 2, 3, 4].map(value => ({ label: `第${value}季度`, value }))} onChange={value => { automaticPeriod.current = false; setQuarter(value); }} /></label>}
<div role="group" className="query-field query-period-field query-period-year"><span>年份</span><Select aria-label="年份" value={year} options={years.length ? years : [{ label: `${year}年`, value: year }]} onChange={value => { automaticPeriod.current = false; setYear(value); }} loading={optionsLoading} /></div>
{period === 'month' && <div role="group" className="query-field query-period-field query-period-month"><span>月份</span><Select aria-label="月份" value={month} options={MONTHS.map((label, index) => ({ label, value: index + 1 }))} onChange={value => { automaticPeriod.current = false; setMonth(value); }} /></div>}
{period === 'quarter' && <div role="group" className="query-field query-period-field query-period-quarter"><span>季度</span><Select aria-label="季度" value={quarter} options={[1, 2, 3, 4].map(value => ({ label: `第${value}季度`, value }))} onChange={value => { automaticPeriod.current = false; setQuarter(value); }} /></div>}
{filterSelect('产业部', department, options?.departments?.filter(name => !RETIRED_DEPARTMENTS.has(name)), values => { setDepartment(values); setGroup([]); setProduct([]); })}
{filterSelect('业务分组', group, allowedGroups, values => { setGroup(values); setProduct([]); }, !department.length)}
{filterSelect('产品', product, department.length || group.length ? organizationPathOptions.products : options?.products, setProduct)}
<ExtraQueryFilters key={queryRevision} projectGroup={projectGroup} projectGroups={options?.projectGroupStatus === 'READY' ? options.projectGroups : undefined} onProjectGroup={setProjectGroup} value={extraFilters} onChange={setExtraFilters} onUnauthorized={onUnauthorized} />
<div className="query-toolbar-tail">
<ExtraQueryFilters key={queryRevision} releaseId={queryParams.releaseId} projectGroup={projectGroup} projectGroups={options?.projectGroupStatus === 'READY' ? options.projectGroups : undefined} onProjectGroup={setProjectGroup} value={extraFilters} onChange={setExtraFilters} onUnauthorized={onUnauthorized} />
<div className="query-toolbar-tail"><QuerySnapshotButton title={drilledProduct ? `${drilledProduct} · 产品质量查询` : page === 'overall' ? '总体合格率' : `${scopeName}质量查询`} queryKey={JSON.stringify([queryParams,trendMode,trendObject,trendStage,trendGranularity,rateBasis,fullFields,defectDisplay,queryRevision])} disabled={queryBusy || summaryBusy || !summaryMetricsData} onUnauthorized={onUnauthorized} />
<span className={`query-status ${queryBusy || summaryBusy ? 'busy' : currentMetricsError || summaryMetricsError ? 'failed' : ''}`}><i />{queryBusy || summaryBusy ? '正在查询' : currentMetricsError || summaryMetricsError ? '查询失败' : '查询完成'}</span>
<Button type="default" onClick={() => { automaticPeriod.current = false; const previous = defaultQueryMonth(options); const previousQuarter = previousCompleteQuarter(); setViewOverride(); setDrilledProduct(''); setDepartment([]); setGroup([]); setProduct([]); setProjectGroup([]); setExtraFilters({}); setSearch(''); setAppliedSearch(''); setTrendObject(''); setYear(page === 'overall' ? new Date().getFullYear() : previous.year); setMonth(previous.month); setQuarter(previousQuarter.quarter); setPeriod(page === 'overall' ? 'year' : 'month'); setTrendGranularity('month'); }}>重置</Button>
</div>
@@ -747,7 +748,7 @@ export default function QueryPage({ page, onUnauthorized }: {
{currentMetricsError && <Alert showIcon type="error" message={data ? "更新失败,当前显示上次结果" : "质量指标查询失败"} description={currentMetricsError} action={<Button size="small" icon={<ReloadOutlined />} onClick={() => setQueryRevision(value => value + 1)}>重试</Button>} />}
{drilledProduct && summaryMetricsError && <Alert showIcon type="error" message="当前产品指标查询失败" description={summaryMetricsError} action={<Button size="small" onClick={() => setQueryRevision(value => value + 1)}>重试</Button>} />}
<section className={`metric-strip ${!displayedSummaryData ? 'query-awaiting-data' : ''}`} aria-label="质量指标" aria-busy={summaryBusy} inert={!summaryMetricsData}>
<section className={`metric-strip ${!displayedSummaryData ? 'query-awaiting-data' : ''}`} data-snapshot-module="metrics" aria-label="质量指标" aria-busy={summaryBusy} inert={!summaryMetricsData}>
<div className="rate-basis-control"><Segmented size="small" value={rateBasis} options={[{ label: '原口径', value: 'original' }, { label: '去本部报废', value: 'withoutHeadquartersScrap' }]} onChange={value => setRateBasis(value as typeof rateBasis)} aria-label="合格率口径" /></div>
<MetricCard primary label="综合合格率" value={rateText(visibleCompositeRate(rowForSummary, rateBasis))} onClick={() => setBasisOpen(true)} />
<MetricCard label="黑片合格率" value={rateText(visibleStageRate(rowForSummary, 'black'))} note={!displayedSummaryData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'black') ? hasValidRateDenominator(rowForSummary, 'black') ? `合格重量 ${numberText(rowForSummary?.black?.qualifiedWeight)} kg` : '按当前启用规则及空值策略计算' : '缺少黑片来源'} stage="black" onClick={() => openRecords(null, 'black')} />
@@ -832,7 +833,7 @@ export default function QueryPage({ page, onUnauthorized }: {
{defectsRefreshing && <span className="defect-refresh-indicator"><Spin size="small" />正在更新</span>}
</div>
{trendObjectMetricsError && <Alert showIcon type="warning" message="当前趋势对象的不良数据读取失败" description={trendObjectMetricsError} />}
<div className="defect-stage-grid" inert={!activeDefectData}>
<div className="defect-stage-grid" data-snapshot-module="defects" inert={!activeDefectData}>
{(['black', 'bright'] as const).map(stage => {
const items = stage === 'black' ? blackDefectItems : brightDefectItems;
return <section className="defect-stage-column" key={stage} aria-label={`${stage === 'black' ? '黑片' : '亮片'}不良构成`}>
@@ -921,7 +922,14 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna
...(query.includeUnassigned ? { includeUnassigned: true } : {}),
}), [query.year, query.month, query.quarter, query.department, query.group, query.product, query.productSearch, query.projectGroup, query.extraFilters, query.columnFilters, query.includeUnassigned]);
const fineQueryKey = JSON.stringify(fineQuery);
const visible = useResourceVisibility(container, active);
const [snapshotRequested, setSnapshotRequested] = useState(false);
useEffect(() => {
const root = container.current?.closest('.query-page');
const request = (event: Event) => { if (active && (event as CustomEvent<{modules:string[]}>).detail?.modules.includes('pareto')) setSnapshotRequested(true); };
root?.addEventListener('quality:query-snapshot', request);
return () => root?.removeEventListener('quality:query-snapshot', request);
}, [active]);
const visible = useResourceVisibility(container, active) || snapshotRequested;
const showLoading = useDelayedIndicator(loading);
useEffect(() => {
@@ -1043,7 +1051,7 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna
instance.setOption(option, { replaceMerge: ['series'], lazyUpdate: false });
}, [items, totalWeight, themeRevision, active]);
return <section className="defect-pareto-section" aria-busy={loading || pending} aria-label={onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '综合报废重量柏拉图'}>
return <section className="defect-pareto-section" data-snapshot-module="pareto" data-snapshot-ready={error ? 'error' : responses && !loading && !pending ? 'true' : 'false'} aria-busy={loading || pending} aria-label={onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '综合报废重量柏拉图'}>
<div className="defect-pareto-heading"><strong>{onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '黑片与亮片综合报废重量柏拉图'}</strong>{showLoading && <span className="defect-refresh-indicator"><Spin size="small" />正在更新</span>}</div>
{error && <Alert showIcon type="warning" message="细分报废重量读取失败" description={error} />}
{!loading && !releaseId && <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前没有已发布数据版本" />}
@@ -1179,7 +1187,14 @@ function trendBarWidth(chartWidth: number, count: number): number {
export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod, onMonth, onlyStage }: { rows: TrendMetricRow[]; mode: 'production' | 'defects'; stage: Stage; rateBasis: 'original' | 'withoutHeadquartersScrap'; targetRate: number | null; selectedPeriod?: string; onMonth: (value: number | string) => void; onlyStage?: Stage }) {
const { active } = usePageCache();
const container = useRef<HTMLDivElement>(null);
const visible = useResourceVisibility(container, active);
const [snapshotRequested, setSnapshotRequested] = useState(false);
useEffect(() => {
const root = container.current?.closest('.query-page');
const request = (event: Event) => { if (active && (event as CustomEvent<{modules:string[]}>).detail?.modules.includes('trend')) setSnapshotRequested(true); };
root?.addEventListener('quality:query-snapshot', request);
return () => root?.removeEventListener('quality:query-snapshot', request);
}, [active]);
const visible = useResourceVisibility(container, active) || snapshotRequested;
const chart = useRef<ReturnType<typeof echarts.init> | null>(null);
const onMonthRef = useRef(onMonth);
const rowsRef = useRef(rows);
@@ -1557,6 +1572,7 @@ export function RecordsDrawer({
<BusinessValue value={raw} />
</details>;
} },
...(retainedResult?.rows.some(record=>Object.hasOwn(record,'salesOrderType'))?[{title:'销售订单类型',dataIndex:'salesOrderType',key:'salesOrderType',width:170,render:(value:string|null)=>value||'未匹配'}]:[]),
{ title: '工作表', dataIndex: 'sheet', key: 'sheet', width: 120 },
{ title: '行号', dataIndex: 'rowNumber', key: 'rowNumber', align: 'right', width: 85 },
{ title: '月份', dataIndex: 'month', key: 'month', align: 'center', width: 100, render: value => {
@@ -1574,14 +1590,14 @@ export function RecordsDrawer({
return <Drawer className="source-records-drawer" open={open} onClose={onClose} width={Math.min(1120, window.innerWidth)} title={<div className="drawer-title">来源明细 <small>{row?.label || (month ? MONTHS[month - 1] : '当前筛选条件')}</small></div>} destroyOnClose>
<div className="drawer-controls"><Segmented disabled={lockedStage} value={stage} options={[{ label: '黑片', value: 'black' }, { label: '亮片', value: 'bright' }]} onChange={value => { onStage(value as Stage); setPage(1); setRawFields([]); setField(undefined); setFieldSearch(''); setSelectedColumns(undefined); setSort(undefined); }} aria-label="明细阶段" /><span>{result ? `共 ${result.total} 条来源记录 · 已载入 ${rawFields.length} 个原始字段` : '按当前查询条件获取原始来源行'}</span><Button size="small" icon={<DownloadOutlined />} loading={exporting} disabled={fetching || !result || !!error} onClick={exportRecords} title={lockedStage ? '导出当前阶段和筛选范围的全部来源明细' : '导出当前查询范围全部来源明细,含黑片和亮片两个工作表'}>导出明细 Excel</Button></div>
<div className="record-query-tools">
<label><span>字段检索</span><Select {...readableSelectPopup} allowClear showSearch optionFilterProp="label" placeholder="选择原始字段" value={field} options={rawFields.map(name => ({ label: name, value: name }))} onChange={value => { setField(value); setPage(1); }} /></label>
<div role="group"><span>字段检索</span><Select aria-label="字段检索" {...readableSelectPopup} allowClear showSearch optionFilterProp="label" placeholder="选择原始字段" value={field} options={rawFields.map(name => ({ label: name, value: name }))} onChange={value => { setField(value); setPage(1); }} /></div>
<Input allowClear disabled={!field} prefix={<SearchOutlined />} placeholder={field ? `搜索字段:${field}` : '先选择检索字段'} value={fieldSearch} onChange={event => { setFieldSearch(event.target.value); setPage(1); }} />
<label><span>显示列</span><Select {...readableSelectPopup} mode="multiple" allowClear showSearch optionFilterProp="label" placeholder="默认显示前 8 个字段" value={selectedColumns} options={rawFields.map(name => ({ label: name, value: name }))} onChange={value => { setSelectedColumns(value); setPage(1); }} /></label>
<label><span>排序字段</span><Select {...readableSelectPopup} allowClear showSearch optionFilterProp="label" placeholder="默认顺序" value={sort} options={[
<div role="group"><span>显示列</span><Select aria-label="显示列" {...readableSelectPopup} mode="multiple" allowClear showSearch optionFilterProp="label" placeholder="默认显示前 8 个字段" value={selectedColumns} options={rawFields.map(name => ({ label: name, value: name }))} onChange={value => { setSelectedColumns(value); setPage(1); }} /></div>
<div role="group"><span>排序字段</span><Select aria-label="排序字段" {...readableSelectPopup} allowClear showSearch optionFilterProp="label" placeholder="默认顺序" value={sort} options={[
{ label: '月份', value: 'month' }, { label: '来源文件', value: 'sourceFile' }, { label: '工作表', value: 'sheet' }, { label: '行号', value: 'rowNumber' },
{ label: '产业部', value: 'department' }, { label: '业务分组', value: 'group' }, { label: '项目组', value: 'projectGroup' }, { label: '产品', value: 'product' },
...(field ? [{ label: `原始字段:${field}`, value: 'rawField' }] : []),
]} onChange={value => { setSort(value); setPage(1); }} /></label>
]} onChange={value => { setSort(value); setPage(1); }} /></div>
<Segmented value={direction} options={[{ label: '升序', value: 'asc' }, { label: '降序', value: 'desc' }]} onChange={value => { setDirection(value as 'asc' | 'desc'); setPage(1); }} aria-label="排序方向" />
</div>
{error && <Alert type="error" showIcon message={retainedResult ? "更新失败,当前显示上次结果" : "来源明细加载失败"} description={error} action={<Button size="small" onClick={() => setRevision(value => value + 1)}>重试</Button>} />}