修复:统一阶段筛选尺寸并平滑更新钻取趋势

This commit is contained in:
2026-11-01 17:01:35 +08:00
parent 5c37b39858
commit d0fee1544a
4 changed files with 31 additions and 14 deletions
+7
View File
@@ -102,3 +102,10 @@
- 六个查询页桌面端指标卡统一最小高度 96px,避免黑片与亮片页因没有辅助说明而矮一截;保留手机端原有 84px 最小高度。
- 六个查询页和六种主题的卡片高度已实测一致;数据、字号、卡片排列与口径切换保持原有行为。
## 2026-11-01:筛选框统一与钻取趋势过渡(本地)
- 黑片、亮片取消独立的筛选框最小宽度与间距,年份、月份、季度复用其他查询页的尺寸规则;月份统一为两位显示,原查询方式保留。
- 钻取时保留上次成功的趋势及目标线,新数据返回后使用同一图表实例进行 520ms 更新动画;减少动态效果时直接更新。
- 旧范围图表在更新或失败时禁止交互;加载失败保留原图并允许重试。已取消的请求不能覆盖后续相同范围的新请求。
- 本地复现原钻取存在 23 帧空白,修复后三级钻取与六主题均为零空白帧;快速返回重入、失败保留、实际筛选框尺寸及相关检查通过,未发布。
+21 -8
View File
@@ -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 } },
+3 -3
View File
@@ -77,9 +77,9 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU
{supportError&&<Alert showIcon type="error" message="查询条件读取失败" description={supportError} action={<Button onClick={()=>void loadSupport()}>重试</Button>}/>}
<section className="query-toolbar panel" aria-label={`${label}汇总条件`}>
<Segmented aria-label="统计周期" value={period} options={[{label:'年度',value:'year'},{label:'季度',value:'quarter'},{label:'月度',value:'month'}]} onChange={v=>{automaticPeriod.current=false;setPeriod(v as PeriodKind);}}/>
<label className="query-field query-period-field"><span>年份</span><Select aria-label="年份" value={year} onChange={v=>{automaticPeriod.current=false;setYear(v);}} options={(options?.years?.length?options.years:[year]).map(v=>({label:`${v}年`,value:v}))}/></label>
{period==='month'&&<label className="query-field query-period-field"><span>月份</span><Select aria-label="月份" value={month} onChange={v=>{automaticPeriod.current=false;setMonth(v);}} options={Array.from({length:12},(_,i)=>({label:`${i+1}月`,value:i+1}))}/></label>}
{period==='quarter'&&<label className="query-field query-period-field"><span>季度</span><Select aria-label="季度" value={quarter} onChange={v=>{automaticPeriod.current=false;setQuarter(v);}} options={[1,2,3,4].map(v=>({label:`第${v}季度`,value:v}))}/></label>}
<label className="query-field query-period-field query-period-year"><span>年份</span><Select aria-label="年份" value={year} onChange={v=>{automaticPeriod.current=false;setYear(v);}} options={(options?.years?.length?options.years:[year]).map(v=>({label:`${v}年`,value:v}))}/></label>
{period==='month'&&<label className="query-field query-period-field query-period-month"><span>月份</span><Select aria-label="月份" value={month} onChange={v=>{automaticPeriod.current=false;setMonth(v);}} options={Array.from({length:12},(_,i)=>({label:`${String(i+1).padStart(2,'0')}月`,value:i+1}))}/></label>}
{period==='quarter'&&<label className="query-field query-period-field query-period-quarter"><span>季度</span><Select aria-label="季度" value={quarter} onChange={v=>{automaticPeriod.current=false;setQuarter(v);}} options={[1,2,3,4].map(v=>({label:`第${v}季度`,value:v}))}/></label>}
{select('产业部',department,options?.departments||[],values=>{setDepartment(values);setGroup([]);setProduct([]);})}
{select('业务分组',group,groups,values=>{setGroup(values);setProduct([]);})}
{select('产品',product,products,setProduct)}
-3
View File
@@ -1,12 +1,9 @@
.stage-product-page .query-toolbar { gap: 10px; }
.stage-source-filters { display: contents; }
.stage-source-filters > .ant-select { width: 220px; }
.stage-source-filter-row { flex: 1 0 100%; display: grid; grid-template-columns: minmax(120px,180px) 150px minmax(240px,1fr) 32px; align-items: center; gap: 10px; }
.stage-source-filter-row > strong { overflow-wrap: anywhere; font-size: var(--font-body); }
.stage-source-filter-row > .ant-select { width: 100%; min-width: 0; }
.stage-query-pending { flex-basis: 100%; color: var(--muted-ink); font-size: var(--font-control); }
.stage-product-page .query-field > .ant-select { min-width: 110px; }
.stage-product-page .query-primary-field > .ant-select { min-width: 0; }
@media(max-width:760px) {
.stage-source-filter-row { grid-template-columns: minmax(0,1fr) 140px 32px; }
.stage-source-filter-row > .ant-select:nth-of-type(2) { grid-column: 1 / 3; grid-row: 2; }