优化:查询页面平滑切换与默认月份高亮
This commit is contained in:
+104
-99
@@ -1,3 +1,4 @@
|
||||
import { AnimatedMetricText, SmoothTableFrame, useAnimatedMetricText, useRetainedResult } from './QueryResultMotion';
|
||||
import { trendBarPalette } from './trendBarPalette';
|
||||
import { getWorkspaceTheme } from './ui-themes';
|
||||
import { queryScrapWeight, queryTotalScrapWeight, type QueryRateBasis } from './queryMetricValues';
|
||||
@@ -44,7 +45,7 @@ import type {
|
||||
import type { PageKey } from './QualityWorkspace';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
import { isInternalDataField, readableMetricFormula } from './publicDataDisplay';
|
||||
import { previousCompleteMonth, previousCompleteQuarter } from './periodDefaults';
|
||||
import { defaultQueryMonth, previousCompleteMonth, previousCompleteQuarter } from './periodDefaults';
|
||||
import { defectWeightRate } from './trendMetrics';
|
||||
import './query-motion.css';
|
||||
import { ExtraQueryFilters } from './ExtraQueryFilters';
|
||||
@@ -299,9 +300,10 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [options, setOptions] = useState<OptionsResponse | null>(null);
|
||||
const [optionsError, setOptionsError] = useState('');
|
||||
const [optionsLoading, setOptionsLoading] = useState(true);
|
||||
const automaticPeriod = useRef(!initialQuery.year && !initialQuery.month && !initialQuery.quarter);
|
||||
const defaultMonth = previousCompleteMonth();
|
||||
const defaultQuarter = previousCompleteQuarter();
|
||||
const [period, setPeriod] = useState<PeriodKind>(initialQuery.month ? 'month' : initialQuery.quarter ? 'quarter' : page === 'overall' ? 'year' : 'month');
|
||||
const [period, setPeriod] = useState<PeriodKind>(initialQuery.month ? 'month' : initialQuery.quarter ? 'quarter' : initialQuery.year ? 'year' : 'month');
|
||||
const [year, setYear] = useState(initialQuery.year || (period === 'month' ? defaultMonth.year : period === 'quarter' ? defaultQuarter.year : new Date().getFullYear()));
|
||||
const [month, setMonth] = useState(initialQuery.month || defaultMonth.month);
|
||||
const [quarter, setQuarter] = useState(initialQuery.quarter || defaultQuarter.quarter);
|
||||
@@ -342,7 +344,6 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [recordQuerySnapshot, setRecordQuerySnapshot] = useState<QueryParams | null>(null);
|
||||
const [basisOpen, setBasisOpen] = useState(false);
|
||||
const trendAnchorTop = useRef<number | null>(null);
|
||||
const tableContent = useRef<HTMLDivElement>(null);
|
||||
const summaryExport = useRef<{ exportExcel: () => Promise<void> }>(null);
|
||||
const [summaryExporting, setSummaryExporting] = useState(false);
|
||||
const trendSection = useRef<HTMLElement>(null);
|
||||
@@ -353,7 +354,6 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
if (active && refreshSeen.current !== refreshKey) { refreshSeen.current = refreshKey; setQueryRevision(value => value + 1); }
|
||||
if (!active) { setRecordsOpen(false); setBasisOpen(false); }
|
||||
}, [active, refreshKey]);
|
||||
const tableHeight = useRef(525);
|
||||
|
||||
|
||||
|
||||
@@ -362,8 +362,11 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
api.options().then(result => {
|
||||
if (!alive) return;
|
||||
setOptions(result);
|
||||
const yearOptions = (result.years || []).map(value => Number(String(value).match(/\d{4}/)?.[0])).filter(Number.isFinite);
|
||||
if (yearOptions.length && !yearOptions.includes(year)) setYear(Math.max(...yearOptions));
|
||||
if (automaticPeriod.current) {
|
||||
const available = defaultQueryMonth(result);
|
||||
setYear(available.year); setMonth(available.month);
|
||||
automaticPeriod.current = false;
|
||||
}
|
||||
setOptionsError('');
|
||||
}).catch(errorValue => {
|
||||
if (onUnauthorized(errorValue)) return;
|
||||
@@ -413,10 +416,6 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const queryPending = !currentMetricsData && !currentMetricsError;
|
||||
const queryBusy = loading || queryPending;
|
||||
const metricKeyRef = useRef(metricKey);
|
||||
useLayoutEffect(() => {
|
||||
// CSS min-height uses layout pixels; DOM rectangles include workspace zoom.
|
||||
if (currentMetricsData && tableContent.current) tableHeight.current = tableContent.current.offsetHeight;
|
||||
}, [currentMetricsData, fullFields, drilledProduct]);
|
||||
metricKeyRef.current = metricKey;
|
||||
const useSummaryTrend = period === 'year' && !trendObject && trendGranularity === 'month';
|
||||
const trendParams = useMemo<QueryParams>(() => {
|
||||
@@ -446,6 +445,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}, [queryKey, active]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optionsLoading) return;
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
@@ -467,7 +467,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
setErrorKey(metricKey);
|
||||
}).finally(() => { if (!controller.signal.aborted) setLoading(false); });
|
||||
return () => controller.abort();
|
||||
}, [metricKey, queryRevision, onUnauthorized]);
|
||||
}, [metricKey, queryRevision, onUnauthorized, optionsLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!trendObject || defectQueryKey === queryKey) {
|
||||
@@ -491,6 +491,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}, [trendObject, defectQueryKey, queryKey, queryRevision, onUnauthorized]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optionsLoading) return;
|
||||
if (useSummaryTrend) {
|
||||
setTrendLoading(false);
|
||||
return;
|
||||
@@ -506,7 +507,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
if (!controller.signal.aborted && !onUnauthorized(errorValue)) message.error(`趋势加载失败:${chooseError(errorValue)}`);
|
||||
}).finally(() => { if (!controller.signal.aborted) setTrendLoading(false); });
|
||||
return () => controller.abort();
|
||||
}, [trendKey, useSummaryTrend, queryRevision, onUnauthorized, message]);
|
||||
}, [trendKey, useSummaryTrend, queryRevision, onUnauthorized, message, optionsLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -568,6 +569,21 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
return orderedRows.filter(row => [row.label, row.department, row.group, row.product, row.projectGroup].filter(Boolean).join(' ').toLocaleLowerCase().includes(term));
|
||||
}, [page, period, currentMetricsData, appliedSearch, year, view, department, allowedGroupSet]);
|
||||
|
||||
const tableReady = drilledProduct ? trendDataKey === trendKey && !trendLoading : !!currentMetricsData;
|
||||
const retainedTable = useRetainedResult(tableReady ? {
|
||||
rows: drilledProduct ? drilledTrendData : visibleRows,
|
||||
view: drilledProduct ? 'overall' as const : view,
|
||||
layoutView: drilledProduct ? 'product' as const : view,
|
||||
period: drilledProduct ? 'year' as const : period,
|
||||
year, month, quarter, drilledProduct,
|
||||
} : null);
|
||||
const tableRows = retainedTable?.rows || [];
|
||||
const tablePeriod = retainedTable?.period || period;
|
||||
const tableView = retainedTable?.view || view;
|
||||
const tableMonth = retainedTable?.month || month;
|
||||
const tableQuarter = retainedTable?.quarter || quarter;
|
||||
const tableProduct = retainedTable?.drilledProduct || '';
|
||||
|
||||
const captureTrendAnchor = useCallback(() => {
|
||||
trendAnchorTop.current = trendSection.current?.getBoundingClientRect().top ?? null;
|
||||
// Keep enough document height while the downstream charts are replaced by
|
||||
@@ -575,6 +591,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
defectsHeight.current = defectsSection.current?.offsetHeight ?? 0;
|
||||
}, []);
|
||||
const selectTrendPeriod = useCallback((value: number | string) => {
|
||||
automaticPeriod.current = false;
|
||||
const raw = String(value);
|
||||
const quarterMatch = raw.match(/^(\d{4})-Q([1-4])$/);
|
||||
const yearMonth = raw.match(/^(\d{4})-(\d{1,2})$/);
|
||||
@@ -662,7 +679,8 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}, [summaryMetricsData, drilledProduct, defectQueryParams, queryParams, view, message]);
|
||||
const summaryMetricsError = drilledProduct ? trendObjectMetricsError : currentMetricsError;
|
||||
const summaryBusy = drilledProduct ? trendObjectMetricsLoading || !summaryMetricsData && !summaryMetricsError : queryBusy;
|
||||
const rowForSummary = summaryMetricsData?.summary;
|
||||
const displayedSummaryData = useRetainedResult(summaryMetricsData);
|
||||
const rowForSummary = displayedSummaryData?.summary;
|
||||
const rawFormulaDescriptions = summaryMetricsData?.context.metricFormulaDescriptions;
|
||||
const formulaDescriptions = rawFormulaDescriptions && typeof rawFormulaDescriptions === 'object' && !Array.isArray(rawFormulaDescriptions) ? rawFormulaDescriptions as Record<string, unknown> : {};
|
||||
const compositeFormula = formulaDescriptions[rateBasis === 'original' ? 'compositeRate' : 'compositeRateWithoutHeadquartersScrap'];
|
||||
@@ -719,11 +737,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
value={period}
|
||||
options={[{ label: '年度', value: 'year' }, { label: '季度', value: 'quarter' }, { label: '月度', value: 'month' }]}
|
||||
onChange={value => {
|
||||
automaticPeriod.current = false;
|
||||
const nextPeriod = value as PeriodKind;
|
||||
setPeriod(nextPeriod);
|
||||
setTrendGranularity(nextPeriod === 'quarter' ? 'quarter' : 'month');
|
||||
if (nextPeriod === 'month') {
|
||||
const previous = previousCompleteMonth();
|
||||
const previous = defaultQueryMonth(options);
|
||||
setYear(previous.year);
|
||||
setMonth(previous.month);
|
||||
} else if (nextPeriod === 'quarter') {
|
||||
@@ -734,9 +753,9 @@ 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={setYear} 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={setMonth} /></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={setQuarter} /></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>}
|
||||
{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)}
|
||||
@@ -744,7 +763,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
<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">
|
||||
<span className={`query-status ${queryBusy || summaryBusy ? 'busy' : currentMetricsError || summaryMetricsError ? 'failed' : ''}`}><i />{queryBusy || summaryBusy ? '正在查询' : currentMetricsError || summaryMetricsError ? '查询失败' : '查询完成'}</span>
|
||||
<Button type="default" onClick={() => { const previous = previousCompleteMonth(); const previousQuarter = previousCompleteQuarter(); 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>
|
||||
<Button type="default" onClick={() => { automaticPeriod.current = false; const previous = defaultQueryMonth(options); const previousQuarter = previousCompleteQuarter(); setDepartment([]); setGroup([]); setProduct([]); setProjectGroup([]); setExtraFilters({}); setSearch(''); setAppliedSearch(''); setTrendObject(''); setYear(previous.year); setMonth(previous.month); setQuarter(previousQuarter.quarter); setPeriod('month'); setTrendGranularity('month'); }}>重置</Button>
|
||||
</div>
|
||||
{organizationSummary.length > 0 && <div className="organization-breadcrumb" aria-label="当前组织路径">
|
||||
<span>组织路径</span><Button type="link" onClick={() => { setDepartment([]); setGroup([]); setProduct([]); }}>全部组织</Button>
|
||||
@@ -754,12 +773,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
|
||||
{currentMetricsError && <Alert showIcon type="error" message="质量指标查询失败" 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 ${!summaryMetricsData ? 'query-awaiting-data' : ''}`} aria-label="质量指标" aria-busy={summaryBusy} inert={!summaryMetricsData}>
|
||||
<section className={`metric-strip ${!displayedSummaryData ? 'query-awaiting-data' : ''}`} 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={!summaryMetricsData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'black') ? hasValidRateDenominator(rowForSummary, 'black') ? `合格重量 ${numberText(rowForSummary?.black?.qualifiedWeight)} kg` : '按当前启用规则及空值策略计算' : '缺少黑片来源'} stage="black" onClick={() => openRecords(null, 'black')} />
|
||||
<MetricCard label="亮片合格率" value={rateText(visibleStageRate(rowForSummary, 'bright', rateBasis))} note={!summaryMetricsData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'bright') ? hasValidRateDenominator(rowForSummary, 'bright') ? `合格重量 ${numberText(rowForSummary?.bright?.qualifiedWeight)} kg` : '按当前启用规则及空值策略计算' : '缺少亮片来源'} stage="bright" onClick={() => openRecords(null, 'bright')} />
|
||||
<MetricCard label="报废总重" value={rowForSummary && (hasStageRows(rowForSummary, 'black') || hasStageRows(rowForSummary, 'bright')) ? `${numberText(queryTotalScrapWeight(rowForSummary, rateBasis))} kg` : '—'} note={!summaryMetricsData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'black') || hasStageRows(rowForSummary, 'bright') ? `黑片 ${numberText(rowForSummary?.black?.scrapWeight)} kg · 亮片 ${numberText(queryScrapWeight(rowForSummary?.bright, 'bright', rateBasis))} kg` : '缺少阶段来源'} onClick={() => openRecords(null, 'black')} />
|
||||
<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')} />
|
||||
<MetricCard label="亮片合格率" value={rateText(visibleStageRate(rowForSummary, 'bright', rateBasis))} note={!displayedSummaryData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'bright') ? hasValidRateDenominator(rowForSummary, 'bright') ? `合格重量 ${numberText(rowForSummary?.bright?.qualifiedWeight)} kg` : '按当前启用规则及空值策略计算' : '缺少亮片来源'} stage="bright" onClick={() => openRecords(null, 'bright')} />
|
||||
<MetricCard label="报废总重" value={rowForSummary && (hasStageRows(rowForSummary, 'black') || hasStageRows(rowForSummary, 'bright')) ? `${numberText(queryTotalScrapWeight(rowForSummary, rateBasis))} kg` : '—'} note={!displayedSummaryData ? (summaryBusy ? '正在更新…' : '指标暂不可用') : hasStageRows(rowForSummary, 'black') || hasStageRows(rowForSummary, 'bright') ? `黑片 ${numberText(rowForSummary?.black?.scrapWeight)} kg · 亮片 ${numberText(queryScrapWeight(rowForSummary?.bright, 'bright', rateBasis))} kg` : '缺少阶段来源'} onClick={() => openRecords(null, 'black')} />
|
||||
</section>
|
||||
|
||||
{['department', 'group', 'product'].includes(page) && <>
|
||||
@@ -767,77 +786,6 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
</>}
|
||||
|
||||
<>
|
||||
<section className="panel section-panel table-panel">
|
||||
<div className="section-heading-row">
|
||||
<SectionHeading title={drilledProduct ? '产品月度质量数据' : page === 'overall' ? `${period === 'year' ? '年度月度' : period === 'quarter' ? '季度' : '月度'}汇总` : `${scopeName}质量汇总`} subtitle={drilledProduct ? `${year} 年 · ${drilledProduct} · 重量 / kg 合格率 / %` : '重量 / kg 合格率 / %'} />
|
||||
<div className="table-tools">
|
||||
<Input allowClear={!drilledProduct} disabled={Boolean(drilledProduct)} maxLength={view === 'product' ? 256 : undefined} prefix={<SearchOutlined />} placeholder={view === 'product' ? '输入关键词或完整产品名称' : `搜索${view === 'group' ? '业务分组' : '汇总对象'}`} value={drilledProduct || search} onChange={event => setSearch(event.target.value)} aria-label={view === 'product' ? '搜索产品名称并同步筛选指标和趋势' : '搜索汇总对象'} />
|
||||
<Button type="primary" disabled={Boolean(drilledProduct)} onClick={() => applySearch()} aria-label="开始搜索">搜索</Button>
|
||||
<Segmented value={fullFields ? 'full' : 'key'} options={[{ label: '关键指标', value: 'key' }, { label: '完整字段', value: 'full' }]} onChange={value => setFullFields(value === 'full')} aria-label="字段显示" />
|
||||
<Segmented value={defectDisplay} options={[{label:'不良重量',value:'weight'},{label:'不良率',value:'rate'}]} onChange={value=>setDefectDisplay(value as typeof defectDisplay)} aria-label="不良显示方式" />
|
||||
{!drilledProduct && (view === 'group' || view === 'product' && (group.length > 0 || department.length > 0)) && <Button onClick={() => { setSearch(''); setAppliedSearch(''); setTrendObject(''); if (view === 'product') { setProduct([]); setGroup([]); setViewOverride('group'); } else { setGroup([]); setDepartment([]); setViewOverride('department'); } }}>{view === 'product' ? '返回业务分组' : '返回产业部'}</Button>}
|
||||
{drilledProduct && <Button onClick={() => { setDrilledProduct(''); setTrendObject(''); setTrendMode('production'); }}>返回产品汇总</Button>}
|
||||
<Button icon={<DownloadOutlined />} aria-label="Excel导出" loading={summaryExporting} disabled={queryBusy || summaryBusy || !summaryMetricsData || Boolean(drilledProduct && trendLoading) || !(drilledProduct ? drilledTrendData : visibleRows).length} onClick={async () => {
|
||||
setSummaryExporting(true);
|
||||
try { await summaryExport.current?.exportExcel(); }
|
||||
catch (error) { message.error(`导出失败:${chooseError(error)}`); }
|
||||
finally { setSummaryExporting(false); }
|
||||
}}>Excel导出</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mobile-scroll-hint">横向滑动查看完整指标</div>
|
||||
<Spin spinning={queryBusy}><div ref={tableContent} className="query-table-content" style={{ minHeight: queryBusy ? tableHeight.current : undefined }} aria-busy={queryBusy} inert={!currentMetricsData}>
|
||||
{drilledProduct ? (
|
||||
<MetricTable
|
||||
ref={summaryExport}
|
||||
exportFilename={`${drilledProduct || scopeName}质量汇总-${year}${drilledProduct || period === 'year' ? '' : period === 'month' ? `-${String(month).padStart(2, '0')}` : `-Q${quarter}`}-${fullFields ? '完整字段' : '关键指标'}`}
|
||||
rows={drilledTrendData}
|
||||
view="overall"
|
||||
layoutView="product"
|
||||
pageSizeOverride={12}
|
||||
period="year"
|
||||
month={month}
|
||||
quarter={quarter}
|
||||
fullFields={fullFields}
|
||||
defectDisplay={defectDisplay}
|
||||
rateBasis={rateBasis}
|
||||
onDetail={openRecords}
|
||||
onBasis={() => setBasisOpen(true)}
|
||||
onDrilldown={() => undefined}
|
||||
/>
|
||||
) : (
|
||||
<MetricTable
|
||||
ref={summaryExport}
|
||||
exportFilename={`${drilledProduct || scopeName}质量汇总-${year}${drilledProduct || period === 'year' ? '' : period === 'month' ? `-${String(month).padStart(2, '0')}` : `-Q${quarter}`}-${fullFields ? '完整字段' : '关键指标'}`}
|
||||
rows={visibleRows}
|
||||
view={view}
|
||||
period={period}
|
||||
month={month}
|
||||
quarter={quarter}
|
||||
fullFields={fullFields}
|
||||
defectDisplay={defectDisplay}
|
||||
rateBasis={rateBasis}
|
||||
onDetail={openRecords}
|
||||
onBasis={() => setBasisOpen(true)}
|
||||
emptyText={queryBusy ? '正在更新数据…' : currentMetricsError ? '查询失败,暂无可展示结果' : '当前条件下暂无数据'}
|
||||
onDrilldown={row => {
|
||||
if (view === 'overall') setViewOverride('department');
|
||||
else if (view === 'department' && row.department) { setSearch(''); setAppliedSearch(''); setTrendObject(''); setGroup([]); setProduct([]); setDepartment([row.department]); setViewOverride('group'); }
|
||||
else if (view === 'group' && row.group) { setSearch(''); setAppliedSearch(''); setTrendObject(''); setProduct([]); setGroup([row.group]); setViewOverride('product'); }
|
||||
else if (view === 'product') {
|
||||
const selectedProduct = row.product || row.label;
|
||||
if (!selectedProduct) return;
|
||||
setDrilledProduct(selectedProduct);
|
||||
setTrendObject(selectedProduct);
|
||||
setTrendGranularity('month');
|
||||
setTrendMode('production');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div></Spin>
|
||||
</section>
|
||||
|
||||
<div className="analysis-stack">
|
||||
<section className="panel section-panel trend-panel" ref={trendSection} id={active ? 'monthly-trend' : undefined}>
|
||||
<div className="section-heading-row trend-heading-row">
|
||||
@@ -860,6 +808,62 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
<div className="chart-footnote"><span style={{ marginLeft: 'auto' }}>点击期间筛选,再次点击可取消</span></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section className="panel section-panel table-panel">
|
||||
<div className="section-heading-row">
|
||||
<SectionHeading title={tableProduct ? '产品月度质量数据' : page === 'overall' ? `${tablePeriod === 'year' ? '年度月度' : tablePeriod === 'quarter' ? '季度' : '月度'}汇总` : `${scopeName}质量汇总`} subtitle={tableProduct ? `${retainedTable?.year || year} 年 · ${tableProduct} · 重量 / kg 合格率 / %` : '重量 / kg 合格率 / %'} />
|
||||
<div className="table-tools">
|
||||
{(queryBusy || !tableReady) && <span className="defect-refresh-indicator"><Spin size="small" />正在更新</span>}
|
||||
<Input allowClear={!drilledProduct} disabled={Boolean(drilledProduct)} maxLength={view === 'product' ? 256 : undefined} prefix={<SearchOutlined />} placeholder={view === 'product' ? '输入关键词或完整产品名称' : `搜索${view === 'group' ? '业务分组' : '汇总对象'}`} value={drilledProduct || search} onChange={event => setSearch(event.target.value)} aria-label={view === 'product' ? '搜索产品名称并同步筛选指标和趋势' : '搜索汇总对象'} />
|
||||
<Button type="primary" disabled={Boolean(drilledProduct)} onClick={() => applySearch()} aria-label="开始搜索">搜索</Button>
|
||||
<Segmented value={fullFields ? 'full' : 'key'} options={[{ label: '关键指标', value: 'key' }, { label: '完整字段', value: 'full' }]} onChange={value => setFullFields(value === 'full')} aria-label="字段显示" />
|
||||
<Segmented value={defectDisplay} options={[{label:'不良重量',value:'weight'},{label:'不良率',value:'rate'}]} onChange={value=>setDefectDisplay(value as typeof defectDisplay)} aria-label="不良显示方式" />
|
||||
{!drilledProduct && (view === 'group' || view === 'product' && (group.length > 0 || department.length > 0)) && <Button onClick={() => { setSearch(''); setAppliedSearch(''); setTrendObject(''); if (view === 'product') { setProduct([]); setGroup([]); setViewOverride('group'); } else { setGroup([]); setDepartment([]); setViewOverride('department'); } }}>{view === 'product' ? '返回业务分组' : '返回产业部'}</Button>}
|
||||
{drilledProduct && <Button onClick={() => { setDrilledProduct(''); setTrendObject(''); setTrendMode('production'); }}>返回产品汇总</Button>}
|
||||
<Button icon={<DownloadOutlined />} aria-label="Excel导出" loading={summaryExporting} disabled={queryBusy || summaryBusy || !summaryMetricsData || Boolean(drilledProduct && trendLoading) || !(drilledProduct ? drilledTrendData : visibleRows).length} onClick={async () => {
|
||||
setSummaryExporting(true);
|
||||
try { await summaryExport.current?.exportExcel(); }
|
||||
catch (error) { message.error(`导出失败:${chooseError(error)}`); }
|
||||
finally { setSummaryExporting(false); }
|
||||
}}>Excel导出</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mobile-scroll-hint">横向滑动查看完整指标</div>
|
||||
<SmoothTableFrame busy={queryBusy || !tableReady} blocked={queryBusy || summaryBusy || !tableReady}>
|
||||
<MetricTable
|
||||
ref={summaryExport}
|
||||
exportFilename={`${drilledProduct || scopeName}质量汇总-${year}${drilledProduct || period === 'year' ? '' : period === 'month' ? `-${String(month).padStart(2, '0')}` : `-Q${quarter}`}-${fullFields ? '完整字段' : '关键指标'}`}
|
||||
rows={tableRows}
|
||||
view={tableView}
|
||||
layoutView={retainedTable?.layoutView || view}
|
||||
pageSizeOverride={tableProduct ? 12 : undefined}
|
||||
period={tablePeriod}
|
||||
month={tableMonth}
|
||||
quarter={tableQuarter}
|
||||
fullFields={fullFields}
|
||||
defectDisplay={defectDisplay}
|
||||
rateBasis={rateBasis}
|
||||
onDetail={openRecords}
|
||||
onBasis={() => setBasisOpen(true)}
|
||||
emptyText={queryBusy ? '正在更新数据…' : currentMetricsError ? '查询失败,暂无可展示结果' : '当前条件下暂无数据'}
|
||||
onDrilldown={row => {
|
||||
if (drilledProduct) return;
|
||||
if (view === 'overall') setViewOverride('department');
|
||||
else if (view === 'department' && row.department) { setSearch(''); setAppliedSearch(''); setTrendObject(''); setGroup([]); setProduct([]); setDepartment([row.department]); setViewOverride('group'); }
|
||||
else if (view === 'group' && row.group) { setSearch(''); setAppliedSearch(''); setTrendObject(''); setProduct([]); setGroup([row.group]); setViewOverride('product'); }
|
||||
else if (view === 'product') {
|
||||
const selectedProduct = row.product || row.label;
|
||||
if (!selectedProduct) return;
|
||||
setDrilledProduct(selectedProduct);
|
||||
setTrendObject(selectedProduct);
|
||||
setTrendGranularity('month');
|
||||
setTrendMode('production');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</SmoothTableFrame>
|
||||
</section>
|
||||
|
||||
<section className="panel section-panel defects-panel" ref={defectsSection} aria-busy={defectsRefreshing} style={{ minHeight: queryBusy && trendAnchorTop.current != null ? defectsHeight.current : undefined }}>
|
||||
<div className="section-heading-row">
|
||||
<SectionHeading title="不良具体构成" />
|
||||
@@ -917,10 +921,11 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}
|
||||
|
||||
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)$/);
|
||||
const displayedValue = useAnimatedMetricText(value);
|
||||
const parts = displayedValue.match(/^(.*?)(%| kg)$/);
|
||||
return <button className={`metric-card ${primary ? 'primary' : ''} ${stage || ''}`} onClick={onClick}>
|
||||
<span className="metric-label">{stage && <i className={`stage-dot ${stage}`} />}{label}</span>
|
||||
<strong className="metric-value">{parts ? <>{parts[1]}<span className="metric-unit">{parts[2]}</span></> : value}</strong>
|
||||
<strong className="metric-value">{parts ? <>{parts[1]}<span className="metric-unit">{parts[2]}</span></> : displayedValue}</strong>
|
||||
{note && <small>{note}</small>}
|
||||
</button>;
|
||||
}
|
||||
@@ -1133,7 +1138,7 @@ export function MetricTable({
|
||||
align: 'center' as const,
|
||||
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) => <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}>{field === 'rate' ? rateText(visibleStageRate(row, stage)) : defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight') ? rateText(defectWeightRate(stageValue(row, stage, field, rateBasis),stageValue(row, stage, 'totalWeight'))) : numberText(stageValue(row, stage, field, rateBasis))}</Button>,
|
||||
render: (_: unknown, row: MetricRow) => <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}><AnimatedMetricText value={field === 'rate' ? rateText(visibleStageRate(row, stage)) : defectDisplay === 'rate' && (field === 'scrapWeight' || field === 'headquartersScrapWeight') ? rateText(defectWeightRate(stageValue(row, stage, field, rateBasis),stageValue(row, stage, 'totalWeight'))) : numberText(stageValue(row, stage, field, rateBasis))} /></Button>,
|
||||
});
|
||||
const defectColumns = (stage: Stage, names: string[]) => names.map(name => ({
|
||||
title: `${compact ? stage === 'black' ? '黑片' : '亮片' : ''}${defectDisplay === 'rate' ? defectRateLabel(name) : name}`,
|
||||
@@ -1143,7 +1148,7 @@ export function MetricTable({
|
||||
width: fullFields ? 100 : 130,
|
||||
render: (_: unknown, row: MetricRow) => {
|
||||
const value = defectList(row, stage).find(item => item.name === name);
|
||||
return <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}>{defectDisplay === 'rate' ? rateText(defectWeightRate(value?.weight,stageValue(row,stage,'totalWeight'))) : numberText(value?.weight ?? null)}</Button>;
|
||||
return <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}><AnimatedMetricText value={defectDisplay === 'rate' ? rateText(defectWeightRate(value?.weight,stageValue(row,stage,'totalWeight'))) : numberText(value?.weight ?? null)} /></Button>;
|
||||
},
|
||||
}));
|
||||
const brightDetailColumns: ColumnsType<MetricRow> = defectColumns('bright', brightDefects);
|
||||
@@ -1155,8 +1160,8 @@ export function MetricTable({
|
||||
const allColumns: ColumnsType<MetricRow> = [
|
||||
{ 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) => <span className="object-cell">{view === 'department' || view === 'group' || view === 'product' ? <Button type="link" className="object-drilldown" style={{ userSelect: 'text', WebkitUserSelect: 'text' }} onClick={() => { if (window.getSelection()?.isCollapsed !== false) onDrilldown(row); }}>{title(row)} <span>›</span></Button> : <strong>{title(row)}</strong>}{view === 'group' && row.department && <small>{row.department}</small>}</span> },
|
||||
{ key: 'stage-black', title: <span className="stage-heading black"><i />黑片</span>, children: [numeric('总重量', 'black', 'totalWeight'), numeric('合格重量', 'black', 'qualifiedWeight'), numeric('报废重量', 'black', 'scrapWeight'), ...defectColumns('black', blackDefects), numeric('合格率', 'black', 'rate')] },
|
||||
{ key: 'stage-bright', title: <span className="stage-heading bright"><i />亮片</span>, children: [numeric('总重量', 'bright', 'totalWeight'), numeric('合格重量', 'bright', 'qualifiedWeight'), numeric('报废重量', 'bright', 'scrapWeight'), ...brightDetailColumns, { ...numeric('合格率', 'bright', 'rate'), render: (_: unknown, row: MetricRow) => <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}>{rateText(visibleStageRate(row, 'bright', rateBasis))}</Button> }] },
|
||||
{ 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) => <button className="combined-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}>{rateText(visibleCompositeRate(row, rateBasis))}</button> },
|
||||
{ key: 'stage-bright', title: <span className="stage-heading bright"><i />亮片</span>, children: [numeric('总重量', 'bright', 'totalWeight'), numeric('合格重量', 'bright', 'qualifiedWeight'), numeric('报废重量', 'bright', 'scrapWeight'), ...brightDetailColumns, { ...numeric('合格率', 'bright', 'rate'), render: (_: unknown, row: MetricRow) => <Button type="link" className="table-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}><AnimatedMetricText value={rateText(visibleStageRate(row, 'bright', rateBasis))} /></Button> }] },
|
||||
{ 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) => <button className="combined-value" tabIndex={-1} style={{ userSelect: 'text', WebkitUserSelect: 'text' }}><AnimatedMetricText value={rateText(visibleCompositeRate(row, rateBasis))} /></button> },
|
||||
{ title: '操作', key: 'actions', fixed: compact ? undefined : 'right', width: 96, align: 'center', render: (_: unknown, row) => (row as TrendMetricRow).noData ? <span>—</span> : <Button type="link" onClick={() => openRow(row, onlyStage || 'black')}>来源明细</Button> },
|
||||
];
|
||||
const columns = onlyStage ? allColumns.filter(column => !['compositeRate', `stage-${onlyStage === 'black' ? 'bright' : 'black'}`].includes(String(column.key))) : allColumns;
|
||||
|
||||
Reference in New Issue
Block a user