修复:统一阶段筛选尺寸并平滑更新钻取趋势
This commit is contained in:
+21
-8
@@ -321,6 +321,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [dataKey, setDataKey] = useState('');
|
||||
const [trendData, setTrendData] = useState<TrendMetricRow[]>([]);
|
||||
const [trendDataKey, setTrendDataKey] = useState('');
|
||||
const [trendFailure, setTrendFailure] = useState<{ key: string; message: string } | null>(null);
|
||||
const [trendTarget, setTrendTarget] = useState<number | null>(null);
|
||||
const [trendTargetKey, setTrendTargetKey] = useState('');
|
||||
const [trendObject, setTrendObject] = useState('');
|
||||
@@ -491,6 +492,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
|
||||
useEffect(() => {
|
||||
if (optionsLoading) return;
|
||||
setTrendFailure(null);
|
||||
if (useSummaryTrend) {
|
||||
setTrendLoading(false);
|
||||
return;
|
||||
@@ -498,15 +500,15 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const controller = new AbortController();
|
||||
setTrendLoading(true);
|
||||
api.metrics(trendParams, controller.signal).then(result => {
|
||||
if (trendKeyRef.current !== trendKey) return;
|
||||
if (controller.signal.aborted || trendKeyRef.current !== trendKey) return;
|
||||
setTrendData(Array.isArray(result.trend) ? result.trend : []);
|
||||
setTrendDataKey(trendKey);
|
||||
})
|
||||
.catch(errorValue => {
|
||||
if (!controller.signal.aborted && !onUnauthorized(errorValue)) message.error(`趋势加载失败:${chooseError(errorValue)}`);
|
||||
if (!controller.signal.aborted && !onUnauthorized(errorValue)) setTrendFailure({ key: trendKey, message: chooseError(errorValue) });
|
||||
}).finally(() => { if (!controller.signal.aborted) setTrendLoading(false); });
|
||||
return () => controller.abort();
|
||||
}, [trendKey, useSummaryTrend, queryRevision, onUnauthorized, message, optionsLoading]);
|
||||
}, [trendKey, useSummaryTrend, queryRevision, onUnauthorized, optionsLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -531,6 +533,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
|
||||
const currentTrendTarget = trendTargetKey === trendKey ? trendTarget : null;
|
||||
const visibleTrendData = useMemo(() => fullYearTrend(trendDataKey === trendKey ? trendData : [], year, trendGranularity), [trendData, trendDataKey, trendKey, year, trendGranularity]);
|
||||
const currentTrendError = trendFailure?.key === trendKey ? trendFailure.message : '';
|
||||
const trendRefreshing = trendLoading || (useSummaryTrend && queryBusy) || (trendDataKey !== trendKey && !(useSummaryTrend ? currentMetricsError : currentTrendError));
|
||||
// 只在当前查询返回后替换画面;钻取等待期间保留上一次趋势和目标线。
|
||||
const retainedTrend = useRetainedResult(trendDataKey === trendKey ? { rows: visibleTrendData, target: currentTrendTarget } : null);
|
||||
const renderedTrendData = retainedTrend?.rows || visibleTrendData;
|
||||
const renderedTrendTarget = retainedTrend ? retainedTrend.target : currentTrendTarget;
|
||||
const drilledTrendData = useMemo(
|
||||
() => trendDataKey === trendKey ? visibleTrendData : fullYearTrend([], year, 'month'),
|
||||
[trendDataKey, trendKey, visibleTrendData, year],
|
||||
@@ -798,11 +806,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
</label>
|
||||
{trendMode !== 'data' && <Segmented value={trendStage} options={[{ label: '亮片', value: 'bright' }, { label: '黑片', value: 'black' }]} onChange={value => setTrendStage(value as Stage)} aria-label="趋势阶段" />}
|
||||
</div>
|
||||
<div className="trend-chart-shell" aria-busy={trendLoading}>
|
||||
{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'
|
||||
? <TrendTable rows={visibleTrendData} defectDisplay={defectDisplay} rateBasis={rateBasis} onMonth={selectTrendPeriod} />
|
||||
: <TrendChart rows={visibleTrendData} mode={trendMode} stage={trendStage} rateBasis={rateBasis} targetRate={currentTrendTarget} selectedPeriod={selectedTrendPeriod} onMonth={selectTrendPeriod} />}
|
||||
{(trendLoading || (useSummaryTrend && queryBusy)) && <span className="trend-refresh-indicator"><Spin size="small" />正在更新趋势</span>}
|
||||
? <TrendTable rows={renderedTrendData} defectDisplay={defectDisplay} rateBasis={rateBasis} onMonth={selectTrendPeriod} />
|
||||
: <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>
|
||||
<div className="chart-footnote"><span style={{ marginLeft: 'auto' }}>点击期间筛选,再次点击可取消</span></div>
|
||||
</section>
|
||||
@@ -1304,6 +1313,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 => ({
|
||||
id: String(row.period ?? row.month),
|
||||
value: hasStageRows(row, stage) ? stageValue(row, stage, field, rateBasis) : null,
|
||||
itemStyle: { color: field === 'qualifiedWeight'
|
||||
? (String(row.period ?? row.month) === selectedPeriod ? bars.selectedQualified : bars.qualified)
|
||||
@@ -1319,7 +1329,10 @@ export function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedP
|
||||
})].join('<br/>');
|
||||
};
|
||||
const base: echarts.EChartsCoreOption = {
|
||||
animation: false,
|
||||
animation: !window.matchMedia('(prefers-reduced-motion: reduce)').matches,
|
||||
animationDuration: 0,
|
||||
animationDurationUpdate: 520,
|
||||
animationEasingUpdate: 'cubicOut',
|
||||
textStyle: { fontFamily, color: ink, fontSize },
|
||||
grid: { left: 65, right: mode === 'production' ? 67 : 32, top: 70, bottom: 38 },
|
||||
legend: { type: 'scroll', top: 0, left: 9, right: 9, itemWidth: 14, itemHeight: 7, itemGap: 20, textStyle: { color: ink, fontFamily, fontSize, fontWeight: 500 } },
|
||||
|
||||
Reference in New Issue
Block a user