From 9dbe85c65cb97d1131a17df45e429eb778f48386 Mon Sep 17 00:00:00 2001 From: lyun Date: Sat, 31 Oct 2026 11:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8C=87=E6=A0=87=E5=8F=A3=E5=BE=84=E3=80=81?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E5=B8=83=E5=B1=80=E4=B8=8EExcel=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DESIGN.md | 15 +++ web/src/QueryPage.tsx | 112 +++++++++--------- web/src/StageProductPage.tsx | 15 ++- web/src/queryMetricValues.ts | 21 ++++ web/src/typography.css | 59 ++++++++- web/src/useStickyQueryMetrics.ts | 29 +++++ web/src/workspace-finish.css | 44 +++++++ web/verification/metric_workbook.test.mjs | 51 ++++++-- web/verification/query_metric_values.test.mjs | 27 +++++ 9 files changed, 301 insertions(+), 72 deletions(-) create mode 100644 web/src/queryMetricValues.ts create mode 100644 web/src/useStickyQueryMetrics.ts create mode 100644 web/verification/query_metric_values.test.mjs diff --git a/DESIGN.md b/DESIGN.md index b6b4803..4e0555f 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -36,3 +36,18 @@ - 查询页字号比例追加调整:适当放大筛选与表格、收小指标,四项指标标签统一13px/600;已按用户要求发布并同步源码。(用户反馈字号不协调,具体取值由Agent推断) - 查询页趋势图与柏拉图同步使用页面字体变量:图例与单位使用界面字体、数值刻度使用数字字体,悬浮提示略大;抵消图表局部缩放,保持与表格文字协调。已检查趋势图深浅主题,类型检查与8项相关回归通过;底部预览已补入当前线上全年筛选的真实快照,33个细分字段齐全;已核对不良构成与柏拉图深浅主题,阶段标题14px、分类与数值13px、辅助表头12px,保留原有数据核对提示。2026-10-30 已按用户要求发布。 + +- 查询表格语义配色:黑片黑色、亮片沿用原黑片的主题蓝色、综合合格率沿用原亮片绿色,覆盖总体/产业部/业务分组/产品/黑片/亮片汇总及月度数据表;顶部指标同步。午夜黑主题中黑片文字以中性浅灰保证对比度。2026-10-31 已按用户要求发布。(用户指定颜色,深色适配由Agent推断) + +- 查询字号进一步调整:顶部综合合格率42px(移动端沿用现有自适应),月份及产业部对象16px、表内综合合格率15px、所有查询表头14px/600;布局与其他业务数字字号不变。已检查深浅主题,无指标截断或页面横向溢出,2026-10-31 已按用户要求发布。(用户指定层级,具体取值由Agent推断) + +- 查询列顺序:综合合格率移至操作列之前,桌面端两列固定右侧;完整字段模式采用重量112px、阶段合格率96px、不良分类100px,综合合格率120px、操作96px。对象列按月份/组织/产品分别设置;月度趋势数据表综合合格率也置于最右。导出沿用显示列顺序。已实测横向滚动右侧位置不变,2026-10-31 已发布。 + +- 跨两行查询表头字重700,单行表头600;右侧冻结综合合格率列补充独立左边框,贯穿表头与数据行。深浅主题与左右滚动已验证,2026-10-31 已发布。 + +- 指标卡片与顶部筛选栏同步冻结,按筛选栏实际高度定位,展开筛选与换行自动更新,并为小屏保留阅读空间。删除“亮片本部报废调整”说明,保留口径切换。 +- 关键指标、完整字段与月度数据表的两阶段总重量均置于合格重量之前。黑片总重量增加悬浮规则提示,说明利用料/废品库扣减与过账外废处理;直接展示已发布数据结果。 +- 原口径下本部报废列紧随扩散废;去本部报废时隐藏该列,并在卡片、表格、趋势、Excel中统一扣减亮片报废重量。不改来源数据、总重量与后端合格率公式;缺失分量时显示不可用。 +- 指标名称保持“亮片合格率”“综合合格率”,切换后增加11px/400的“(去本部报废)”小字。顶部卡片与跨行综合表头分行显示,亮片二级表头单行显示以维持行高;说明图标样式与黑片总重一致,保留原有计算口径入口。 +- 所有查询页导出按钮显示下载图标与“Excel导出”文字。 +- 2026-10-31 已按用户要求发布;构建及31项相关检查通过,线上字段顺序、口径切换、导出入口与顶部冻结已核对。 diff --git a/web/src/QueryPage.tsx b/web/src/QueryPage.tsx index aeb2e12..ac01261 100644 --- a/web/src/QueryPage.tsx +++ b/web/src/QueryPage.tsx @@ -1,3 +1,5 @@ +import { queryScrapWeight, queryTotalScrapWeight, type QueryRateBasis } from './queryMetricValues'; +import { useStickyQueryMetrics } from './useStickyQueryMetrics'; import { BusinessValue } from './BusinessValue'; import { usePageCache } from './pageCache'; import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react'; @@ -22,7 +24,7 @@ import { Tooltip, } from 'antd'; import type { ColumnsType } from 'antd/es/table'; -import { DownloadOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons'; +import { DownloadOutlined, InfoCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons'; import { ApiError, api, decodeQueryValueList, encodeQueryValueList } from './api'; import type { DefectMetric, @@ -193,8 +195,8 @@ function objectLabel(row: MetricRow, view: ViewKind): string { return row.product || row.label; } -function stageValue(row: MetricRow | undefined, stage: Stage, field: 'qualifiedWeight' | 'scrapWeight' | 'totalWeight' | 'rate' | 'headquartersScrapWeight'): number | null { - return row?.[stage]?.[field] ?? null; +function stageValue(row: MetricRow | undefined, stage: Stage, field: 'qualifiedWeight' | 'scrapWeight' | 'totalWeight' | 'rate' | 'headquartersScrapWeight', basis: QueryRateBasis = 'original'): number | null { + return field === 'scrapWeight' ? queryScrapWeight(row?.[stage], stage, basis) : row?.[stage]?.[field] ?? null; } function defectList(row: MetricRow | undefined, stage: Stage): DefectMetric[] { @@ -285,6 +287,7 @@ export default function QueryPage({ page, onUnauthorized }: { onUnauthorized: (error: unknown) => boolean; onNavigate?: (page: PageKey, query: QueryParams, resultRef?: TopResultRef) => void; }) { + const stickyPageRef = useStickyQueryMetrics(); const { message } = App.useApp(); const { active, initialSearch, refreshKey, onLocationChange } = usePageCache(); const baseView = SCOPE[page] || 'overall'; @@ -697,7 +700,7 @@ export default function QueryPage({ page, onUnauthorized }: { ].filter(Boolean); return ( -
+
{optionsError && } onClick={() => { setOptionsLoading(true); api.options().then(result => { setOptions(result); setOptionsError(''); }).catch(e => { if (!onUnauthorized(e)) setOptionsError(chooseError(e)); }).finally(() => setOptionsLoading(false)); }}>重试} />}
} onClick={() => setQueryRevision(value => value + 1)}>重试} />} {drilledProduct && summaryMetricsError && setQueryRevision(value => value + 1)}>重试} />}
-
亮片本部报废调整 setRateBasis(value as typeof rateBasis)} aria-label="合格率口径" />
- setBasisOpen(true)} /> +
setRateBasis(value as typeof rateBasis)} aria-label="合格率口径" />
+ setBasisOpen(true)} /> openRecords(null, 'black')} /> - openRecords(null, 'bright')} /> - openRecords(null, 'black')} /> + openRecords(null, 'bright')} /> + openRecords(null, 'black')} />
-
- {drilledProduct && <>{drilledProduct} · }{summaryMetricsData ? <>来源覆盖 {summaryMetricsData.coverage.sourceMonths.filter(item => item.blackRows > 0 || item.brightRows > 0).length} 个月 · 参与计算 {summaryMetricsData.coverage.includedRows.toLocaleString('zh-CN')} / 原始 {summaryMetricsData.coverage.rawRows.toLocaleString('zh-CN')} 行 · 未分类 {summaryMetricsData.coverage.excludedBlankRows.toLocaleString('zh-CN')} 行({includeUnassigned ? '已包含' : '本次排除'}) : summaryBusy ? '正在更新来源覆盖…' : '来源覆盖暂不可用'} - - -
- {['department', 'group', 'product'].includes(page) && <> {options?.projectGroupStatus === 'UNCONFIGURED' && } } @@ -769,12 +766,12 @@ export default function QueryPage({ page, onUnauthorized }: { setDefectDisplay(value as typeof defectDisplay)} aria-label="不良显示方式" /> {!drilledProduct && (view === 'group' || view === 'product' && (group.length > 0 || department.length > 0)) && } {drilledProduct && } -
横向滑动查看完整指标
@@ -828,13 +825,12 @@ export default function QueryPage({ page, onUnauthorized }: { /> )} -
{queryBusy ? '正在更新当前查询结果…' : drilledProduct ? trendLoading && trendDataKey !== trendKey ? `${drilledProduct} · 正在查询月度数据` : `${drilledProduct} · 共 ${drilledTrendData.length} 个月` : page === 'overall' && period === 'year' ? `年度月份 12 行 · 已有数据 ${new Set((currentMetricsData?.trend || []).map(item => String(item.month))).size} 个月` : `共 ${visibleRows.length} 行`}
- + setTrendMode(value as typeof trendMode)} aria-label="趋势视图" />
@@ -850,12 +846,12 @@ export default function QueryPage({ page, onUnauthorized }: { : } {(trendLoading || (useSummaryTrend && queryBusy)) && 正在更新趋势}
-
全年期间均显示;无数据期间留空,指标由源分量重新汇总。点击期间筛选,再次点击可取消
+
点击期间筛选,再次点击可取消
- +
{trendObjectMetricsLoading &&
正在更新当前趋势对象的不良数据
} {trendObjectMetricsError && } @@ -879,8 +875,8 @@ export default function QueryPage({ page, onUnauthorized }: { - setBasisOpen(false)} footer={} width={680}> -
当前{rateBasis === 'original' ? '综合合格率' : '综合调整率'}{rateText(visibleCompositeRate(rowForSummary, rateBasis))}黑片 {rateText(visibleStageRate(rowForSummary, 'black'))} · {rateBasis === 'original' ? '亮片' : '亮片调整率'} {rateText(visibleStageRate(rowForSummary, 'bright', rateBasis))}
+ setBasisOpen(false)} footer={} width={680}> +
当前综合合格率{rateText(visibleCompositeRate(rowForSummary, rateBasis))}黑片 {rateText(visibleStageRate(rowForSummary, 'black'))} · 亮片 {rateText(visibleStageRate(rowForSummary, 'bright', rateBasis))}

以下为当前查询实际使用的公式、适用条件与空值处理规则。月、季、年先汇总计算分量,再按生效公式计算。

综合公式
{formulaText(compositeFormula)}
@@ -911,7 +907,7 @@ export default function QueryPage({ page, onUnauthorized }: { ); } -export function MetricCard({ primary, label, value, note, stage, onClick }: { primary?: boolean; label: string; value: string; note?: string; stage?: Stage; onClick: () => void }) { +export function MetricCard({ primary, label, value, note, stage, onClick }: { primary?: boolean; label: React.ReactNode; value: string; note?: string; stage?: Stage; onClick: () => void }) { const parts = value.match(/^(.*?)(%| kg)$/); return
; } -const FINE_DEFECT_FIELD_COUNT = 33; export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUnauthorized, onlyStage }: { releaseId?: string; query: QueryParams; externalScrapWeight?: number | null; onUnauthorized: (error: unknown) => boolean; onlyStage?: Stage; @@ -1008,13 +1003,12 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna kind: 'source' as const, }))); if (onlyStage !== 'bright' && typeof externalScrapWeight === 'number' && Number.isFinite(externalScrapWeight) && externalScrapWeight > 0) { - raw.push({ key: 'black:externalScrap', label: '黑片·外废(仅大类重量)', category: '外废', weight: externalScrapWeight, kind: 'category' }); + raw.push({ key: 'black:externalScrap', label: '黑片·外废', category: '外废', weight: externalScrapWeight, kind: 'category' }); } return raw.filter(item => typeof item.weight === 'number' && Number.isFinite(item.weight) && item.weight > 0) .sort((left, right) => right.weight! - left.weight! || left.label.localeCompare(right.label, 'zh-CN')); }, [responses, externalScrapWeight, onlyStage]); const totalWeight = items.reduce((total, item) => total + (item.weight || 0), 0); - const visibleFieldCount = responses ? (responses.black.sourceFields?.length || 0) + (responses.bright.sourceFields?.length || 0) : 0; useEffect(() => { const instance = chart.current; @@ -1037,7 +1031,7 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna textStyle: { color: ink, fontFamily, fontSize }, animationDuration: 420, animationDurationUpdate: 520, - grid: { left: 68, right: 72, top: 48, bottom: items.length > 12 ? 92 : 62, containLabel: true }, + grid: { left: 32, right: 24, top: 48, bottom: 12, containLabel: true }, legend: { top: 8, data: ['报废重量', '累计占比'], textStyle: { color: ink, fontFamily, fontSize, fontWeight: 500 } }, tooltip: { trigger: 'axis', @@ -1051,7 +1045,7 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna const item = items[index]; if (!item) return ''; const share = totalWeight > 0 ? (item.weight || 0) / totalWeight * 100 : 0; - return `${escapeTooltipText(item.label)}
分类:${escapeTooltipText(item.category)}
报废重量:${numberText(item.weight)} kg
综合占比:${share.toFixed(2)}%
累计占比:${cumulative[index].toFixed(2)}%${item.kind === 'category' ? '
来源仅提供大类重量' : '
来自源表细分重量字段'}`; + return `${escapeTooltipText(item.label)}
分类:${escapeTooltipText(item.category)}
报废重量:${numberText(item.weight)} kg
综合占比:${share.toFixed(2)}%
累计占比:${cumulative[index].toFixed(2)}%`; }, }, xAxis: { @@ -1073,13 +1067,8 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna instance.setOption(option, { notMerge: true, lazyUpdate: false }); }, [items, totalWeight, themeRevision]); - const incompleteCategories = responses - ? (['black', 'bright'] as const).flatMap(stage => responses[stage].coverage?.categories || []) - .filter(item => item.reconciliationStatus !== 'RECONCILED' && item.reconciliationStatus !== 'UNAVAILABLE').length - : 0; - return
-
{onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '黑片与亮片综合报废重量柏拉图'}{responses ? `细分源字段 ${visibleFieldCount}${onlyStage ? '' : ` / ${FINE_DEFECT_FIELD_COUNT}`} 项${incompleteCategories ? ` · ${incompleteCategories} 类细分数据未与正式大类完全核对` : ''}` : '按当前筛选范围汇总全部可见细分报废重量'}
+
{onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '黑片与亮片综合报废重量柏拉图'}
{loading &&
正在汇总细分报废重量
} {error && } {!loading && !releaseId && } @@ -1103,6 +1092,12 @@ function useCompactTable() { return compact; } +export const rateMetricLabel = (label: string, basis: QueryRateBasis) => {label}{basis !== 'original' && (去本部报废)}; + +const totalWeightTitle = (label: string) => {label}黑片总重量为合格率计算使用的适用总重量。
按来源逐行计算:合格重量+报废重量-利用料及废品库对应的合格重量、报废重量;发料地点包含“利用料”或“废品”时扣减。
检验备注包含“过账”时,外废不计入报废重量;月、季、年均先汇总来源分量。具体取值以已发布数据版本及生效规则为准。}>
; + +const rateBasisTitle = (label: string, basis: QueryRateBasis, kind: 'bright' | 'composite', onBasis?: () => void) => {onBasis ? : label}{basis !== 'original' && (去本部报废)}{kind === 'composite' && <>综合合格率=黑片合格率×亮片合格率。
}原口径:亮片合格重量÷亮片总重量。
去本部报废:(亮片合格重量+本部报废)÷亮片总重量,同时从亮片报废重量中扣除本部报废,总重量不变。
当前:{basis === 'original' ? '原口径' : '去本部报废'}。计算结果以已发布数据版本及生效规则为准。}>
; + export function MetricTable({ ref, exportFilename, rows, view, layoutView = view, pageSizeOverride, period, month, quarter, fullFields, rateBasis, onDetail, onBasis, onDrilldown, onlyStage, defectDisplay = 'weight', emptyText = '当前条件下暂无数据', }: { @@ -1125,31 +1120,37 @@ export function MetricTable({ onDetail(row, stage, isOverall && period === 'year' ? monthNumber((row as TrendMetricRow).month) || undefined : isOverall && period === 'month' ? month : undefined); }; const numeric = (label: string, stage: Stage, field: 'qualifiedWeight' | 'scrapWeight' | 'totalWeight' | 'rate' | 'headquartersScrapWeight', className = '') => ({ - title: `${compact ? stage === 'black' ? '黑片' : '亮片' : ''}${defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight') ? defectRateLabel(label) : label}`, + title: stage === 'black' && field === 'totalWeight' ? totalWeightTitle(`${compact ? '黑片' : ''}${label}`) : stage === 'bright' && field === 'rate' ? rateBasisTitle(`${compact ? '亮片' : ''}${label}`, rateBasis, 'bright') : `${compact ? stage === 'black' ? '黑片' : '亮片' : ''}${defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight') ? defectRateLabel(label) : label}`, exportRate: defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight'), key: `${stage}-${field}`, align: 'center' as const, - width: field === 'rate' ? 116 : 145, + width: field === 'rate' ? (stage === 'bright' && rateBasis !== 'original' ? 164 : fullFields ? 96 : 116) : (fullFields ? 112 : 145), className: `${field === 'rate' ? `rate-cell ${stage}` : 'weight-cell'} ${className}`, - render: (_: unknown, row: MetricRow) => , + render: (_: unknown, row: MetricRow) => , }); const defectColumns = (stage: Stage, names: string[]) => names.map(name => ({ title: `${compact ? stage === 'black' ? '黑片' : '亮片' : ''}${defectDisplay === 'rate' ? defectRateLabel(name) : name}`, exportRate: defectDisplay === 'rate', key: `${stage}-defect-${name}`, align: 'center' as const, - width: 130, + width: fullFields ? 100 : 130, render: (_: unknown, row: MetricRow) => { const value = defectList(row, stage).find(item => item.name === name); return ; }, })); + const brightDetailColumns: ColumnsType = defectColumns('bright', brightDefects); + if (fullFields && rateBasis === 'original') { + const diffusionIndex = brightDetailColumns.findIndex(column => column.key === 'bright-defect-扩散废'); + brightDetailColumns.splice(diffusionIndex < 0 ? brightDetailColumns.length : diffusionIndex + 1, 0, + numeric('本部报废', 'bright', 'headquartersScrapWeight')); + } const allColumns: ColumnsType = [ - { title: isOverall ? period === 'year' ? '月份' : '统计期间' : view === 'group' ? '产业部 / 业务分组' : view === 'product' ? '产品规格' : view === 'projectGroup' ? '项目组' : view === 'department' ? '产业部' : '对象', key: 'object', dataIndex: 'label', fixed: 'left', width: compact ? isOverall ? 100 : 180 : layoutView === 'product' ? 300 : layoutView === 'group' ? 260 : 220, render: (_: unknown, row) => {view === 'department' || view === 'group' || view === 'product' ? : {title(row)}}{view === 'group' && row.department && {row.department}} }, - { title: , key: 'compositeRate', dataIndex: 'compositeRate', align: 'center', fixed: compact ? undefined : 'left', width: 140, className: 'combined-column', render: (_: number | null, row: MetricRow) => }, - { key: 'stage-black', title: 黑片, children: [numeric('合格重量', 'black', 'qualifiedWeight'), ...(fullFields ? [numeric('总重量', 'black', 'totalWeight')] : []), numeric('报废重量', 'black', 'scrapWeight'), ...defectColumns('black', blackDefects), numeric('合格率', 'black', 'rate')] }, - { key: 'stage-bright', title: 亮片, children: [numeric('合格重量', 'bright', 'qualifiedWeight'), ...(fullFields ? [numeric('总重量', 'bright', 'totalWeight')] : []), numeric('报废重量', 'bright', 'scrapWeight'), ...(fullFields ? [numeric('本部报废重量', 'bright', 'headquartersScrapWeight')] : []), ...defectColumns('bright', brightDefects), { ...numeric(rateBasis === 'original' ? '合格率' : '不含本部报废调整率', 'bright', 'rate'), render: (_: unknown, row: MetricRow) => }] }, - { title: '操作', key: 'actions', fixed: compact ? undefined : 'right', width: 100, align: 'center', render: (_: unknown, row) => (row as TrendMetricRow).noData ? — : }, + { title: isOverall ? period === 'year' ? '月份' : '统计期间' : view === 'group' ? '产业部 / 业务分组' : view === 'product' ? '产品规格' : view === 'projectGroup' ? '项目组' : view === 'department' ? '产业部' : '对象', key: 'object', dataIndex: 'label', fixed: 'left', width: compact ? isOverall ? 100 : 180 : isOverall ? 120 : layoutView === 'product' ? (fullFields ? 240 : 300) : layoutView === 'group' ? (fullFields ? 220 : 260) : (fullFields ? 180 : 220), render: (_: unknown, row) => {view === 'department' || view === 'group' || view === 'product' ? : {title(row)}}{view === 'group' && row.department && {row.department}} }, + { key: 'stage-black', title: 黑片, children: [numeric('总重量', 'black', 'totalWeight'), numeric('合格重量', 'black', 'qualifiedWeight'), numeric('报废重量', 'black', 'scrapWeight'), ...defectColumns('black', blackDefects), numeric('合格率', 'black', 'rate')] }, + { key: 'stage-bright', title: 亮片, children: [numeric('总重量', 'bright', 'totalWeight'), numeric('合格重量', 'bright', 'qualifiedWeight'), numeric('报废重量', 'bright', 'scrapWeight'), ...brightDetailColumns, { ...numeric('合格率', 'bright', 'rate'), render: (_: unknown, row: MetricRow) => }] }, + { title: rateBasisTitle('综合合格率', rateBasis, 'composite', onBasis), key: 'compositeRate', dataIndex: 'compositeRate', align: 'center', fixed: compact ? undefined : 'right', width: 120, className: 'combined-column', render: (_: number | null, row: MetricRow) => }, + { title: '操作', key: 'actions', fixed: compact ? undefined : 'right', width: 96, align: 'center', render: (_: unknown, row) => (row as TrendMetricRow).noData ? — : }, ]; const columns = onlyStage ? allColumns.filter(column => !['compositeRate', `stage-${onlyStage === 'black' ? 'bright' : 'black'}`].includes(String(column.key))) : allColumns; useImperativeHandle(ref, () => ({ @@ -1162,8 +1163,8 @@ export function MetricTable({ return defectDisplay === 'rate' ? defectWeightRate(weight,stageValue(row,stage,'totalWeight')) : weight; } const field = key.slice(stage.length + 1) as 'qualifiedWeight' | 'scrapWeight' | 'totalWeight' | 'headquartersScrapWeight' | 'rate'; - if (defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight')) return defectWeightRate(stageValue(row,stage,field),stageValue(row,stage,'totalWeight')); - return field === 'rate' ? visibleStageRate(row, stage, stage === 'bright' ? rateBasis : 'original') : stageValue(row, stage, field); + if (defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight')) return defectWeightRate(stageValue(row,stage,field,rateBasis),stageValue(row,stage,'totalWeight')); + return field === 'rate' ? visibleStageRate(row, stage, stage === 'bright' ? rateBasis : 'original') : stageValue(row, stage, field, rateBasis); }), })); const dataSource = rows.map((row, index) => ({ ...row, key: row.key || `${title(row)}-${index}` })); @@ -1182,7 +1183,7 @@ export function MetricTable({ const scroll = { x: scrollWidth }; const displayColumns = compact ? columns.flatMap(column => 'children' in column && column.children ? column.children : [column]) : columns; const pageRows = dataSource.slice((effectivePage - 1) * effectivePageSize, effectivePage * effectivePageSize); - return
size="small" bordered columns={displayColumns} dataSource={pageRows} pagination={false} scroll={scroll} rowKey="key" locale={{ emptyText }} /> + return
size="small" bordered tableLayout="fixed" columns={displayColumns} dataSource={pageRows} pagination={false} scroll={scroll} rowKey="key" locale={{ emptyText }} /> {pageSizeOverride == null && { setPageSize(nextPageSize); setCurrentPage(nextPageSize === pageSize ? nextPage : 1); }} />}
; } @@ -1291,7 +1292,7 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP const surface = css.getPropertyValue('--surface').trim() || '#ffffff'; const labels = rows.map(row => row.periodLabel || String(row.month)); const barData = (field: 'qualifiedWeight' | 'scrapWeight') => rows.map(row => ({ - value: hasStageRows(row, stage) ? row[stage][field] ?? null : null, + value: hasStageRows(row, stage) ? stageValue(row, stage, field, rateBasis) : null, })); const formatTooltip = (params: unknown, onlyRates = false) => { const items: ChartTooltipParam[] = Array.isArray(params) ? params as ChartTooltipParam[] : [params as ChartTooltipParam]; @@ -1334,9 +1335,9 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP series: [ { id: 'qualified-weight', name: `${stageName}合格重量`, type: 'bar', z: 1, stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: barColor }, emphasis: { itemStyle: { color: blue } }, data: barData('qualifiedWeight') }, { id: 'scrap-weight', name: `${stageName}报废重量`, type: 'bar', z: 1, stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: '#edaa83' }, emphasis: { itemStyle: { color: '#e58e5d' } }, data: barData('scrapWeight') }, - { id: 'composite-rate', name: rateBasis === 'original' ? '综合合格率' : '综合调整率', type: 'line', yAxisIndex: 1, ...pointStyle, ...targetLine, lineStyle: { width: 2.5, color: blue }, itemStyle: { color: blue, borderColor: surface, borderWidth: 1.5 }, data: rows.map(row => rateNumber(visibleCompositeRate(row, rateBasis))) }, + { id: 'composite-rate', name: '综合合格率', type: 'line', yAxisIndex: 1, ...pointStyle, ...targetLine, lineStyle: { width: 2.5, color: blue }, itemStyle: { color: blue, borderColor: surface, borderWidth: 1.5 }, data: rows.map(row => rateNumber(visibleCompositeRate(row, rateBasis))) }, { id: 'black-rate', name: '黑片合格率', type: 'line', yAxisIndex: 1, ...pointStyle, lineStyle: { width: 1.8, color: '#9278bf' }, itemStyle: { color: '#9278bf', borderColor: surface, borderWidth: 1 }, data: rows.map(row => rateNumber(visibleStageRate(row, 'black'))) }, - { id: 'bright-rate', name: rateBasis === 'original' ? '亮片合格率' : '亮片不含本部报废调整率', type: 'line', yAxisIndex: 1, ...pointStyle, lineStyle: { width: 1.8, color: teal }, itemStyle: { color: teal, borderColor: surface, borderWidth: 1 }, data: rows.map(row => rateNumber(visibleStageRate(row, 'bright', rateBasis))) }, + { id: 'bright-rate', name: '亮片合格率', type: 'line', yAxisIndex: 1, ...pointStyle, lineStyle: { width: 1.8, color: teal }, itemStyle: { color: teal, borderColor: surface, borderWidth: 1 }, data: rows.map(row => rateNumber(visibleStageRate(row, 'bright', rateBasis))) }, ], }; } else { @@ -1399,20 +1400,23 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP } function TrendTable({ rows, rateBasis, onMonth, defectDisplay = 'weight', showMonthLinks = true }: { rows: TrendMetricRow[]; rateBasis: 'original' | 'withoutHeadquartersScrap'; onMonth: (value: number | string) => void; defectDisplay?: 'weight'|'rate'; showMonthLinks?: boolean }) { + const compact = useCompactTable(); const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(SUMMARY_PAGE_SIZE); useEffect(() => setCurrentPage(1), [rows]); const columns: ColumnsType = [ { title: '统计期间', dataIndex: 'month', key: 'month', align: 'center', fixed: 'left', width: 130, render: (_: unknown, row) => }, - { title: rateBasis === 'original' ? '综合合格率' : '综合调整率', dataIndex: 'compositeRate', key: 'compositeRate', align: 'center', width: 130, className: 'combined-column', render: (_: number | null, row: MetricRow) => rateText(visibleCompositeRate(row, rateBasis)) }, + { title: totalWeightTitle('黑片总重量 / kg'), dataIndex: ['black', 'totalWeight'], key: 'blackTotal', align: 'center', width: 160, render: value => numberText(value) }, { title: '黑片合格重量 / kg', dataIndex: ['black', 'qualifiedWeight'], key: 'blackQualified', align: 'center', width: 160, render: value => numberText(value) }, { title: defectDisplay === 'rate' ? '黑片报废率' : '黑片报废重量 / kg', dataIndex: ['black', 'scrapWeight'], key: 'blackScrap', align: 'center', width: 160, render: (_: unknown, row: TrendMetricRow) => defectDisplay === 'rate' ? rateText(defectWeightRate(row.black.scrapWeight,row.black.totalWeight)) : numberText(row.black.scrapWeight) }, - { title: '黑片合格率', dataIndex: ['black', 'rate'], key: 'blackRate', align: 'center', width: 130, render: (_: number | null, row: TrendMetricRow) => rateText(visibleStageRate(row, 'black')) }, + { title: '黑片合格率', dataIndex: ['black', 'rate'], key: 'blackRate', align: 'center', width: 130, className: 'rate-cell black', render: (_: number | null, row: TrendMetricRow) => rateText(visibleStageRate(row, 'black')) }, + { title: '亮片总重量 / kg', dataIndex: ['bright', 'totalWeight'], key: 'brightTotal', align: 'center', width: 160, render: value => numberText(value) }, { title: '亮片合格重量 / kg', dataIndex: ['bright', 'qualifiedWeight'], key: 'brightQualified', align: 'center', width: 160, render: value => numberText(value) }, - { title: defectDisplay === 'rate' ? '亮片报废率' : '亮片报废重量 / kg', dataIndex: ['bright', 'scrapWeight'], key: 'brightScrap', align: 'center', width: 160, render: (_: unknown, row: TrendMetricRow) => defectDisplay === 'rate' ? rateText(defectWeightRate(row.bright.scrapWeight,row.bright.totalWeight)) : numberText(row.bright.scrapWeight) }, - { title: rateBasis === 'original' ? '亮片合格率' : '亮片不含本部报废调整率', dataIndex: ['bright', 'rate'], key: 'brightRate', align: 'center', width: 180, render: (_: number | null, row: TrendMetricRow) => rateText(visibleStageRate(row, 'bright', rateBasis)) }, + { title: defectDisplay === 'rate' ? '亮片报废率' : '亮片报废重量 / kg', dataIndex: ['bright', 'scrapWeight'], key: 'brightScrap', align: 'center', width: 160, render: (_: unknown, row: TrendMetricRow) => defectDisplay === 'rate' ? rateText(defectWeightRate(queryScrapWeight(row.bright,'bright',rateBasis),row.bright.totalWeight)) : numberText(queryScrapWeight(row.bright,'bright',rateBasis)) }, + { title: rateBasisTitle('亮片合格率', rateBasis, 'bright'), dataIndex: ['bright', 'rate'], key: 'brightRate', align: 'center', width: rateBasis === 'original' ? 180 : 194, className: 'rate-cell bright', render: (_: number | null, row: TrendMetricRow) => rateText(visibleStageRate(row, 'bright', rateBasis)) }, + { title: rateBasisTitle('综合合格率', rateBasis, 'composite'), dataIndex: 'compositeRate', key: 'compositeRate', align: 'center', width: 120, fixed: compact ? undefined : 'right', className: 'combined-column', render: (_: number | null, row: MetricRow) => rateText(visibleCompositeRate(row, rateBasis)) }, ]; - return rows.length ?
String(row.month)} pagination={{ current: currentPage, pageSize, showSizeChanger: rows.length > SUMMARY_PAGE_SIZE, pageSizeOptions: SUMMARY_PAGE_SIZE_OPTIONS, showTotal: (total, range) => `显示 ${range[0]}–${range[1]} 行,共 ${total} 个月`, onChange: (nextPage, nextPageSize) => { setPageSize(nextPageSize); setCurrentPage(nextPageSize === pageSize ? nextPage : 1); } }} scroll={{ x: 1130 }} /> + return rows.length ?
String(row.month)} pagination={{ current: currentPage, pageSize, showSizeChanger: rows.length > SUMMARY_PAGE_SIZE, pageSizeOptions: SUMMARY_PAGE_SIZE_OPTIONS, showTotal: (total, range) => `显示 ${range[0]}–${range[1]} 行,共 ${total} 个月`, onChange: (nextPage, nextPageSize) => { setPageSize(nextPageSize); setCurrentPage(nextPageSize === pageSize ? nextPage : 1); } }} scroll={{ x: columns.reduce((total, column) => total + Number(column.width || 0), 0) }} /> {showMonthLinks &&
{rows.map(row => )}
} : ; } diff --git a/web/src/StageProductPage.tsx b/web/src/StageProductPage.tsx index f3908e9..20ee88f 100644 --- a/web/src/StageProductPage.tsx +++ b/web/src/StageProductPage.tsx @@ -1,8 +1,10 @@ +import { queryScrapWeight } from './queryMetricValues'; +import { useStickyQueryMetrics } from './useStickyQueryMetrics'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { Alert, App, Button, Checkbox, Empty, Input, Modal, Segmented, Select, Spin } from 'antd'; import { DownloadOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons'; import { api, decodeQueryValueList, encodeQueryValueList } from './api'; -import { MetricTable, MetricCard, DefectBreakdown, DefectParetoPanel, SectionHeading, RecordsDrawer, TrendChart, fullYearTrend, queryFromLocation } from './QueryPage'; +import { MetricTable, MetricCard, rateMetricLabel, DefectBreakdown, DefectParetoPanel, SectionHeading, RecordsDrawer, TrendChart, fullYearTrend, queryFromLocation } from './QueryPage'; import { StageSourceFilters } from './StageSourceFilters'; import { stageProductQuery, sortStageRowsByTotalWeight } from './stageProductQuery'; import { usePageCache } from './pageCache'; @@ -15,6 +17,7 @@ import './stage-product.css'; const weight=(v:number|null|undefined)=>typeof v==='number'?v.toLocaleString('zh-CN',{maximumFractionDigits:2}):'—'; const rate=(v:number|null|undefined)=>typeof v==='number'?`${(v*100).toFixed(2)}%`:'—'; export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onUnauthorized:(error:unknown)=>boolean}) { + const stickyPageRef = useStickyQueryMetrics(); const {message}=App.useApp();const {active,initialSearch,refreshKey,onLocationChange}=usePageCache(); const [initial]=useState(()=>queryFromLocation(initialSearch));const defaults=previousCompleteMonth(); const [period,setPeriod]=useState(initial.quarter?'quarter':initial.month?'month':initial.year?'year':'month'); @@ -61,7 +64,7 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU const openDetail=(row:MetricRow|null,_stage:Stage,selectedMonth?:number)=>{if(!applied||!current?.release)return;setRecords({row,query:{...applied,releaseId:current.release.id,...(row&&selectedMonth==null?{product:row.product||'__UNASSIGNED__'}:{}),...(selectedMonth?{month:selectedMonth,quarter:undefined}: {})}});}; const runExport=async()=>{setExporting(true);try{await exporter.current?.exportExcel();}catch(e){message.error(e instanceof Error?e.message:'导出失败');}finally{setExporting(false);}}; const formulaKey=stage==='black'?'blackRate':rateBasis==='original'?'brightRate':'brightRateWithoutHeadquartersScrap'; - return
+ return
{supportError&&void loadSupport()}>重试}/>}
setPeriod(v as PeriodKind)}/> @@ -80,14 +83,14 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU
{error&&setRevision(v=>v+1)}>重试}/>}
- {stage==='bright'&&
亮片本部报废调整setRateBasis(v as typeof rateBasis)}/>
} - setBasisOpen(true)}/> + {stage==='bright'&&
setRateBasis(v as typeof rateBasis)}/>
} + setBasisOpen(true)}/> openDetail(null,stage)}/> - openDetail(null,stage)}/> + openDetail(null,stage)}/> openDetail(null,stage)}/>
{current?`来源覆盖 ${current.coverage.sourceMonths.filter(m=>(stage==='black'?m.blackRows:m.brightRows)>0).length} 个月 · 参与计算 ${current.coverage.includedRows.toLocaleString()} 行`:loading?'正在查询…':'暂无统计结果'}
-
setSearch(e.target.value)} onPressEnter={submit}/>setFullFields(v==='full')}/>setDefectDisplay(v as typeof defectDisplay)}/>
+
setSearch(e.target.value)} onPressEnter={submit}/>setFullFields(v==='full')}/>setDefectDisplay(v as typeof defectDisplay)}/>
setBasisOpen(true)} onDrilldown={row=>{setProduct([row.product||'__UNASSIGNED__']);setSearch('');setApplied({...applied!,product:row.product||'__UNASSIGNED__',productSearch:undefined});setRevision(v=>v+1);}}/>
setTrendMode(v as typeof trendMode)}/>
{trendMode==='data'&&setDefectDisplay(v as typeof defectDisplay)}/>}