同步:补齐已发布的查询面板与不良构成源码
This commit is contained in:
+61
-92
@@ -47,6 +47,9 @@ import { readableSelectPopup } from './readableSelectPopup';
|
||||
import { isInternalDataField, readableMetricFormula } from './publicDataDisplay';
|
||||
import { defaultQueryMonth, previousCompleteMonth, previousCompleteQuarter } from './periodDefaults';
|
||||
import { defectWeightRate } from './trendMetrics';
|
||||
import DefectComposition from './DefectComposition';
|
||||
import { QueryTrendPanel, QueryTablePanel } from './QueryPanels';
|
||||
import { selectTrendPeriod as nextTrendPeriod } from './trendPeriodSelection';
|
||||
import './query-motion.css';
|
||||
import { ExtraQueryFilters } from './ExtraQueryFilters';
|
||||
import { freezeSourceRecordsQuery } from './sourceRecordsContext';
|
||||
@@ -299,10 +302,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 automaticPeriod = useRef(page !== 'overall' && !initialQuery.year && !initialQuery.month && !initialQuery.quarter);
|
||||
const defaultMonth = previousCompleteMonth();
|
||||
const defaultQuarter = previousCompleteQuarter();
|
||||
const [period, setPeriod] = useState<PeriodKind>(initialQuery.month ? 'month' : initialQuery.quarter ? 'quarter' : initialQuery.year ? 'year' : 'month');
|
||||
const [period, setPeriod] = useState<PeriodKind>(initialQuery.month ? 'month' : initialQuery.quarter ? 'quarter' : initialQuery.year || page === 'overall' ? '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);
|
||||
@@ -599,35 +602,9 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}, []);
|
||||
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})$/);
|
||||
const yearMatch = raw.match(/^(\d{4})$/);
|
||||
if (quarterMatch) {
|
||||
if (period === 'quarter' && year === Number(quarterMatch[1]) && quarter === Number(quarterMatch[2])) {
|
||||
captureTrendAnchor(); setPeriod('year'); return;
|
||||
}
|
||||
if (period !== 'quarter' || year !== Number(quarterMatch[1]) || quarter !== Number(quarterMatch[2])) captureTrendAnchor();
|
||||
setYear(Number(quarterMatch[1])); setQuarter(Number(quarterMatch[2])); setPeriod('quarter');
|
||||
} else if (yearMonth) {
|
||||
if (period === 'month' && year === Number(yearMonth[1]) && month === Number(yearMonth[2])) {
|
||||
captureTrendAnchor(); setPeriod('year'); return;
|
||||
}
|
||||
if (period !== 'month' || year !== Number(yearMonth[1]) || month !== Number(yearMonth[2])) captureTrendAnchor();
|
||||
setYear(Number(yearMonth[1])); setMonth(Number(yearMonth[2])); setPeriod('month');
|
||||
} else if (yearMatch) {
|
||||
if (period !== 'year' || year !== Number(yearMatch[1])) captureTrendAnchor();
|
||||
setYear(Number(yearMatch[1])); setPeriod('year');
|
||||
} else {
|
||||
const selected = monthNumber(value);
|
||||
if (selected) {
|
||||
if (period === 'month' && month === selected) {
|
||||
captureTrendAnchor(); setPeriod('year'); return;
|
||||
}
|
||||
if (period !== 'month' || month !== selected) captureTrendAnchor();
|
||||
setPeriod('month'); setMonth(selected);
|
||||
}
|
||||
}
|
||||
const next = nextTrendPeriod(value, { period, year, month, quarter });
|
||||
if (next.period !== period || next.year !== year || next.month !== month || next.quarter !== quarter) captureTrendAnchor();
|
||||
setYear(next.year); setMonth(next.month); setQuarter(next.quarter); setPeriod(next.period);
|
||||
}, [period, year, month, quarter, captureTrendAnchor]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -770,7 +747,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={() => { 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>
|
||||
<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>
|
||||
{organizationSummary.length > 0 && <div className="organization-breadcrumb" aria-label="当前组织路径">
|
||||
<span>组织路径</span><Button type="link" onClick={() => { setDepartment([]); setGroup([]); setProduct([]); }}>全部组织</Button>
|
||||
@@ -794,18 +771,11 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
|
||||
<>
|
||||
<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">
|
||||
<SectionHeading title={`${trendGranularity === 'month' ? '月度' : trendGranularity === 'quarter' ? '季度' : '年度'}变化趋势`} />
|
||||
<Segmented value={trendMode} options={[{ label: '合格率与产量', value: 'production' }, { label: '不良率', value: 'defects' }, { label: `${trendGranularity === 'quarter' ? '季度' : trendGranularity === 'year' ? '年度' : '月度'}数据`, value: 'data' }]} onChange={value => setTrendMode(value as typeof trendMode)} aria-label="趋势视图" />
|
||||
</div>
|
||||
<div className="trend-controls">
|
||||
{trendMode==='data'&&<Segmented value={defectDisplay} options={[{label:'不良重量',value:'weight'},{label:'不良率',value:'rate'}]} onChange={value=>setDefectDisplay(value as typeof defectDisplay)} aria-label="趋势不良显示方式"/>}
|
||||
<label className="query-field trend-granularity"><span>趋势粒度</span><Select {...readableSelectPopup} value={trendGranularity} options={[{ label: '按月', value: 'month' }, { label: '按季度', value: 'quarter' }, { label: '按年度', value: 'year' }]} onChange={value => setTrendGranularity(value)} aria-label="趋势粒度" /></label>
|
||||
<label className="query-field trend-object"><span>趋势对象</span><Select {...readableSelectPopup} allowClear placeholder={`当前${scopeName}筛选`} value={trendObject || undefined} options={trendOptions} onChange={setSynchronizedTrendObject} aria-label="趋势对象" />
|
||||
</label>
|
||||
{trendMode !== 'data' && <Segmented value={trendStage} options={[{ label: '亮片', value: 'bright' }, { label: '黑片', value: 'black' }]} onChange={value => setTrendStage(value as Stage)} aria-label="趋势阶段" />}
|
||||
</div>
|
||||
<QueryTrendPanel panelRef={trendSection} id={active ? 'monthly-trend' : undefined}
|
||||
mode={trendMode} onMode={setTrendMode} granularity={trendGranularity} onGranularity={setTrendGranularity}
|
||||
defectDisplay={defectDisplay} onDefectDisplay={setDefectDisplay} object={trendObject} onObject={setSynchronizedTrendObject}
|
||||
objects={trendOptions} scopeName={scopeName}
|
||||
stageSwitch={<Segmented value={trendStage} options={[{ label: '亮片', value: 'bright' }, { label: '黑片', value: 'black' }]} onChange={value => setTrendStage(value as Stage)} aria-label="趋势阶段" />}>
|
||||
{currentTrendError && <Alert type="warning" showIcon message="趋势读取失败" description={currentTrendError} action={<Button onClick={() => setQueryRevision(value => value + 1)}>重试</Button>} />}
|
||||
<div className="trend-chart-shell" aria-busy={trendRefreshing} inert={trendRefreshing || trendDataKey !== trendKey}>
|
||||
{trendMode === 'data'
|
||||
@@ -813,29 +783,22 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
: <TrendChart rows={renderedTrendData} mode={trendMode} stage={trendStage} rateBasis={rateBasis} targetRate={renderedTrendTarget} selectedPeriod={selectedTrendPeriod} onMonth={selectTrendPeriod} />}
|
||||
{trendRefreshing && <span className="trend-refresh-indicator"><Spin size="small" />正在更新趋势</span>}
|
||||
</div>
|
||||
</section>
|
||||
</QueryTrendPanel>
|
||||
|
||||
|
||||
<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 className="query-return-button" icon={<ArrowLeftOutlined />} onClick={() => { setSearch(''); setAppliedSearch(''); setTrendObject(''); if (view === 'product') { setProduct([]); setGroup([]); setViewOverride('group'); } else { setGroup([]); setDepartment([]); setViewOverride('department'); } }}>返回上一级</Button>}
|
||||
{drilledProduct && <Button className="query-return-button" icon={<ArrowLeftOutlined />} onClick={() => { setDrilledProduct(''); setTrendObject(''); setTrendMode('production'); }}>返回上一级</Button>}
|
||||
<Button type="primary" className="query-export-button" icon={<DownloadOutlined />} aria-label="Excel导出" loading={summaryExporting} disabled={queryBusy || summaryBusy || !summaryMetricsData || Boolean(drilledProduct && trendLoading) || !(drilledProduct ? drilledTrendData : visibleRows).length} onClick={async () => {
|
||||
<QueryTablePanel
|
||||
heading={<SectionHeading title={tableProduct ? '产品月度质量数据' : page === 'overall' ? `${tablePeriod === 'year' ? '年度月度' : tablePeriod === 'quarter' ? '季度' : '月度'}汇总` : `${scopeName}质量汇总`} subtitle={tableProduct ? `${retainedTable?.year || year} 年 · ${tableProduct} · 重量 / kg 合格率 / %` : '重量 / kg 合格率 / %'} />} busy={queryBusy || !tableReady}
|
||||
search={drilledProduct || search} onSearchChange={setSearch} onSearch={() => applySearch()} productView={view === 'product'} searchPlaceholder={view === 'group' ? '搜索业务分组' : undefined} searchDisabled={Boolean(drilledProduct)}
|
||||
fullFields={fullFields} onFullFields={setFullFields} defectDisplay={defectDisplay} onDefectDisplay={setDefectDisplay}
|
||||
returnControls={<>{!drilledProduct && (view !== baseView || view === 'group' || view === 'product' && (group.length > 0 || department.length > 0)) && <Button className="query-return-button" icon={<ArrowLeftOutlined />} onClick={() => { setSearch(''); setAppliedSearch(''); setTrendObject(''); if (view === 'product') { setProduct([]); setGroup([]); setViewOverride('group'); } else if (view === 'group') { setGroup([]); setDepartment([]); setViewOverride('department'); } else { setViewOverride(); } }}>返回上一级</Button>}
|
||||
{drilledProduct && <Button className="query-return-button" icon={<ArrowLeftOutlined />} onClick={() => { setDrilledProduct(''); setTrendObject(''); setTrendMode('production'); }}>返回上一级</Button>}</>}
|
||||
exporting={summaryExporting} exportDisabled={queryBusy || summaryBusy || !summaryMetricsData || Boolean(drilledProduct && trendLoading) || !(drilledProduct ? drilledTrendData : visibleRows).length}
|
||||
onExport={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}
|
||||
@@ -869,7 +832,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}}
|
||||
/>
|
||||
</SmoothTableFrame>
|
||||
</section>
|
||||
</QueryTablePanel>
|
||||
|
||||
<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">
|
||||
@@ -937,23 +900,15 @@ export function MetricCard({ primary, label, value, note, stage, onClick }: { pr
|
||||
</button>;
|
||||
}
|
||||
|
||||
export function DefectBreakdown({ items, stage, totalWeight, maximum, onDetail }: { items: DefectMetric[]; stage: Stage; totalWeight?: number | null; maximum: number; onDetail: () => void }) {
|
||||
return <div className="defect-list">
|
||||
<div className="defect-header"><span>不良分类</span><span aria-hidden="true" /><span>重量 / kg</span><span>占比</span><span>废率</span></div>
|
||||
{items.map(item => <button className="defect-row" key={item.name} onClick={onDetail}>
|
||||
<span className="defect-name">{item.name}</span>
|
||||
<span className="defect-track"><i className={stage} style={{ width: `${maximum > 0 ? Math.max(0, (item.weight || 0) / maximum * 100) : 0}%` }} /></span>
|
||||
<span className="defect-weight">{numberText(item.weight)}</span>
|
||||
<span className="defect-rate">{rateText(item.rate)}</span>
|
||||
<span className="defect-rate">{rateText(defectWeightRate(item.weight, totalWeight))}</span>
|
||||
</button>)}
|
||||
</div>;
|
||||
export function DefectBreakdown({ items, stage, totalWeight, onDetail }: { items: DefectMetric[]; stage: Stage; totalWeight?: number | null; maximum: number; onDetail: () => void }) {
|
||||
return <DefectComposition items={items} stage={stage} totalWeight={totalWeight} onDetail={onDetail} />;
|
||||
}
|
||||
|
||||
|
||||
export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUnauthorized, onlyStage, refreshKey = 0, pending = false }: {
|
||||
releaseId?: string; query: QueryParams; externalScrapWeight?: number | null; onUnauthorized: (error: unknown) => boolean; onlyStage?: Stage; refreshKey?: number; pending?: boolean;
|
||||
}) {
|
||||
const { active } = usePageCache();
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
const chart = useRef<ReturnType<typeof echarts.init> | null>(null);
|
||||
const [responses, setResponses] = useState<{ black: FineDefectTopResponse; bright: FineDefectTopResponse; externalScrapWeight?: number | null } | null>(null);
|
||||
@@ -1005,13 +960,18 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna
|
||||
|
||||
useEffect(() => {
|
||||
const node = container.current;
|
||||
if (!node) return;
|
||||
const instance = echarts.init(node, undefined, { renderer: 'svg' });
|
||||
if (!node || !active) return;
|
||||
const instance = echarts.init(node, undefined, { renderer: 'svg', width: node.clientWidth, height: node.clientHeight });
|
||||
chart.current = instance;
|
||||
const observer = new ResizeObserver(() => instance.resize());
|
||||
const observer = new ResizeObserver(() => {
|
||||
const { clientWidth: width, clientHeight: height } = node;
|
||||
if (width > 0 && height > 0 && (width !== instance.getWidth() || height !== instance.getHeight())) {
|
||||
instance.resize({ width, height, animation: { duration: 0 } });
|
||||
}
|
||||
});
|
||||
observer.observe(node);
|
||||
return () => { observer.disconnect(); instance.dispose(); if (chart.current === instance) chart.current = null; };
|
||||
}, []);
|
||||
}, [active]);
|
||||
|
||||
const items = useMemo(() => {
|
||||
if (!responses) return [];
|
||||
@@ -1039,8 +999,8 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna
|
||||
const styles = getComputedStyle(container.current);
|
||||
const ink = styles.getPropertyValue('--ink').trim() || '#222222';
|
||||
const line = styles.getPropertyValue('--line').trim() || '#dfe5ef';
|
||||
const blue = styles.getPropertyValue('--blue').trim() || '#607ae1';
|
||||
const teal = styles.getPropertyValue('--teal').trim() || '#008f7d';
|
||||
const black = styles.getPropertyValue('--defect-black').trim() || '#718797';
|
||||
const bright = styles.getPropertyValue('--defect-bright').trim() || '#607AE1';
|
||||
const surface = styles.getPropertyValue('--surface').trim() || '#ffffff';
|
||||
let accumulated = 0;
|
||||
const cumulative = items.map(item => {
|
||||
@@ -1081,12 +1041,12 @@ export function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUna
|
||||
{ type: 'value', name: '累计占比', min: 0, max: 100, nameTextStyle: { color: ink, fontSize }, axisLabel: { color: ink, fontFamily: numericFamily, fontSize, formatter: '{value}%' }, splitLine: { show: false } },
|
||||
],
|
||||
series: [
|
||||
{ id: 'pareto-weight', name: '报废重量', type: 'bar', z: 1, barMaxWidth: 36, data: items.map(item => ({ id: item.key, name: item.label, value: item.weight, itemStyle: { color: item.kind === 'category' ? '#9aa4b2' : item.key.startsWith('black:') ? blue : teal } })) },
|
||||
{ id: 'pareto-weight', name: '报废重量', type: 'bar', z: 1, barMaxWidth: 36, itemStyle: { color: onlyStage === 'black' ? black : bright }, data: items.map(item => ({ id: item.key, name: item.label, value: item.weight, itemStyle: { color: item.kind === 'category' ? '#9aa4b2' : item.key.startsWith('black:') ? black : bright } })) },
|
||||
{ id: 'pareto-cumulative', name: '累计占比', type: 'line', z: 10, yAxisIndex: 1, symbol: 'circle', symbolSize: 5, lineStyle: { width: 2, color: '#d58c35' }, itemStyle: { color: '#d58c35', borderColor: surface, borderWidth: 1 }, data: cumulative.map((value, index) => ({ id: items[index].key, name: items[index].label, value })) },
|
||||
],
|
||||
};
|
||||
instance.setOption(option, { replaceMerge: ['series'], lazyUpdate: false });
|
||||
}, [items, totalWeight, themeRevision]);
|
||||
}, [items, totalWeight, themeRevision, active]);
|
||||
|
||||
return <section className="defect-pareto-section" aria-busy={loading || pending} aria-label={onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '综合报废重量柏拉图'}>
|
||||
<div className="defect-pareto-heading"><strong>{onlyStage ? `${onlyStage === 'black' ? '黑片' : '亮片'}报废重量柏拉图` : '黑片与亮片综合报废重量柏拉图'}</strong>{loading && <span className="defect-refresh-indicator"><Spin size="small" />正在更新</span>}</div>
|
||||
@@ -1219,6 +1179,7 @@ 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 chart = useRef<ReturnType<typeof echarts.init> | null>(null);
|
||||
const onMonthRef = useRef(onMonth);
|
||||
@@ -1267,10 +1228,12 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!container.current || !hasRows) return;
|
||||
const instance = echarts.init(container.current, undefined, { renderer: 'svg' });
|
||||
if (!container.current || !hasRows || !active) return;
|
||||
const instance = echarts.init(container.current, undefined, { renderer: 'svg', width: container.current.clientWidth, height: container.current.clientHeight });
|
||||
chart.current = instance;
|
||||
graphicIds.current.clear();
|
||||
selectionReady.current = false;
|
||||
setBarMasks([]);
|
||||
instance.on('click', params => {
|
||||
if (params.componentType !== 'series' && params.componentType !== 'xAxis') return;
|
||||
const currentRows = rowsRef.current;
|
||||
@@ -1285,8 +1248,9 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
const observer = new ResizeObserver(() => {
|
||||
if (!container.current) return;
|
||||
const { clientWidth, clientHeight } = container.current;
|
||||
if (clientWidth <= 0 || clientHeight <= 0) return;
|
||||
if (clientWidth !== instance.getWidth() || clientHeight !== instance.getHeight()) {
|
||||
instance.resize();
|
||||
instance.resize({ width: clientWidth, height: clientHeight, animation: { duration: 0 } });
|
||||
if (modeRef.current === 'production') {
|
||||
const barWidth = trendBarWidth(instance.getWidth(), rowsRef.current.length);
|
||||
instance.setOption({ series: [{ id: 'qualified-weight', barWidth }, { id: 'scrap-weight', barWidth }] });
|
||||
@@ -1296,7 +1260,7 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
});
|
||||
observer.observe(container.current);
|
||||
return () => { observer.disconnect(); instance.dispose(); chart.current = null; };
|
||||
}, [hasRows, refreshBarMasks]);
|
||||
}, [hasRows, refreshBarMasks, active]);
|
||||
|
||||
useEffect(() => {
|
||||
const instance = chart.current;
|
||||
@@ -1308,6 +1272,8 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
const bars = trendBarPalette(getWorkspaceTheme(document.documentElement.dataset.workspaceTheme).id);
|
||||
const barColor = bars.qualified;
|
||||
const teal = css.getPropertyValue('--teal').trim() || '#008f7d';
|
||||
const blackLine = css.getPropertyValue('--defect-black').trim() || '#718797';
|
||||
const brightLine = css.getPropertyValue('--defect-bright').trim() || blue;
|
||||
const line = css.getPropertyValue('--line').trim() || '#dfe5ef';
|
||||
const surface = css.getPropertyValue('--surface').trim() || '#ffffff';
|
||||
const labels = rows.map(row => row.periodLabel || String(row.month));
|
||||
@@ -1329,7 +1295,8 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
};
|
||||
const base: echarts.EChartsCoreOption = {
|
||||
animation: !window.matchMedia('(prefers-reduced-motion: reduce)').matches,
|
||||
animationDuration: 0,
|
||||
animationDuration: 520,
|
||||
animationEasing: 'cubicOut',
|
||||
animationDurationUpdate: 520,
|
||||
animationEasingUpdate: 'cubicOut',
|
||||
textStyle: { fontFamily, color: ink, fontSize },
|
||||
@@ -1346,6 +1313,7 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
const maxRate = rates.length ? Math.max(100, Math.ceil(Math.max(...rates) + 1)) : 100;
|
||||
const stageName = stage === 'black' ? '黑片' : '亮片';
|
||||
const barWidth = trendBarWidth(instance.getWidth(), rows.length);
|
||||
const ratePoints = { ...pointStyle, symbol: 'emptyCircle', symbolSize: 6 };
|
||||
const targetLine = targetRate == null ? {} : { markLine: {
|
||||
silent: true,
|
||||
symbol: 'none',
|
||||
@@ -1362,9 +1330,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: bars.hoverQualified } }, data: barData('qualifiedWeight') },
|
||||
{ id: 'scrap-weight', name: `${stageName}报废重量`, type: 'bar', z: 1, stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: bars.scrap }, emphasis: { itemStyle: { color: bars.hoverScrap } }, data: barData('scrapWeight') },
|
||||
{ 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: '亮片合格率', 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: 'composite-rate', name: '综合合格率', type: 'line', yAxisIndex: 1, ...ratePoints, ...targetLine, symbolSize: 7, emphasis: { ...pointStyle.emphasis, scale: 1.15 }, lineStyle: { width: 3.2, color: teal, cap: 'round', join: 'round' }, itemStyle: { color: teal, borderColor: teal, borderWidth: 2 }, data: rows.map(row => rateNumber(visibleCompositeRate(row, rateBasis))) },
|
||||
{ id: 'black-rate', name: '黑片合格率', type: 'line', yAxisIndex: 1, ...ratePoints, lineStyle: { width: 2.6, color: blackLine, cap: 'round', join: 'round' }, itemStyle: { color: blackLine, borderColor: blackLine, borderWidth: 2 }, data: rows.map(row => rateNumber(visibleStageRate(row, 'black'))) },
|
||||
{ id: 'bright-rate', name: '亮片合格率', type: 'line', yAxisIndex: 1, ...ratePoints, lineStyle: { width: 2.6, color: brightLine, cap: 'round', join: 'round' }, itemStyle: { color: brightLine, borderColor: brightLine, borderWidth: 2 }, data: rows.map(row => rateNumber(visibleStageRate(row, 'bright', rateBasis))) },
|
||||
],
|
||||
};
|
||||
} else {
|
||||
@@ -1382,7 +1350,7 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
}
|
||||
instance.setOption(option, { replaceMerge: ['series', 'yAxis'], lazyUpdate: false });
|
||||
refreshBarMasks();
|
||||
}, [rows, mode, stage, rateBasis, targetRate, themeRevision, refreshBarMasks, onlyStage, selectedPeriod]);
|
||||
}, [rows, mode, stage, rateBasis, targetRate, themeRevision, refreshBarMasks, onlyStage, selectedPeriod, active]);
|
||||
|
||||
const dimmedPeriod = selectedPeriod === lineSelectedPeriod ? undefined : selectedPeriod;
|
||||
|
||||
@@ -1426,7 +1394,7 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
</div>;
|
||||
}
|
||||
|
||||
function TrendTable({ rows, rateBasis, onMonth, defectDisplay = 'weight' }: { rows: TrendMetricRow[]; rateBasis: 'original' | 'withoutHeadquartersScrap'; onMonth: (value: number | string) => void; defectDisplay?: 'weight'|'rate' }) {
|
||||
export function TrendTable({ rows, rateBasis, onMonth, defectDisplay = 'weight', onlyStage }: { rows: TrendMetricRow[]; rateBasis: 'original' | 'withoutHeadquartersScrap'; onMonth: (value: number | string) => void; defectDisplay?: 'weight'|'rate'; onlyStage?: Stage }) {
|
||||
const compact = useCompactTable();
|
||||
const columns: ColumnsType<TrendMetricRow> = [
|
||||
{ title: '统计期间', dataIndex: 'month', key: 'month', align: 'center', fixed: 'left', width: 130, render: (_: unknown, row) => <Button type="link" onClick={() => onMonth(row.month)}>{row.periodLabel || String(row.month)}</Button> },
|
||||
@@ -1440,7 +1408,8 @@ function TrendTable({ rows, rateBasis, onMonth, defectDisplay = 'weight' }: { ro
|
||||
{ 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 ? <div className="metric-table-scroll trend-data-table"><Table size="small" bordered tableLayout="fixed" columns={columns} dataSource={rows} rowKey={row => String(row.month)} pagination={false} scroll={{ x: columns.reduce((total, column) => total + Number(column.width || 0), 0) }} />
|
||||
const visibleColumns = onlyStage ? columns.filter(column => column.key === 'month' || String(column.key).startsWith(onlyStage)) : columns;
|
||||
return rows.length ? <div className="metric-table-scroll trend-data-table"><Table size="small" bordered tableLayout="fixed" columns={visibleColumns} dataSource={rows} rowKey={row => String(row.month)} pagination={false} scroll={{ x: visibleColumns.reduce((total, column) => total + Number(column.width || 0), 0) }} />
|
||||
</div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前数据未返回趋势" />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user