优化:统一阶段更多筛选并放大侧栏内容

This commit is contained in:
2026-11-01 15:33:59 +08:00
parent e6ceae12f0
commit fb245f7d2e
3 changed files with 26 additions and 7 deletions
+13 -5
View File
@@ -2,7 +2,7 @@ import { SmoothTableFrame, useRetainedResult } from './QueryResultMotion';
import { queryScrapWeight } from './queryMetricValues';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Alert, App, Button, Empty, Input, Modal, Segmented, Select, Spin } from 'antd';
import { DownloadOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
import { DownOutlined, DownloadOutlined, ReloadOutlined, SearchOutlined, UpOutlined } from '@ant-design/icons';
import { api, decodeQueryValueList, encodeQueryValueList } from './api';
import { MetricTable, MetricCard, DefectBreakdown, DefectParetoPanel, SectionHeading, RecordsDrawer, TrendChart, fullYearTrend, queryFromLocation } from './QueryPage';
import { StageSourceFilters } from './StageSourceFilters';
@@ -24,6 +24,7 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU
const [year,setYear]=useState(initial.year||defaults.year);const [month,setMonth]=useState(initial.month||defaults.month);const [quarter,setQuarter]=useState(initial.quarter||previousCompleteQuarter().quarter);
const [department,setDepartment]=useState(()=>decodeQueryValueList(initial.department));const [group,setGroup]=useState(()=>decodeQueryValueList(initial.group));const [product,setProduct]=useState(()=>decodeQueryValueList(initial.product));const [projectGroup,setProjectGroup]=useState(()=>decodeQueryValueList(initial.projectGroup));
const [sourceFilters,setSourceFilters]=useState<SourceColumnFilter[]>(initial.columnFilters||[]);const [search,setSearch]=useState(initial.productSearch||'');const includeUnassigned=true;
const [moreFiltersOpen,setMoreFiltersOpen]=useState(false);
const [options,setOptions]=useState<OptionsResponse|null>(null);const [catalog,setCatalog]=useState<{releaseId:string;sourceFields:SourceColumnField[]}|null>(null);const [supportError,setSupportError]=useState('');const [supportLoading,setSupportLoading]=useState(true);
const [applied,setApplied]=useState<QueryParams|null>(null);const [revision,setRevision]=useState(0);const [response,setResponse]=useState<{key:string;value:MetricsResponse}|null>(null);const [loading,setLoading]=useState(false);const [failure,setFailure]=useState<{key:string;message:string}|null>(null);
const [defectDisplay,setDefectDisplay]=useState<'weight'|'rate'>('weight');
@@ -62,7 +63,9 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU
const dirty=!!applied&&JSON.stringify(draft)!==JSON.stringify(applied);const submit=()=>{automaticPeriod.current=false;setApplied(draft);setRevision(v=>v+1);};
const groups=(options?.groups||[]).filter(name=>!department.length||department.includes(options?.groupDepartments?.[name]||''));
const paths=options?.organizationPaths||[];const products=department.length||group.length?[...new Set(paths.filter(path=>(!department.length||department.includes(path.department||''))&&(!group.length||group.includes(path.group||''))).map(path=>path.product).filter((v):v is string=>!!v))]:options?.products||[];
const select=(name:string,value:string[],choices:string[],change:(v:string[])=>void)=><label className="query-field query-primary-field"><span>{name}</span><Select {...readableSelectPopup} mode="multiple" allowClear showSearch optionFilterProp="label" aria-label={name} placeholder="全部" maxTagCount="responsive" value={value} options={[...new Set([...choices,...value])].map(v=>({label:v==='__UNASSIGNED__'?'未分类':v,value:v}))} onChange={change}/></label>;
const select=(name:string,value:string[],choices:string[],change:(v:string[])=>void,extra=false)=><label className={`query-field ${extra?'query-extra-field':'query-primary-field'}`}><span>{name}</span><Select {...readableSelectPopup} mode="multiple" allowClear showSearch optionFilterProp="label" aria-label={name} placeholder="全部" maxTagCount="responsive" value={value} options={[...new Set([...choices,...value])].map(v=>({label:v==='__UNASSIGNED__'?'未分类':v,value:v}))} onChange={change}/></label>;
const moreFilterCount=(projectGroup.length?1:0)+sourceFilters.length;
const moreFilterSummary=[projectGroup.length?`项目组:${projectGroup.map(v=>v==='__UNASSIGNED__'?'未分类':v).join('、')}`:'',...sourceFilters.map(rule=>fields.find(field=>field.key===rule.field)?.label||rule.field)].filter(Boolean).join(';');
const displayed = useRetainedResult(current && applied ? { data: current, query: applied } : null);
const displayedQuery = displayed?.query || applied;
const sortedRows=useMemo(()=>sortStageRowsByTotalWeight(displayed?.data.rows||[],stage),[displayed?.data,stage]);
@@ -80,10 +83,15 @@ export default function StageProductPage({stage,onUnauthorized}:{stage:Stage;onU
{select('产业部',department,options?.departments||[],values=>{setDepartment(values);setGroup([]);setProduct([]);})}
{select('业务分组',group,groups,values=>{setGroup(values);setProduct([]);})}
{select('产品',product,products,setProduct)}
{options?.projectGroupStatus==='READY'&&select('项目组',projectGroup,options.projectGroups||[],setProjectGroup)}
{catalog&&<StageSourceFilters part="picker" stage={stage} fields={fields} query={draft} value={sourceFilters} onChange={setSourceFilters} onUnauthorized={onUnauthorized}/>}
<div className="query-more-toggle" title={moreFilterSummary||undefined}>
<Button type="text" size="small" icon={moreFiltersOpen?<UpOutlined/>:<DownOutlined/>} aria-expanded={moreFiltersOpen} aria-controls={`stage-more-filters-${stage}`} onClick={()=>setMoreFiltersOpen(open=>!open)}>更多筛选{moreFilterCount?`(已选 ${moreFilterCount} 项)`:''}</Button>
{moreFilterCount>0&&<Button type="link" size="small" onClick={()=>{setProjectGroup([]);setSourceFilters([]);}}>清除</Button>}
</div>
<div className="query-toolbar-tail"><Button type="text" icon={<ReloadOutlined/>} loading={supportLoading} onClick={()=>void loadSupport()}>刷新</Button><Button type="primary" icon={<SearchOutlined/>} disabled={supportLoading||!!supportError||!catalog} loading={loading} onClick={submit}>查询</Button></div>
{catalog&&<StageSourceFilters part="rows" stage={stage} fields={fields} query={draft} value={sourceFilters} onChange={setSourceFilters} onUnauthorized={onUnauthorized}/>}
{moreFiltersOpen&&<div className="query-extra-fields" id={`stage-more-filters-${stage}`}>
{options?.projectGroupStatus==='READY'&&select('项目组',projectGroup,options.projectGroups||[],setProjectGroup,true)}
{catalog&&<StageSourceFilters stage={stage} fields={fields} query={draft} value={sourceFilters} onChange={setSourceFilters} onUnauthorized={onUnauthorized}/>}
</div>}
{dirty&&<div className="stage-query-pending">筛选条件已修改,点击“查询”更新统计结果</div>}
</section>
{error&&<Alert showIcon type="error" message="查询失败" description={error} action={<Button onClick={()=>setRevision(v=>v+1)}>重试</Button>}/>}
+2 -2
View File
@@ -29,7 +29,7 @@ body { color: var(--ink); background: #f4f6fb; font-size: var(--font-body); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.app-shell { min-height: var(--viewport-height); }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 15; display: flex; width: var(--sidebar); flex-direction: column; padding: 16px 12px 10px; background: #f8f9fc; border-right: 1px solid var(--line); }
.sidebar { --font-body: 14px; --font-control: 13px; position: fixed; inset: 0 auto 0 0; z-index: 15; display: flex; width: var(--sidebar); flex-direction: column; padding: 16px 12px 10px; background: #f8f9fc; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 7px; border: 0; background: transparent; text-align: left; font-size: var(--font-dialog-title); font-weight: 700; cursor: pointer; white-space: nowrap; }
.brand-mark { display: inline-flex; align-items: center; gap: 2px; width: 22px; height: 23px; transform: skew(-17deg); }
.brand-mark i { display: block; width: 4px; height: 17px; background: var(--blue); }
@@ -40,7 +40,7 @@ button { color: inherit; }
.nav-group { margin-top: 12px; }
.nav-group-label { padding: 7px 9px 6px; color: var(--ink); font-size: var(--font-control); font-weight: 650; }
.nav-item { display: flex; width: 100%; min-height: 36px; align-items: center; gap: 10px; padding: 7px 9px; border: 0; background: transparent; text-align: left; cursor: pointer; font-size: var(--font-body); }
.nav-item .anticon { width: 16px; color: var(--ink); font-size: var(--font-dialog-title); }
.nav-item .anticon { width: 18px; flex: 0 0 18px; color: var(--ink); font-size: 18px; }
.nav-item:hover { background: #eef2fb; }
.nav-item.active { color: var(--blue-dark); background: #e3ebff; font-weight: 650; }
.nav-item.active .anticon { color: var(--blue); }