完善:质量分析平台查询与分析功能
This commit is contained in:
@@ -73,8 +73,8 @@ export function AiMarkdown({ content, className }: { content: string; className?
|
||||
const body: string[][] = [];
|
||||
while (index < lines.length && lines[index].trim() && lines[index].includes('|')) body.push(tableCells(lines[index++]));
|
||||
blocks.push(<div className="ai-markdown-table-wrap" key={`table-${blocks.length}`}><table>
|
||||
<thead><tr>{headers.map((cell, cellIndex) => <th key={cellIndex}>{inlineMarkdown(cell, `th-${cellIndex}`)}</th>)}</tr></thead>
|
||||
<tbody>{body.map((row, rowIndex) => <tr key={rowIndex}>{headers.map((_, cellIndex) => <td key={cellIndex}>{inlineMarkdown(row[cellIndex] || '', `td-${rowIndex}-${cellIndex}`)}</td>)}</tr>)}</tbody>
|
||||
<thead><tr><th className="ai-markdown-index">序号</th>{headers.map((cell, cellIndex) => <th key={cellIndex}>{inlineMarkdown(cell, `th-${cellIndex}`)}</th>)}</tr></thead>
|
||||
<tbody>{body.map((row, rowIndex) => <tr key={rowIndex}><td className="ai-markdown-index">{rowIndex + 1}</td>{headers.map((_, cellIndex) => <td key={cellIndex}>{inlineMarkdown(row[cellIndex] || '', `td-${rowIndex}-${cellIndex}`)}</td>)}</tr>)}</tbody>
|
||||
</table></div>);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Spin } from 'antd';
|
||||
import { CheckCircleOutlined, CloseCircleOutlined, DownOutlined, RightOutlined } from '@ant-design/icons';
|
||||
import { analysisIsRunning } from './analysisConversationState';
|
||||
import { sanitizeAnalysisDisplayText } from './analysisDisplayText';
|
||||
|
||||
const record = (value: unknown): Record<string, unknown> => value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
||||
const callLabel = (step: Record<string, unknown>) => String(step.label || ({ read: '读取分析资料', mcp_call: '查询质量数据' } as Record<string, string>)[String(step.tool)] || step.tool || '分析步骤');
|
||||
const INPUT_LABELS: Record<string, string> = { mode: '分析方式', scope: '范围', period: '期间', comparisonPeriod: '对比期间', filters: '筛选', view: '汇总维度', stage: '阶段', dimension: '排名维度', defect: '具体缺陷', category: '缺陷大类', limit: '返回数量', sort: '排序', year: '年', month: '月', quarter: '季度', department: '产业部', group: '业务分组', product: '规格', projectGroup: '项目组', includeUnassigned: '包含未分类行' };
|
||||
const INPUT_VALUES: Record<string, string> = { overall: '全公司', auto_combined: '汽车交通合计', auto_domestic: '汽车交通国内', auto_overseas: '汽车交通海外', black: '黑片', bright: '亮片', category: '缺陷大类', defect: '具体缺陷', product: '规格', department: '产业部', group: '业务分组', projectGroup: '项目组', scrap_delta: '报废增量', current_scrap: '当前报废重量', rate_drop: '合格率降幅', catalog: '确认可用数据', query: '指标查询', compare: '期间比较', top: '重点对象排名', changes: '变化对象追查', defects: '具体缺陷分析', details: '来源明细核查' };
|
||||
function inputText(input: Record<string, unknown>): string {
|
||||
return Object.entries(input).map(([key, value]) => {
|
||||
const shown = typeof value === 'object' && value ? inputText(record(value)).replaceAll('\n', ',') : typeof value === 'boolean' ? value ? '是' : '否' : INPUT_VALUES[String(value)] || String(value);
|
||||
return `${INPUT_LABELS[key] || key}:${shown}`;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
export function AnalysisProcess({ turn }: { turn: Record<string, unknown> }) {
|
||||
const result = record(turn.result);
|
||||
const plan = record(turn.plan || result.plan);
|
||||
const running = analysisIsRunning(turn.status || result.status);
|
||||
const rawSteps = turn.steps || result.steps || plan.steps;
|
||||
const steps = Array.isArray(rawSteps) ? rawSteps.map(record) : [];
|
||||
const [open, setOpen] = useState(running);
|
||||
const [now, setNow] = useState(Date.now());
|
||||
useEffect(() => { setOpen(running); }, [running]);
|
||||
useEffect(() => {
|
||||
if (!running) return;
|
||||
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [running]);
|
||||
if (!running && !steps.length) return null;
|
||||
const started = Date.parse(String(turn.startedAt || plan.startedAt || turn.createdAt || ''));
|
||||
const elapsed = Number.isFinite(started) ? Math.max(0, Math.floor((now - started) / 1000)) : undefined;
|
||||
const message = sanitizeAnalysisDisplayText(String(turn.progressMessage || plan.progressMessage || (turn.status === 'QUEUED' ? '任务已排队,等待开始' : '正在研究问题并准备下一步查询…')));
|
||||
return <section className={`analysis-process ${running ? 'is-running' : ''}`} aria-label="分析调用过程">
|
||||
<button type="button" className="analysis-process-toggle" aria-expanded={open} onClick={() => setOpen(value => !value)}>
|
||||
{running ? <Spin size="small" /> : <CheckCircleOutlined />}
|
||||
<strong>{running ? '正在分析' : '查看分析过程'}</strong>
|
||||
<span>{steps.length ? `${steps.length} 次调用` : '准备中'}{running && elapsed !== undefined ? ` · ${elapsed} 秒` : ''}</span>
|
||||
{open ? <DownOutlined /> : <RightOutlined />}
|
||||
</button>
|
||||
{open && <div className="analysis-process-body">
|
||||
<ol>{steps.map((step, index) => {
|
||||
const state = String(step.status || '').toLowerCase();
|
||||
const recovered = step.recovered === true;
|
||||
const failed = ['failed', 'error'].includes(state) && !recovered;
|
||||
const active = ['started', 'running', 'queued'].includes(state) && running;
|
||||
const begin = Date.parse(String(step.startedAt || ''));
|
||||
const end = Date.parse(String(step.finishedAt || ''));
|
||||
const seconds = Number.isFinite(begin) && Number.isFinite(end) ? Math.max(0, (end - begin) / 1000).toFixed(1) : undefined;
|
||||
const input = record(step.input);
|
||||
return <li key={String(step.step || index)}>
|
||||
<div className="analysis-process-step">{active ? <Spin size="small" /> : failed ? <CloseCircleOutlined /> : <CheckCircleOutlined />}<strong>{index + 1}. {callLabel(step)}</strong><span>{active ? '进行中' : recovered ? '已重试成功' : failed ? '未成功' : '已结束'}{seconds ? ` · ${seconds} 秒` : ''}</span></div>
|
||||
{Object.keys(input).length > 0 && <details><summary>查询条件</summary><pre>{inputText(input)}</pre></details>}
|
||||
{typeof step.outputSummary === 'string' && <p>{sanitizeAnalysisDisplayText(step.outputSummary)}</p>}
|
||||
</li>;
|
||||
})}</ol>
|
||||
{running && <p className="analysis-process-current" role="status">{message}</p>}
|
||||
</div>}
|
||||
</section>;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ const escape = (value: string) => value.replaceAll('&', '&').replaceAll('<',
|
||||
|
||||
const reportCss = `
|
||||
.q-report{box-sizing:border-box;width:900px;padding:52px;background:#fff;color:#202b3c;font:15px/1.85 -apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;overflow-wrap:anywhere}
|
||||
.q-report *{box-sizing:border-box}.q-report header{padding-bottom:26px;border-bottom:2px solid #355f9b}.q-report .q-eyebrow{font-size:12px;letter-spacing:2px;color:#53739c}.q-report h1{font-size:27px;line-height:1.5;margin:10px 0}.q-report .q-subtitle{font-size:12px;color:#69778b}.q-report h2{font-size:18px;margin:30px 0 12px}.q-report p{margin:10px 0}.q-report .q-prose{white-space:pre-wrap}.q-report .q-kpis{display:flex;gap:12px;margin:22px 0}.q-report .q-kpi{flex:1;padding:17px 18px;background:#f2f6fb;border-radius:6px}.q-report .q-kpi span{display:block;font-size:12px;color:#66778d}.q-report .q-kpi strong{display:block;font-size:27px;font-variant-numeric:tabular-nums;color:#254f87}.q-report table{width:100%;border-collapse:collapse;font-size:13px;table-layout:fixed}.q-report th{background:#f2f6fb;color:#53657c;text-align:left}.q-report th,.q-report td{padding:10px 12px;border-bottom:1px solid #e3e9f0;vertical-align:top}.q-report th:first-child,.q-report td:first-child{width:44%}.q-report .q-note{font-size:12px;color:#69778b}.q-report footer{margin-top:34px;padding-top:16px;border-top:1px solid #dde5ef;font-size:11px;color:#738197}.q-report .q-partial{color:#996b20}@media print{body{margin:0}.q-report{width:100%;padding:20px}tr{break-inside:avoid}}
|
||||
.q-report *{box-sizing:border-box}.q-report header{padding-bottom:26px;border-bottom:2px solid #355f9b}.q-report .q-eyebrow{font-size:12px;letter-spacing:2px;color:#53739c}.q-report h1{font-size:27px;line-height:1.5;margin:10px 0}.q-report .q-subtitle{font-size:12px;color:#69778b}.q-report h2{font-size:18px;margin:30px 0 12px}.q-report p{margin:10px 0}.q-report .q-prose{white-space:pre-wrap}.q-report .q-kpis{display:flex;gap:12px;margin:22px 0}.q-report .q-kpi{flex:1;padding:17px 18px;background:#f2f6fb;border-radius:6px}.q-report .q-kpi span{display:block;font-size:12px;color:#66778d}.q-report .q-kpi strong{display:block;font-size:27px;font-variant-numeric:tabular-nums;color:#254f87}.q-report table{width:100%;border:1px solid #dfe5ef;border-collapse:collapse;font-size:13px;table-layout:fixed}.q-report th{background:#f2f6fb;color:#53657c;text-align:center;font-weight:650}.q-report th,.q-report td{padding:10px 12px;border:1px solid #dfe5ef;text-align:center;vertical-align:middle}.q-report tbody tr:nth-child(even){background:#f8fafd}.q-report th:first-child,.q-report td:first-child{width:62px;color:#738197;font-variant-numeric:tabular-nums}.q-report .q-note{font-size:12px;color:#69778b}.q-report footer{margin-top:34px;padding-top:16px;border-top:1px solid #dde5ef;font-size:11px;color:#738197}.q-report .q-partial{color:#996b20}@media print{body{margin:0}.q-report{width:100%;padding:20px}tr{break-inside:avoid}}
|
||||
`;
|
||||
|
||||
function ReportDocument({ turn, stamp }: { turn: Row; stamp: string }) {
|
||||
@@ -39,7 +39,7 @@ function ReportDocument({ turn, stamp }: { turn: Row; stamp: string }) {
|
||||
<header><div className="q-eyebrow">质量中心 · 分析报告</div><h1>{question.length > 90 ? `${question.slice(0, 90)}…` : question}</h1><div className="q-subtitle">{period(main.context)}{period(main.context) ? ' · ' : ''}{stamp}</div></header>
|
||||
{String(turn.status || result.status) === 'PARTIAL' && <p className="q-partial">本次分析部分完成,以下保留已获得的结果。</p>}
|
||||
{Object.keys(summary).length > 0 && <div className="q-kpis">
|
||||
<div className="q-kpi"><span>{adjusted ? '综合合格率(不含本部报废)' : '综合合格率'}</span><strong>{coverage.blackRows === 0 || coverage.brightRows === 0 ? '—' : rate(adjusted ? summary.compositeRateWithoutHeadquartersScrap : summary.compositeRate)}</strong></div>
|
||||
<div className="q-kpi"><span>{adjusted ? '综合合格率(不含本部报废)' : '综合合格率'}</span><strong>{coverage.blackRows === 0 && coverage.brightRows === 0 ? '—' : rate(adjusted ? summary.compositeRateWithoutHeadquartersScrap : summary.compositeRate)}</strong></div>
|
||||
<div className="q-kpi"><span>黑片合格率</span><strong>{coverage.blackRows === 0 ? '—' : rate(black.rate)}</strong></div>
|
||||
<div className="q-kpi"><span>{adjusted ? '亮片合格率(不含本部报废)' : '亮片合格率'}</span><strong>{coverage.brightRows === 0 ? '—' : rate(adjusted ? bright.rateWithoutHeadquartersScrap : bright.rate)}</strong></div>
|
||||
</div>}
|
||||
@@ -47,16 +47,16 @@ function ReportDocument({ turn, stamp }: { turn: Row; stamp: string }) {
|
||||
{comparisons.map((item, index) => {
|
||||
const current = record(item.current), comparison = record(item.comparison), delta = record(item.delta), comparable = record(item.comparability);
|
||||
const value = (side: Row) => { const s = record(side.summary); switch (item.metric) { case 'BLACK_RATE': return rate(record(s.black).rate); case 'BRIGHT_RATE': return rate(record(s.bright).rate); case 'BRIGHT_RATE_WITHOUT_HEADQUARTERS_SCRAP': return rate(record(s.bright).rateWithoutHeadquartersScrap); case 'COMPOSITE_RATE_WITHOUT_HEADQUARTERS_SCRAP': return rate(s.compositeRateWithoutHeadquartersScrap); default: return rate(s.compositeRate); } };
|
||||
return <section key={`compare-${index}`}><h2>{metricName(item.metric)} · 期间比较</h2><table><thead><tr><th>期间</th><th>正式结果</th></tr></thead><tbody><tr><td>{period(current.context)}</td><td>{value(current)}</td></tr><tr><td>{period(comparison.context)}</td><td>{value(comparison)}</td></tr><tr><td>变化(百分点)</td><td>{number(delta.percentagePoints)}</td></tr></tbody></table>{comparable.comparable === false && <p className="q-note">{text(comparable.reason || (Array.isArray(comparable.reasons) ? comparable.reasons.join(';') : '所选期间不可比,不给出变化结论。'))}</p>}</section>;
|
||||
return <section key={`compare-${index}`}><h2>{metricName(item.metric)} · 期间比较</h2><table><thead><tr><th>序号</th><th>期间</th><th>正式结果</th></tr></thead><tbody><tr><td>1</td><td>{period(current.context)}</td><td>{value(current)}</td></tr><tr><td>2</td><td>{period(comparison.context)}</td><td>{value(comparison)}</td></tr><tr><td>3</td><td>变化(百分点)</td><td>{number(delta.percentagePoints)}</td></tr></tbody></table>{comparable.comparable === false && <p className="q-note">{text(comparable.reason || (Array.isArray(comparable.reasons) ? comparable.reasons.join(';') : '所选期间不可比,不给出变化结论。'))}</p>}</section>;
|
||||
})}
|
||||
{results.filter(item => Array.isArray(item.groups)).map((item, index) => {
|
||||
const available = item.available === true;
|
||||
const ranked = [...rows(item.groups)].filter(row => typeof row[available ? 'impactPP' : 'scrapDelta'] === 'number').sort((a, b) => available ? Number(a.impactPP) - Number(b.impactPP) : Number(b.scrapDelta) - Number(a.scrapDelta)).slice(0, 10);
|
||||
if (!ranked.length) return null;
|
||||
return <section key={`impact-${index}`}><h2>{stageName(item.stage)} · 优先核查对象</h2><table><thead><tr><th>产品 / 规格</th><th>当前合格率</th><th>比较期合格率</th><th>{available ? '影响(百分点)' : '报废增量(kg)'}</th></tr></thead><tbody>{ranked.map((row, i) => <tr key={i}><td>{text(row.label || row.key)}</td><td>{rate(row.currentRate)}</td><td>{rate(row.comparisonRate)}</td><td>{number(available ? row.impactPP : row.scrapDelta)}</td></tr>)}</tbody></table>{!available && <p className="q-note">按报废增量列出前10项。分组无法完整回加,仅作核查线索,不能当作整体下降贡献。</p>}</section>;
|
||||
return <section key={`impact-${index}`}><h2>{stageName(item.stage)} · 优先核查对象</h2><table><thead><tr><th>序号</th><th>产品 / 规格</th><th>当前合格率</th><th>比较期合格率</th><th>{available ? '影响(百分点)' : '报废增量(kg)'}</th></tr></thead><tbody>{ranked.map((row, i) => <tr key={i}><td>{i + 1}</td><td>{text(row.label || row.key)}</td><td>{rate(row.currentRate)}</td><td>{rate(row.comparisonRate)}</td><td>{number(available ? row.impactPP : row.scrapDelta)}</td></tr>)}</tbody></table>{!available && <p className="q-note">按报废增量列出前10项。分组无法完整回加,仅作核查线索,不能当作整体下降贡献。</p>}</section>;
|
||||
})}
|
||||
{results.filter(item => item.kind === 'analysis_statistics').map((item, index) => <section key={`trend-${index}`}><h2>{stageName(item.stage)} · 历史趋势</h2><table><thead><tr><th>期间</th><th>阶段合格率</th></tr></thead><tbody>{rows(item.trendChange).map((row, i) => <tr key={i}><td>{text(row.label || row.period)}</td><td>{rate(row.stageRate)}</td></tr>)}</tbody></table></section>)}
|
||||
{results.filter(item => Array.isArray(item.rows) && item.dimension && item.stage).map((item, index) => <section key={`top-${index}`}><h2>{stageName(item.stage)} · TOP核查对象</h2><table><thead><tr><th>对象</th><th>报废重量(kg)</th><th>占比</th></tr></thead><tbody>{rows(item.rows).slice(0, 10).map((row, i) => <tr key={i}><td>{text(row.label || row.key)}</td><td>{number(row.weight)}</td><td>{rate(row.share)}</td></tr>)}</tbody></table></section>)}
|
||||
{results.filter(item => item.kind === 'analysis_statistics').map((item, index) => <section key={`trend-${index}`}><h2>{stageName(item.stage)} · 历史趋势</h2><table><thead><tr><th>序号</th><th>期间</th><th>阶段合格率</th></tr></thead><tbody>{rows(item.trendChange).map((row, i) => <tr key={i}><td>{i + 1}</td><td>{text(row.label || row.period)}</td><td>{rate(row.stageRate)}</td></tr>)}</tbody></table></section>)}
|
||||
{results.filter(item => Array.isArray(item.rows) && item.dimension && item.stage).map((item, index) => <section key={`top-${index}`}><h2>{stageName(item.stage)} · TOP核查对象</h2><table><thead><tr><th>序号</th><th>对象</th><th>报废重量(kg)</th><th>占比</th></tr></thead><tbody>{rows(item.rows).slice(0, 10).map((row, i) => <tr key={i}><td>{i + 1}</td><td>{text(row.label || row.key)}</td><td>{number(row.weight)}</td><td>{rate(row.share)}</td></tr>)}</tbody></table></section>)}
|
||||
<footer>数据来源:质量中心。指标沿用正式计算口径,原因判断的依据与局限见分析结论。</footer>
|
||||
</div>;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Alert, App, Button, Empty, Form, Input, InputNumber, Modal, Popconfirm,
|
||||
Select, Segmented, Spin, Table, Tag,
|
||||
Select, Segmented, Spin, Tag,
|
||||
} from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import { DeleteOutlined, PlusOutlined, ReloadOutlined, SaveOutlined } from '@ant-design/icons';
|
||||
import { ApiError, api, collectionItems } from './api';
|
||||
import type { QueryParams, Stage, ViewKind } from './types';
|
||||
@@ -79,7 +80,7 @@ function SnapshotRates({ label, value }: { label: string; value: unknown }) {
|
||||
return <div className="completion-snapshot">
|
||||
<strong>{label}</strong>
|
||||
<dl>
|
||||
<dt>综合合格率</dt><dd>{hasBlack && hasBright ? pct(summary.compositeRate) : '—'}</dd>
|
||||
<dt>综合合格率</dt><dd>{hasBlack || hasBright ? pct(summary.compositeRate) : '—'}</dd>
|
||||
<dt>黑片合格率</dt><dd>{hasBlack ? pct(record(summary.black).rate) : '—'}</dd>
|
||||
<dt>亮片合格率</dt><dd>{hasBright ? pct(record(summary.bright).rate) : '—'}</dd>
|
||||
<dt>覆盖行数</dt><dd>黑 {text(coverage.blackRows, text(record(snapshot.coverage).blackRows, '0'))} · 亮 {text(coverage.brightRows, text(record(snapshot.coverage).brightRows, '0'))}</dd>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Alert, Button, Select, Spin } from 'antd';
|
||||
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
||||
import { api } from './api';
|
||||
import type { FilterField } from './types';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
|
||||
function FieldSelect({ field, value, onChange, onUnauthorized }: { field: FilterField; value: string[]; onChange: (values: string[]) => void; onUnauthorized: (error: unknown) => boolean }) {
|
||||
const [search, setSearch] = useState('');
|
||||
const [choices, setChoices] = useState<string[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hasMore, setHasMore] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [revision, setRevision] = useState(0);
|
||||
const generation = useRef(0);
|
||||
useEffect(() => {
|
||||
const current = ++generation.current;
|
||||
setLoading(true); setChoices([]); setError('');
|
||||
const timer = window.setTimeout(() => {
|
||||
api.filterFieldOptions(field.key, search).then(result => {
|
||||
if (generation.current !== current) return;
|
||||
setChoices(result.values); setHasMore(result.hasMore);
|
||||
}).catch(e => { if (generation.current === current && !onUnauthorized(e)) setError(e.message || '选项加载失败'); })
|
||||
.finally(() => { if (generation.current === current) setLoading(false); });
|
||||
}, search ? 250 : 0);
|
||||
return () => { window.clearTimeout(timer); generation.current++; };
|
||||
}, [field.key, search, revision, onUnauthorized]);
|
||||
return <label className="query-field query-extra-field"><span>{field.label}</span><Select mode="multiple" allowClear showSearch aria-label={field.label}
|
||||
{...readableSelectPopup} maxTagCount="responsive" value={value} loading={loading} filterOption={false} searchValue={search} onSearch={setSearch}
|
||||
onChange={values => { onChange(values); setSearch(''); }} placeholder="全部"
|
||||
options={[...new Set([...choices, ...value.filter(v => v !== '__EMPTY__')])].map(v => ({ label: v, value: v })).concat(field.allowEmpty ? [{ label: '空值', value: '__EMPTY__' }] : [])}
|
||||
notFoundContent={loading ? <Spin size="small" /> : error ? <Button size="small" onClick={() => setRevision(n => n + 1)}>加载失败,重试</Button> : '暂无匹配项'}
|
||||
popupRender={menu => <>{menu}{hasMore && <div className="query-options-hint">选项较多,请输入关键字查找</div>}{error && <div role="alert" className="query-options-hint">{error}</div>}</>}
|
||||
/></label>;
|
||||
}
|
||||
|
||||
export function ExtraQueryFilters({ projectGroup, projectGroups, onProjectGroup, value, onChange, onUnauthorized }: {
|
||||
projectGroup: string[]; projectGroups?: string[]; onProjectGroup: (values: string[]) => void;
|
||||
value: Record<string, string[]>; onChange: (value: Record<string, string[]>) => void; onUnauthorized: (error: unknown) => boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [fields, setFields] = useState<FilterField[]>([]);
|
||||
const [error, setError] = useState('');
|
||||
const [revision, setRevision] = useState(0);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.filterFields().then(result => { if (alive) { setFields(result); setError(''); } }).catch(e => { if (alive && !onUnauthorized(e)) setError(e.message || '筛选字段加载失败'); });
|
||||
return () => { alive = false; };
|
||||
}, [revision, onUnauthorized]);
|
||||
const count = (projectGroup.length ? 1 : 0) + Object.values(value).filter(v => v.length).length;
|
||||
const summary = [projectGroup.length ? `项目组:${projectGroup.map(v => v === '__UNASSIGNED__' ? '未分类' : v).join('、')}` : '', ...Object.entries(value).filter(([, values]) => values.length).map(([key, values]) => `${fields.find(f => f.key === key)?.label || key}:${values.map(v => v === '__EMPTY__' ? '空值' : v).join('、')}`)].filter(Boolean).join(';');
|
||||
return <>
|
||||
<div className="query-more-toggle" title={summary || undefined}><Button type="text" size="small" icon={open ? <UpOutlined /> : <DownOutlined />} aria-expanded={open} onClick={() => setOpen(v => !v)}>更多筛选{count ? `(已选 ${count} 项)` : ''}</Button>
|
||||
{count > 0 && <Button type="link" size="small" onClick={() => { onProjectGroup([]); onChange({}); }}>清除</Button>}
|
||||
</div>
|
||||
{error && <Alert className="query-extra-error" type="error" showIcon message={error} action={<Button onClick={() => setRevision(n => n + 1)}>重试</Button>} />}
|
||||
{open && <div className="query-extra-fields">
|
||||
{projectGroups && <label className="query-field query-extra-field"><span>项目组</span><Select aria-label="项目组" mode="multiple" maxTagCount="responsive" allowClear showSearch optionFilterProp="label" {...readableSelectPopup} value={projectGroup} onChange={onProjectGroup} placeholder="全部" options={[...projectGroups.map(v => ({ label: v, value: v })), { label: '未分类', value: '__UNASSIGNED__' }]} /></label>}
|
||||
{fields.map(field => <FieldSelect key={field.key} field={field} value={value[field.key] || []} onUnauthorized={onUnauthorized} onChange={values => { const next = { ...value }; if (values.length) next[field.key] = values; else delete next[field.key]; onChange(next); }} />)}
|
||||
{Object.keys(value).filter(key => !fields.some(f => f.key === key)).map(key => <Alert key={key} type="warning" message={`筛选字段 ${key} 当前不可用,请清除后继续查询。`} />)}
|
||||
</div>}
|
||||
</>;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Alert, App, Button, Checkbox, Input, Select, Space, Table } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { api } from './api';
|
||||
import type { FilterField } from './types';
|
||||
|
||||
export function FilterFieldSettings({ canManage, onUnauthorized }: { canManage: boolean; onUnauthorized: (error: unknown) => boolean }) {
|
||||
const { message } = App.useApp();
|
||||
const [fields, setFields] = useState<FilterField[]>([]);
|
||||
const [columns, setColumns] = useState<{ black: string[]; bright: string[] }>({ black: [], bright: [] });
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [dirty, setDirty] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [revision, setRevision] = useState(0);
|
||||
useEffect(() => {
|
||||
let alive = true; setLoading(true);
|
||||
Promise.all([api.filterFields(canManage), canManage ? api.filterFieldColumns() : Promise.resolve({ black: [], bright: [] })]).then(([items, cols]) => {
|
||||
if (alive) { setFields(items); setColumns(cols); setDirty(false); setError(''); }
|
||||
}).catch(e => { if (alive && !onUnauthorized(e)) setError(e.message || '筛选字段加载失败'); }).finally(() => { if (alive) setLoading(false); });
|
||||
return () => { alive = false; };
|
||||
}, [canManage, onUnauthorized, revision]);
|
||||
const update = (key: string, change: Partial<FilterField>) => { setFields(items => items.map(f => f.key === key ? { ...f, ...change } : f)); setDirty(true); };
|
||||
const save = async () => {
|
||||
setSaving(true);
|
||||
try { const result = await api.saveFilterFields(fields); setFields(result); setDirty(false); setError(''); message.success('筛选字段已保存,查询页面重新打开后生效'); }
|
||||
catch (e) { if (!onUnauthorized(e)) setError(e instanceof Error ? e.message : '保存失败'); }
|
||||
finally { setSaving(false); }
|
||||
};
|
||||
return <section className="panel filter-field-settings">
|
||||
<div className="section-heading-row"><strong>筛选字段</strong>{canManage && <Space><Button icon={<PlusOutlined />} disabled={loading || saving || fields.length >= 20} onClick={() => { setFields(items => [...items, { key: `field_${Date.now().toString(36)}`, label: '', blackColumn: '', brightColumn: '', enabled: true, allowEmpty: true, sortOrder: items.length }]); setDirty(true); }}>新增字段</Button><Button type="primary" loading={saving} disabled={!dirty || loading || fields.some(f => !f.label.trim() || !f.blackColumn || !f.brightColumn)} onClick={() => void save()}>保存筛选字段</Button></Space>}</div>
|
||||
<p>配置后可在查询页面的“更多筛选”中使用。黑片、亮片按各自来源列筛选,支持搜索、多选和空值;代码按文本保留。</p>
|
||||
{error && <Alert type="error" showIcon message={error} action={<Button onClick={() => setRevision(n => n + 1)}>重新加载</Button>} />}
|
||||
<Table rowKey="key" loading={loading} dataSource={fields} pagination={false} scroll={{ x: 780 }} columns={[
|
||||
{ title: '筛选名称', key: 'label', width: 180, render: (_, f) => <Input aria-label={`筛选名称 ${f.key}`} value={f.label} maxLength={80} disabled={!canManage || saving} onChange={e => update(f.key, { label: e.target.value })} /> },
|
||||
...(['black', 'bright'] as const).map(stage => ({ title: stage === 'black' ? '黑片来源列' : '亮片来源列', key: stage, width: 240, render: (_: unknown, f: FilterField) => <Select aria-label={`${stage === 'black' ? '黑片' : '亮片'}来源列 ${f.key}`} showSearch optionFilterProp="label" style={{ width: '100%' }} value={f[stage === 'black' ? 'blackColumn' : 'brightColumn'] || undefined} disabled={!canManage || saving} placeholder="选择来源列" options={[...new Set([...columns[stage], f[stage === 'black' ? 'blackColumn' : 'brightColumn']].filter(Boolean))].map(v => ({ label: v, value: v }))} onChange={v => update(f.key, { [stage === 'black' ? 'blackColumn' : 'brightColumn']: v })} /> })),
|
||||
{ title: '允许空值', key: 'empty', width: 100, render: (_, f) => <Checkbox aria-label={`允许空值 ${f.label || f.key}`} checked={f.allowEmpty} disabled={!canManage || saving} onChange={e => update(f.key, { allowEmpty: e.target.checked })} /> },
|
||||
{ title: '启用', key: 'enabled', width: 80, render: (_, f) => <Checkbox aria-label={`启用 ${f.label || f.key}`} checked={f.enabled} disabled={!canManage || saving} onChange={e => update(f.key, { enabled: e.target.checked })} /> },
|
||||
...(canManage ? [{ title: '操作', key: 'actions', width: 80, render: (_: unknown, f: FilterField) => <Button type="link" danger disabled={saving} onClick={() => { setFields(items => items.filter(item => item.key !== f.key)); setDirty(true); }}>移除</Button> }] : []),
|
||||
]} />
|
||||
</section>;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Alert, App, Button, Checkbox, Drawer, Empty, Form, Input, InputNumber, Modal, Select, Spin, Switch, Table, Tabs, Tag } from 'antd';
|
||||
import { Alert, App, Button, Checkbox, Drawer, Empty, Form, Input, InputNumber, Modal, Select, Spin, Switch, Tabs, Tag } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import { DownloadOutlined, ReloadOutlined } from '@ant-design/icons';
|
||||
import { ApiError, api, collectionItems } from './api';
|
||||
import type { AuthUser, SourceItem } from './types';
|
||||
|
||||
+203
-99
@@ -1,5 +1,6 @@
|
||||
import { FilterFieldSettings } from './FilterFieldSettings';
|
||||
import { isInternalDataField, publicJson } from './publicDataDisplay';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Alert,
|
||||
App,
|
||||
@@ -16,11 +17,11 @@ import {
|
||||
Select,
|
||||
Spin,
|
||||
Switch,
|
||||
Table,
|
||||
Tabs,
|
||||
Tag,
|
||||
} from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import { DeleteOutlined, DownloadOutlined, ReloadOutlined, RobotOutlined } from '@ant-design/icons';
|
||||
import { ApiError, api, collectionItems, decodeQueryValueList } from './api';
|
||||
import type { AuthUser, Collection, OptionsResponse, QueryParams, SourceItem, ViewKind } from './types';
|
||||
@@ -32,10 +33,12 @@ import { TargetVersionAdmin } from './AnalyticsCompletion';
|
||||
import { AnalysisReportExport, NativeAnalysisReport } from './AnalysisReportExport';
|
||||
import { AiMarkdown } from './AiMarkdown';
|
||||
import { AnalysisApiSettings } from './AnalysisApiSettings';
|
||||
import { AnalysisProcess } from './AnalysisProcess';
|
||||
import { activeAnalysisTurn, analysisIsRunning, beginAnalysisSelection, defaultAnalysisSession, rememberAnalysisSession, rememberPendingAnalysisSession, settledAnalysisTurn } from './analysisConversationState';
|
||||
import './analysis-chat.css';
|
||||
|
||||
const TABLE_PAGE_SIZE = 20;
|
||||
import { DataWorkflowHub, MasterWorkbookUpload, ReadableConfigDefinition, SourceFilesPanel } from './NoCodeDataWorkflow';
|
||||
import { DataWorkflowHub, MasterWorkbookUpload, ReadableConfigDefinition, SourceFilesPanel, type PendingSourceDeletion } from './NoCodeDataWorkflow';
|
||||
import { MappingDefinitionEditor, MasterDataDefinitionEditor, MatchRulesDefinitionEditor, RuleDefinitionEditor, TechnicalDefinitionEditor, validateStructuredMappingDefinition, type ConfigDefinition } from './StructuredConfigEditors';
|
||||
import { useDataWorkflowOperation } from './useDataWorkflowOperation';
|
||||
import { BackupOperationsPanel, CostConfigurationPanel, OperationsMonitorPanel, ServiceIdentityPanel, SourceGovernancePanel, UserAccessPolicyPanel } from './GovernanceCompletion';
|
||||
@@ -60,7 +63,7 @@ function restoredAnalysisTurns(history: Record<string, unknown>, metadata: Colle
|
||||
return collectionItems(metadata).slice().reverse().map(turn => {
|
||||
const found = saved.find(item => item.id === turn.id);
|
||||
const answer = found && isObjectRecord(found.result) ? found.result : {};
|
||||
return { ...answer, ...turn, sessionId: history.id };
|
||||
return { ...found, ...answer, ...turn, sessionId: history.id };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,6 +107,7 @@ function decodeAnalysisLinkContext(encoded: string | null): AnalysisLinkContext
|
||||
if (value.startsWith('~qv1~') && decodeQueryValueList(value).length === 0) throw new Error(`分析条件链接中的${key}多选值无效`);
|
||||
query[key] = value;
|
||||
}
|
||||
if (rawQuery.extraFilters && typeof rawQuery.extraFilters === 'object') query.extraFilters = rawQuery.extraFilters as Record<string,string[]>;
|
||||
if (rawQuery.releaseId && typeof rawQuery.releaseId === 'string') query.releaseId = rawQuery.releaseId;
|
||||
if (typeof rawQuery.includeUnassigned === 'boolean') query.includeUnassigned = rawQuery.includeUnassigned;
|
||||
const rawRef = source.resultRef && typeof source.resultRef === 'object' ? source.resultRef as Record<string, unknown> : undefined;
|
||||
@@ -163,7 +167,7 @@ function unwrapItems(value: unknown): { items: Record<string, unknown>[]; total?
|
||||
return { items: [] };
|
||||
}
|
||||
|
||||
function DynamicTable({ items, rowKey = 'id', paginate = true }: { items: Record<string, unknown>[]; rowKey?: string; paginate?: boolean }) {
|
||||
function DynamicTable({ items, rowKey = 'id', paginate = true, indexOffset = 0 }: { items: Record<string, unknown>[]; rowKey?: string; paginate?: boolean; indexOffset?: number }) {
|
||||
const keys = useMemo(() => {
|
||||
const discovered = new Set<string>();
|
||||
for (const item of items.slice(0, 30)) Object.keys(item).filter(key => !isInternalDataField(key)).forEach(key => discovered.add(key));
|
||||
@@ -185,7 +189,7 @@ function DynamicTable({ items, rowKey = 'id', paginate = true }: { items: Record
|
||||
render: value => readableValue(value),
|
||||
}));
|
||||
return items.length
|
||||
? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={item => String(item[rowKey] ?? JSON.stringify(item))} pagination={paginate ? { pageSize: TABLE_PAGE_SIZE, showSizeChanger: false } : false} scroll={{ x: 'max-content' }} />
|
||||
? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={item => String(item[rowKey] ?? JSON.stringify(item))} pagination={paginate ? { pageSize: TABLE_PAGE_SIZE, showSizeChanger: false } : false} indexOffset={indexOffset} scroll={{ x: 'max-content' }} />
|
||||
<p className="table-caption">显示服务端返回的 {items.length} 条记录</p></div>
|
||||
: <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端当前返回空列表" />;
|
||||
}
|
||||
@@ -194,12 +198,12 @@ export default function ManagementPages({ page, user, onUnauthorized, onNavigate
|
||||
page: PageKey; user: AuthUser; onUnauthorized: (error: unknown) => boolean;
|
||||
onNavigate: (page: PageKey) => void;
|
||||
}) {
|
||||
if (page === 'sources') return <SourcesPage onUnauthorized={onUnauthorized} user={user} />;
|
||||
if (page === 'sources' || page === 'imports') return <SourcesPage onUnauthorized={onUnauthorized} user={user} />;
|
||||
if (page === 'analysis') return <AnalysisPage onUnauthorized={onUnauthorized} user={user} />;
|
||||
if (page === 'access') return <AccessPage user={user} onUnauthorized={onUnauthorized} />;
|
||||
if (page === 'basis') return <BasisPage onUnauthorized={onUnauthorized} />;
|
||||
if (page === 'rules') return <><ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} /><MetricDictionaryPanel user={user} onUnauthorized={onUnauthorized} />{user.roles.some(role => ['SYSTEM_ADMIN', 'RULE_MAINTAINER'].includes(role)) && <TargetVersionAdmin onUnauthorized={onUnauthorized} />}</>;
|
||||
if (page === 'masterData') return <ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} />;
|
||||
if (page === 'masterData') return <><FilterFieldSettings canManage={user.roles.some(role => ['SYSTEM_ADMIN','DATA_MAINTAINER'].includes(role))} onUnauthorized={onUnauthorized} /><ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} /></>;
|
||||
if (page === 'mappings') return <><ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} /><MappingIssueResolutionPanel user={user} onUnauthorized={onUnauthorized} /><CostConfigurationPanel user={user} onUnauthorized={onUnauthorized} /></>;
|
||||
const resource: Record<string, { endpoint: 'imports' | 'tasks'; title: string; subtitle: string }> = {
|
||||
imports: { endpoint: 'imports', title: '导入与校验记录', subtitle: '接收后的来源文件及其校验任务状态。' },
|
||||
@@ -218,6 +222,22 @@ function SourcesPage({ onUnauthorized, user }: { onUnauthorized: (error: unknown
|
||||
const [currentReleaseId, setCurrentReleaseId] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [maintenanceBusy, setMaintenanceBusy] = useState(false);
|
||||
const [historyOpen, setHistoryOpen] = useState(() => new URLSearchParams(window.location.search).get('showImportHistory') === '1');
|
||||
const pendingKey = `quality-pending-source-deletions:${user.id}`;
|
||||
const [pendingDeletion, setPendingDeletion] = useState<PendingSourceDeletion>(() => {
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(pendingKey) || 'null');
|
||||
if (saved && Array.isArray(saved.ids) && saved.ids.length <= 50 && saved.ids.every((id: unknown) => typeof id === 'string') && (saved.releaseId === null || typeof saved.releaseId === 'string')) return saved;
|
||||
} catch { /* Pending changes are optional when storage is unavailable. */ }
|
||||
return { ids: [], releaseId: null };
|
||||
});
|
||||
useEffect(() => { try { if (pendingDeletion.ids.length) localStorage.setItem(pendingKey, JSON.stringify(pendingDeletion)); else localStorage.removeItem(pendingKey); } catch { /* Keep in-memory changes available. */ } }, [pendingKey, pendingDeletion]);
|
||||
const onDeleted = useCallback((ids: string[]) => setPendingDeletion(previous => ({ ...previous, ids: previous.ids.filter(id => !ids.includes(id)) })), []);
|
||||
const toggleDelete = (id: string) => setPendingDeletion(previous => previous.ids.includes(id)
|
||||
? { ...previous, ids: previous.ids.filter(value => value !== id) }
|
||||
: previous.ids.length >= 50 ? previous : { ids: [...previous.ids, id], releaseId: previous.ids.length ? previous.releaseId : currentReleaseId });
|
||||
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -228,14 +248,31 @@ function SourcesPage({ onUnauthorized, user }: { onUnauthorized: (error: unknown
|
||||
};
|
||||
useEffect(() => { void load(); }, []);
|
||||
return <div className="management-page">
|
||||
<PageHeader title="数据接入" description="上传、替换和发布质量数据;按向导完成,无需改文件名或填写技术配置。" actions={<Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button>} />
|
||||
{error && <Alert showIcon type="error" message="来源清单读取失败" description={error} action={<Button size="small" onClick={() => void load()}>重试</Button>} />}
|
||||
<DataWorkflowHub user={user} sources={sources} currentReleaseId={currentReleaseId} onUnauthorized={onUnauthorized} onRefresh={() => void load()} />
|
||||
<SourceFilesPanel user={user} sources={sources} loading={loading} onUnauthorized={onUnauthorized} onRefresh={() => void load()} />
|
||||
<DataWorkflowHub user={user} sources={sources} currentReleaseId={currentReleaseId} pendingDeletion={pendingDeletion} onDeleted={onDeleted} onBusyChange={setMaintenanceBusy} onUnauthorized={onUnauthorized} onRefresh={() => void load()} />
|
||||
<SourceFilesPanel user={user} sources={sources} loading={loading} pendingIds={pendingDeletion.ids} maintenanceBusy={maintenanceBusy} onToggleDelete={toggleDelete} onClearDeletes={() => setPendingDeletion({ ids: [], releaseId: null })} onUnauthorized={onUnauthorized} onRefresh={() => void load()} />
|
||||
<details className="nc-advanced-records" open={historyOpen} onToggle={event => setHistoryOpen(event.currentTarget.open)}><summary>导入记录与失败详情</summary>{historyOpen && <ImportHistoryPanel user={user} currentReleaseId={currentReleaseId} onUnauthorized={onUnauthorized} />}</details>
|
||||
<details className="nc-advanced-records"><summary>高级来源记录与审计</summary><SourceGovernancePanel user={user} currentReleaseId={currentReleaseId} onUnauthorized={onUnauthorized} /></details>
|
||||
</div>;
|
||||
}
|
||||
|
||||
function ImportHistoryPanel({ user, currentReleaseId, onUnauthorized }: { user: AuthUser; currentReleaseId: string | null; onUnauthorized: (error: unknown) => boolean }) {
|
||||
const [items, setItems] = useState<Record<string, unknown>[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const load = useCallback(async () => {
|
||||
try { const result = unwrapItems(await api.tasks()); setItems(result.items.filter(item => String(item.type).toUpperCase() === 'IMPORT')); setError(''); }
|
||||
catch (value) { if (!onUnauthorized(value)) setError(apiMessage(value)); }
|
||||
finally { setLoading(false); }
|
||||
}, [onUnauthorized]);
|
||||
useEffect(() => { void load(); }, [load, currentReleaseId]);
|
||||
useEffect(() => { if (items.some(item => ['QUEUED', 'RUNNING'].includes(String(item.status).toUpperCase()))) { const timer = window.setTimeout(() => void load(), 2000); return () => window.clearTimeout(timer); } }, [items, load]);
|
||||
return <section className="panel section-panel"><div className="resource-toolbar"><strong>导入记录</strong><span>{items.length} 条 · 可查看处理结果和逐行校验问题</span></div>
|
||||
{error && <Alert showIcon type="error" message="导入记录读取失败" description={error} action={<Button onClick={() => void load()}>重试</Button>} />}
|
||||
{loading ? <Spin /> : <TaskTable items={items} importOnly user={user} onUnauthorized={onUnauthorized} onRefresh={() => void load()} />}
|
||||
</section>;
|
||||
}
|
||||
|
||||
function ImportIssuesDrawer({ runId, onClose, onUnauthorized }: { runId: string; onClose: () => void; onUnauthorized: (error: unknown) => boolean }) {
|
||||
const [result, setResult] = useState<Collection | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -253,7 +290,7 @@ function ImportIssuesDrawer({ runId, onClose, onUnauthorized }: { runId: string;
|
||||
const items = unwrapItems(result).items;
|
||||
return <Drawer className="management-drawer" open={Boolean(runId)} title="导入校验问题" width={Math.min(900, window.innerWidth)} onClose={onClose}>
|
||||
{error && <Alert showIcon type="error" message="问题清单读取失败" description={error} />}
|
||||
{loading ? <div className="loading-panel"><Spin />正在读取问题行…</div> : <DynamicTable items={items} paginate={false} />}
|
||||
{loading ? <div className="loading-panel"><Spin />正在读取问题行…</div> : <DynamicTable items={items} paginate={false} indexOffset={(page - 1) * TABLE_PAGE_SIZE} />}
|
||||
{result?.total && result.total > TABLE_PAGE_SIZE && <Pagination className="records-pagination" current={page} pageSize={TABLE_PAGE_SIZE} total={result.total} showTotal={count => `共 ${count} 条问题`} onChange={setPage} />}
|
||||
</Drawer>;
|
||||
}
|
||||
@@ -702,7 +739,7 @@ function MappingIssueResolutionPanel({ user, onUnauthorized }: { user: AuthUser;
|
||||
<PageHeader title="未命中映射问题" description="按源键汇总真实未命中行;裁决会创建独立映射草稿,不直接修改已发布事实。" actions={<div className="completion-actions"><Select aria-label="映射问题状态" value={status} options={[{ label: '待处理', value: 'OPEN' }, { label: '已裁决', value: 'DECIDED' }, { label: '已退回', value: 'RETURNED' }, { label: '已重验', value: 'REVALIDATED' }, { label: '全部状态', value: '' }]} onChange={value => { setStatus(value); setPage(1); }} /><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button></div>} />
|
||||
{error && <Alert showIcon type="error" message="映射问题操作失败" description={error} />}
|
||||
{!canResolve && <Alert showIcon type="info" message="当前账号仅可查看" description="问题裁决需映射维护、数据维护或系统管理授权。" />}
|
||||
<section className="panel section-panel"><div className="resource-toolbar"><strong>源键命中汇总</strong><span>共 {total} 条</span></div>{loading ? <div className="loading-panel"><Spin />正在读取未命中问题…</div> : items.length ? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id)} pagination={false} scroll={{ x: 1050 }} /></div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前状态没有未命中映射问题" />}{total > TABLE_PAGE_SIZE && <Pagination className="records-pagination" current={page} pageSize={TABLE_PAGE_SIZE} total={total} showTotal={count => `共 ${count} 条问题`} onChange={setPage} />}</section>
|
||||
<section className="panel section-panel"><div className="resource-toolbar"><strong>源键命中汇总</strong><span>共 {total} 条</span></div>{loading ? <div className="loading-panel"><Spin />正在读取未命中问题…</div> : items.length ? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id)} pagination={false} indexOffset={(page - 1) * TABLE_PAGE_SIZE} scroll={{ x: 1050 }} /></div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前状态没有未命中映射问题" />}{total > TABLE_PAGE_SIZE && <Pagination className="records-pagination" current={page} pageSize={TABLE_PAGE_SIZE} total={total} showTotal={count => `共 ${count} 条问题`} onChange={setPage} />}</section>
|
||||
<Drawer className="management-drawer" open={Boolean(selectedId)} title="未命中映射问题处理" width={Math.min(1000, window.innerWidth)} onClose={() => { setSelectedId(''); setDetail(null); }}>
|
||||
{!detail ? <div className="completion-loading"><Spin />读取源键命中与历史裁决…</div> : <>
|
||||
<div className="governance-monitor-grid"><div><small>源键</small><strong>{toText(issue.sourceKey)}</strong></div><div><small>映射类型</small><strong>{toText(issue.mappingType)}</strong></div><div><small>汇总行数</small><strong>{toText(issue.rowCount)}</strong></div><div><small>总重量</small><strong>{toText(issue.totalWeight)}</strong></div></div>
|
||||
@@ -879,12 +916,13 @@ function TaskTable({ items, importOnly, user, onUnauthorized, onRefresh }: { ite
|
||||
} catch (error) { if (!onUnauthorized(error)) message.error(apiMessage(error)); if (error instanceof ApiError && error.status === 409) onRefresh(); }
|
||||
finally { setBusyId(''); }
|
||||
};
|
||||
const importState = (value: unknown) => ({ COMPLETED: '导入完成', SUCCEEDED: '导入完成', FAILED: '导入失败', ERROR: '导入失败', RUNNING: '正在导入', QUEUED: '等待导入', CANCELLED: '已取消' }[String(value).toUpperCase()] || toText(value));
|
||||
const columns: ColumnsType<Record<string, unknown>> = [
|
||||
{ title: '任务 ID', dataIndex: 'id', key: 'id', fixed: 'left', width: 220, ellipsis: true },
|
||||
{ title: '任务类型', dataIndex: 'type', key: 'type', width: 130 },
|
||||
{ title: '状态', dataIndex: 'status', key: 'status', width: 130, render: value => <Tag color={String(value).toUpperCase().includes('FAIL') || String(value).toUpperCase() === 'ERROR' ? 'red' : String(value).toUpperCase() === 'SUCCEEDED' || String(value).toUpperCase() === 'COMPLETED' ? 'green' : 'blue'}>{toText(value)}</Tag> },
|
||||
{ title: '状态', dataIndex: 'status', key: 'status', width: 130, render: value => <Tag color={String(value).toUpperCase().includes('FAIL') || String(value).toUpperCase() === 'ERROR' ? 'red' : String(value).toUpperCase() === 'SUCCEEDED' || String(value).toUpperCase() === 'COMPLETED' ? 'green' : 'blue'}>{importOnly ? importState(value) : toText(value)}</Tag> },
|
||||
{ title: '处理阶段', dataIndex: 'stage', key: 'stage', width: 150 },
|
||||
{ title: '进度(服务端)', dataIndex: 'progress', key: 'progress', width: 145, align: 'right' },
|
||||
{ title: importOnly ? '进度' : '进度(服务端)', dataIndex: 'progress', key: 'progress', width: 145, align: 'right', render: value => importOnly ? `${toText(value)}%` : toText(value) },
|
||||
{ title: '已处理 / 总数', key: 'processed', width: 140, align: 'right', render: (_, row) => `${toText(row.processed)} / ${toText(row.total)}` },
|
||||
{ title: '错误码', dataIndex: 'errorCode', key: 'errorCode', width: 150, render: value => value ? <Tag color="red">{toText(value)}</Tag> : '—' },
|
||||
{ title: '错误信息', dataIndex: 'errorMessage', key: 'errorMessage', width: 300, ellipsis: true, render: value => value ? <span className="task-error">{toText(value)}</span> : '—' },
|
||||
@@ -897,10 +935,10 @@ function TaskTable({ items, importOnly, user, onUnauthorized, onRefresh }: { ite
|
||||
</span> },
|
||||
];
|
||||
return <>
|
||||
{items.length ? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id ?? JSON.stringify(row))} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 1600 }} />
|
||||
<p className="table-caption">错误信息、进度和结果均按任务服务实际返回展示。</p></div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端当前没有后台任务" />}
|
||||
{items.length ? <div className="resource-table"><Table size="small" bordered columns={importOnly ? columns.filter(column => ['createdAt', 'status', 'progress', 'processed', 'errorMessage', 'detail'].includes(String(column.key))) : columns} dataSource={items} rowKey={row => String(row.id ?? JSON.stringify(row))} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: importOnly ? 1000 : 1600 }} />
|
||||
{!importOnly && <p className="table-caption">错误信息、进度和结果均按任务服务实际返回展示。</p>}</div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端当前没有后台任务" />}
|
||||
<Drawer className="management-drawer" open={Boolean(selected)} title="任务详情" width={Math.min(760, window.innerWidth)} onClose={() => setSelected(null)}>
|
||||
{selected && <><div className="task-detail-summary"><strong>{toText(selected.type)} · {toText(selected.status)}</strong><span>{toText(selected.stage)} · {toText(selected.id)}</span>{selected.errorMessage !== null && selected.errorMessage !== undefined && selected.errorMessage !== '' && <Alert showIcon type="error" message={toText(selected.errorCode || '任务错误')} description={toText(selected.errorMessage)} />}</div><pre className="json-result">{publicJson(selected)}</pre></>}
|
||||
{selected && <><div className="task-detail-summary"><strong>{importOnly ? importState(selected.status) : `${toText(selected.type)} · ${toText(selected.status)}`}</strong>{!importOnly && <span>{toText(selected.stage)} · {toText(selected.id)}</span>}{selected.errorMessage !== null && selected.errorMessage !== undefined && selected.errorMessage !== '' && <Alert showIcon type="error" message={toText(selected.errorCode || '任务错误')} description={toText(selected.errorMessage)} />}</div>{importOnly ? <dl className="nc-form-grid"><dt>处理状态</dt><dd>{importState(selected.status)}</dd><dt>处理行数</dt><dd>{toText(selected.processed)} / {toText(selected.total)}</dd><dt>创建时间</dt><dd>{toText(selected.createdAt)}</dd></dl> : <pre className="json-result">{publicJson(selected)}</pre>}</>}
|
||||
</Drawer>
|
||||
<ImportIssuesDrawer runId={issuesRunId} onClose={() => setIssuesRunId('')} onUnauthorized={onUnauthorized} />
|
||||
</>;
|
||||
@@ -918,35 +956,49 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
const [sessions, setSessions] = useState<Record<string, unknown>[]>([]);
|
||||
const [turns, setTurns] = useState<Record<string, unknown>[]>([]);
|
||||
const [options, setOptions] = useState<OptionsResponse | null>(null);
|
||||
const [historyLoading, setHistoryLoading] = useState(false);
|
||||
const [historyLoading, setHistoryLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [retryQuestion, setRetryQuestion] = useState('');
|
||||
const [lastTurn, setLastTurn] = useState<Record<string, unknown> | null>(null);
|
||||
const [activeTurnId, setActiveTurnId] = useState('');
|
||||
const [, setStreamProgress] = useState('');
|
||||
const [streamProgress, setStreamProgress] = useState('');
|
||||
const streamController = useRef<AbortController | null>(null);
|
||||
const eventCursors = useRef<Record<string, string>>({});
|
||||
const deepLinkStarted = useRef(false);
|
||||
const mounted = useRef(true);
|
||||
const userSelectionMade = useRef(false);
|
||||
const navigationGeneration = useRef(0);
|
||||
const subscriptionGeneration = useRef(0);
|
||||
const [releaseId, setReleaseId] = useState<string>();
|
||||
const [sourceResultRef, setSourceResultRef] = useState<AnalysisResultRef>();
|
||||
const conversationEnd = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => { conversationEnd.current?.scrollIntoView({ block: 'nearest' }); }, [lastTurn, busy]);
|
||||
|
||||
const loadSessions = async () => {
|
||||
try { setSessions(collectionItems(await api.analysisSessions())); }
|
||||
catch (value) { if (!onUnauthorized(value)) setError(apiMessage(value)); }
|
||||
try { const items = collectionItems(await api.analysisSessions()); if (mounted.current) setSessions(items); }
|
||||
catch (value) { if (mounted.current && !onUnauthorized(value)) setError(apiMessage(value)); }
|
||||
};
|
||||
useEffect(() => {
|
||||
api.options().then(value => { setOptions(value); })
|
||||
.catch(value => { if (!onUnauthorized(value)) setError(apiMessage(value)); });
|
||||
void loadSessions();
|
||||
let alive = true;
|
||||
api.options().then(value => { if (alive) setOptions(value); })
|
||||
.catch(value => { if (alive && !onUnauthorized(value)) setError(apiMessage(value)); });
|
||||
return () => { alive = false; };
|
||||
}, []);
|
||||
|
||||
const hasBackgroundTurns = sessions.some(item => analysisIsRunning(item.activeTurnStatus));
|
||||
useEffect(() => {
|
||||
if (!initialLink.present || initialSessionId || initialTurnId || !options) return;
|
||||
if (!hasBackgroundTurns) return;
|
||||
const timer = window.setInterval(() => void loadSessions(), 5000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [hasBackgroundTurns]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!initialLink.present || initialSessionId || initialTurnId || !options || userSelectionMade.current) return;
|
||||
const generation = navigationGeneration.current;
|
||||
const selection = beginAnalysisSelection(user.id);
|
||||
if (initialLink.error || !initialLink.query) {
|
||||
setError(initialLink.error || '分析链接缺少有效查询条件');
|
||||
setHistoryLoading(false);
|
||||
return;
|
||||
}
|
||||
const linkedQuery = initialLink.query;
|
||||
@@ -954,6 +1006,7 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
const allowedReleaseIds = new Set((options.releases || []).map(item => item.id));
|
||||
if (linkedRelease && !allowedReleaseIds.has(linkedRelease)) {
|
||||
setError('链接对应的数据当前不可访问,请从当前查询结果重新打开分析。');
|
||||
setHistoryLoading(false);
|
||||
return;
|
||||
}
|
||||
setReleaseId(linkedRelease);
|
||||
@@ -961,6 +1014,7 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
if (initialLink.resultRef) setQuery('请解释已绑定的阶段 TOP 排名,并说明可核查的来源依据。');
|
||||
const context: Record<string, unknown> = {
|
||||
year: linkedQuery.year,
|
||||
...(linkedQuery.extraFilters ? { extraFilters: linkedQuery.extraFilters } : {}),
|
||||
...(linkedQuery.month !== undefined ? { month: linkedQuery.month } : {}),
|
||||
...(linkedQuery.quarter !== undefined ? { quarter: linkedQuery.quarter } : {}),
|
||||
view: linkedQuery.view,
|
||||
@@ -973,7 +1027,7 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
...(initialLink.resultRef ? { resultRef: initialLink.resultRef } : {}),
|
||||
};
|
||||
setSessionContext(context);
|
||||
const requestKey = JSON.stringify({ query: linkedQuery, resultRef: initialLink.resultRef || null });
|
||||
const requestKey = JSON.stringify({ userId: user.id, query: linkedQuery, resultRef: initialLink.resultRef || null });
|
||||
const pageWindow = window as AnalysisPageWindow;
|
||||
let linkedSessionRequest = pageWindow.__qualityAnalysisLinkedSessionRequest;
|
||||
if (!linkedSessionRequest || linkedSessionRequest.key !== requestKey) {
|
||||
@@ -987,24 +1041,30 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
setHistoryLoading(true);
|
||||
linkedSessionRequest.promise
|
||||
.then(created => {
|
||||
if (!alive) return;
|
||||
if (!alive || !mounted.current || generation !== navigationGeneration.current) return;
|
||||
const id = String(created.session.id || '');
|
||||
if (!id) throw new Error('服务端未返回分析会话编号');
|
||||
setSessionId(id);
|
||||
rememberPendingAnalysisSession(user.id, id, selection);
|
||||
writeAnalysisLocation(id);
|
||||
if (pageWindow.__qualityAnalysisLinkedSessionRequest === linkedSessionRequest) delete pageWindow.__qualityAnalysisLinkedSessionRequest;
|
||||
void loadSessions();
|
||||
})
|
||||
.catch(value => {
|
||||
if (!alive) return;
|
||||
if (!alive || !mounted.current || generation !== navigationGeneration.current) return;
|
||||
if (pageWindow.__qualityAnalysisLinkedSessionRequest === linkedSessionRequest) delete pageWindow.__qualityAnalysisLinkedSessionRequest;
|
||||
if (!onUnauthorized(value)) setError(apiMessage(value));
|
||||
})
|
||||
.finally(() => { if (alive) setHistoryLoading(false); });
|
||||
.finally(() => {
|
||||
if (pageWindow.__qualityAnalysisLinkedSessionRequest === linkedSessionRequest) delete pageWindow.__qualityAnalysisLinkedSessionRequest;
|
||||
if (alive && mounted.current && generation === navigationGeneration.current) setHistoryLoading(false);
|
||||
});
|
||||
return () => { alive = false; };
|
||||
}, [options]);
|
||||
|
||||
const writeAnalysisLocation = (selectedSessionId?: string, selectedTurnId?: string) => {
|
||||
if (!mounted.current) return;
|
||||
if (selectedSessionId) rememberAnalysisSession(user.id, selectedSessionId);
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('page', 'analysis');
|
||||
if (selectedSessionId) url.searchParams.set('sessionId', selectedSessionId); else url.searchParams.delete('sessionId');
|
||||
@@ -1014,14 +1074,23 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
};
|
||||
|
||||
const openSession = async (id: string, focusTurnId?: string): Promise<boolean> => {
|
||||
setHistoryLoading(true);
|
||||
userSelectionMade.current = true;
|
||||
beginAnalysisSelection(user.id);
|
||||
const generation = ++navigationGeneration.current;
|
||||
subscriptionGeneration.current += 1;
|
||||
streamController.current?.abort(); streamController.current = null;
|
||||
setBusy(false); setActiveTurnId(''); setHistoryLoading(true);
|
||||
const current = () => mounted.current && generation === navigationGeneration.current;
|
||||
try {
|
||||
const [history, turnHistory] = await Promise.all([api.analysisSession(id), api.analysisSessionTurns(id)]);
|
||||
if (!current()) return false;
|
||||
const historyTurns = restoredAnalysisTurns(history, turnHistory);
|
||||
const active = activeAnalysisTurn(historyTurns);
|
||||
const selectedTurnId = focusTurnId || (active ? String(active.id || '') : '');
|
||||
setSessionId(id);
|
||||
setTurns(restoredAnalysisTurns(history, turnHistory).filter(turn => !focusTurnId || String(turn.id || '') !== focusTurnId));
|
||||
writeAnalysisLocation(id, focusTurnId);
|
||||
setLastTurn(null);
|
||||
setError('');
|
||||
setTurns(historyTurns.filter(turn => !selectedTurnId || String(turn.id || '') !== selectedTurnId));
|
||||
writeAnalysisLocation(id, selectedTurnId || undefined);
|
||||
setLastTurn(null); setError(''); setRetryQuestion('');
|
||||
const context = history.context && typeof history.context === 'object' ? history.context as Record<string, unknown> : {};
|
||||
const restoredContext = { ...context };
|
||||
const fixedRelease = typeof history.releaseId === 'string' ? history.releaseId : typeof context.releaseId === 'string' ? context.releaseId : '';
|
||||
@@ -1032,13 +1101,27 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
setSourceResultRef(resultRef.kind === 'TOP' && typeof resultRef.resultId === 'string' && typeof resultRef.releaseId === 'string' && resultRef.releaseId === String(history.releaseId || context.releaseId || '')
|
||||
? { kind: 'TOP', resultId: resultRef.resultId, releaseId: resultRef.releaseId }
|
||||
: undefined);
|
||||
if (selectedTurnId) {
|
||||
const detail = await api.analysisTurn(selectedTurnId);
|
||||
if (!current()) return false;
|
||||
if (String(detail.sessionId || '') !== id) throw new Error('分析轮次与会话链接不匹配');
|
||||
const restored = { ...historyTurns.find(item => item.id === selectedTurnId), ...detail };
|
||||
setLastTurn(restored);
|
||||
if (analysisIsRunning(restored.status)) void followTurn(selectedTurnId, String(restored.question || ''), id);
|
||||
}
|
||||
return true;
|
||||
} catch (value) { if (!onUnauthorized(value)) setError(apiMessage(value)); return false; }
|
||||
finally { setHistoryLoading(false); }
|
||||
} catch (value) { if (current() && !onUnauthorized(value)) setError(apiMessage(value)); return false; }
|
||||
finally { if (current()) setHistoryLoading(false); }
|
||||
};
|
||||
|
||||
const newSession = () => {
|
||||
if (busy) return;
|
||||
userSelectionMade.current = true;
|
||||
beginAnalysisSelection(user.id);
|
||||
setBusy(false); setActiveTurnId(''); setStreamProgress('');
|
||||
navigationGeneration.current += 1; subscriptionGeneration.current += 1;
|
||||
streamController.current?.abort(); streamController.current = null;
|
||||
rememberAnalysisSession(user.id, '');
|
||||
setHistoryLoading(false);
|
||||
setSessionId(''); setTurns([]); setLastTurn(null); setQuery(''); setError(''); setRetryQuestion('');
|
||||
setSessionContext(null);
|
||||
setReleaseId(undefined);
|
||||
@@ -1047,9 +1130,10 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
};
|
||||
|
||||
const deleteSession = async (id: string) => {
|
||||
const generation = navigationGeneration.current;
|
||||
try {
|
||||
await api.deleteAnalysisSession(id);
|
||||
if (sessionId === id) newSession();
|
||||
if (mounted.current && navigationGeneration.current === generation && sessionId === id) newSession();
|
||||
await loadSessions();
|
||||
message.success('会话已删除');
|
||||
} catch (value) {
|
||||
@@ -1058,13 +1142,17 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
};
|
||||
|
||||
const followTurn = async (id: string, question: string, sessionOverride?: string) => {
|
||||
if (!mounted.current) return;
|
||||
streamController.current?.abort();
|
||||
const generation = ++subscriptionGeneration.current;
|
||||
const current = () => mounted.current && generation === subscriptionGeneration.current;
|
||||
const linkedSessionId = sessionOverride || sessionId;
|
||||
if (linkedSessionId) writeAnalysisLocation(linkedSessionId, id);
|
||||
setActiveTurnId(id); setBusy(true); setStreamProgress('分析任务已排队,等待服务端步骤…');
|
||||
const controller = new AbortController(); streamController.current = controller;
|
||||
let streamedResult: Record<string, unknown> = {};
|
||||
let terminalEventStatus = '';
|
||||
setLastTurn(previous => ({ ...(previous || {}), id, question, status: 'QUEUED' }));
|
||||
setLastTurn(previous => ({ ...(previous || {}), id, question, status: previous?.status || 'QUEUED' }));
|
||||
try {
|
||||
let detail: Record<string, unknown> = {};
|
||||
let reconnectAttempt = 0;
|
||||
@@ -1075,10 +1163,11 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
signal: controller.signal,
|
||||
lastEventId: eventCursors.current[id],
|
||||
onEvent: event => {
|
||||
if (!current()) return;
|
||||
receivedEvents += 1;
|
||||
if (event.id) eventCursors.current[id] = event.id;
|
||||
const data = event.data && typeof event.data === 'object' ? event.data as Record<string, unknown> : {};
|
||||
const messageText = typeof data.message === 'string' ? data.message : event.event.replaceAll('_', ' ');
|
||||
const messageText = typeof data.message === 'string' ? data.message : event.event === 'answer' ? '正在整理分析结论…' : '正在分析…';
|
||||
setStreamProgress(messageText);
|
||||
const eventResult = isObjectRecord(data.result) ? data.result : undefined;
|
||||
if (eventResult) streamedResult = { ...streamedResult, ...eventResult };
|
||||
@@ -1099,6 +1188,10 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
status,
|
||||
latestEvent: event.event,
|
||||
eventStep: data.step,
|
||||
...(Array.isArray(data.steps) ? { steps: data.steps } : {}),
|
||||
...(typeof data.startedAt === 'string' ? { startedAt: data.startedAt } : {}),
|
||||
...(typeof data.updatedAt === 'string' ? { updatedAt: data.updatedAt } : {}),
|
||||
progressMessage: messageText,
|
||||
plan: data.plan || prior.plan,
|
||||
...(eventResult ? { result: { ...priorResult, ...eventResult } } : {}),
|
||||
};
|
||||
@@ -1109,14 +1202,23 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
},
|
||||
});
|
||||
} catch (streamError) {
|
||||
if (!(controller.signal.aborted && terminalEventStatus)) throw streamError;
|
||||
if (!current() || (controller.signal.aborted && !terminalEventStatus)) return;
|
||||
if (streamError instanceof ApiError && [401, 403, 404].includes(streamError.status)) throw streamError;
|
||||
if (!terminalEventStatus) setStreamProgress('连接暂时中断,后台仍在分析,正在恢复…');
|
||||
}
|
||||
|
||||
if (!current() || (controller.signal.aborted && !terminalEventStatus)) return;
|
||||
// A normal SSE close is not necessarily turn completion: the server
|
||||
// rotates its event stream while long-running analyses continue.
|
||||
for (const delayMs of [0, 250, 500, 750, 1000, 1000, 1200]) {
|
||||
if (delayMs) await new Promise(resolve => setTimeout(resolve, delayMs));
|
||||
detail = await api.analysisTurn(id);
|
||||
try { detail = await api.analysisTurn(id); }
|
||||
catch (readError) {
|
||||
if (!current()) return;
|
||||
if (readError instanceof ApiError && [401, 403, 404].includes(readError.status)) throw readError;
|
||||
setStreamProgress('连接暂时中断,后台仍在分析,正在恢复…');
|
||||
}
|
||||
if (!current()) return;
|
||||
if (ANALYSIS_FINAL_STATUSES.has(String(detail.status || '').toUpperCase())) break;
|
||||
if (controller.signal.aborted && !terminalEventStatus) break;
|
||||
}
|
||||
@@ -1126,20 +1228,8 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
const reconnectDelay = Math.min(500 * (2 ** reconnectAttempt), 8000);
|
||||
await new Promise(resolve => setTimeout(resolve, reconnectDelay));
|
||||
}
|
||||
const detailResult = isObjectRecord(detail.result) ? detail.result : {};
|
||||
const combinedResult: Record<string, unknown> = { ...detail, ...detailResult, ...streamedResult };
|
||||
delete combinedResult.result;
|
||||
const detailStatus = String(detail.status || '').toUpperCase();
|
||||
const settledStatus = ANALYSIS_FINAL_STATUSES.has(detailStatus) ? detailStatus : terminalEventStatus || detailStatus;
|
||||
const settledTurn = {
|
||||
...detail,
|
||||
...detailResult,
|
||||
...streamedResult,
|
||||
id,
|
||||
question,
|
||||
...(settledStatus ? { status: settledStatus } : {}),
|
||||
result: combinedResult,
|
||||
};
|
||||
if (!current()) return;
|
||||
const settledTurn = settledAnalysisTurn(id, question, detail, streamedResult, terminalEventStatus);
|
||||
setLastTurn(settledTurn);
|
||||
if (ANALYSIS_FINAL_STATUSES.has(String(settledTurn.status || '').toUpperCase())) {
|
||||
setRetryQuestion(''); setQuery('');
|
||||
@@ -1147,99 +1237,104 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
if (parentSessionId) {
|
||||
try {
|
||||
const [savedHistory, savedMetadata] = await Promise.all([api.analysisSession(parentSessionId), api.analysisSessionTurns(parentSessionId)]);
|
||||
if (!current()) return;
|
||||
const historyTurns = restoredAnalysisTurns(savedHistory, savedMetadata);
|
||||
setTurns(historyTurns.filter(item => String(item.id || '') !== id));
|
||||
} catch (historyError) { if (!onUnauthorized(historyError)) setError(apiMessage(historyError)); }
|
||||
} catch (historyError) { if (current() && !onUnauthorized(historyError)) setError(apiMessage(historyError)); }
|
||||
await loadSessions();
|
||||
}
|
||||
}
|
||||
} catch (value) {
|
||||
if (!(value instanceof DOMException && value.name === 'AbortError')) {
|
||||
if (current() && !(value instanceof DOMException && value.name === 'AbortError')) {
|
||||
if (!onUnauthorized(value)) setError(apiMessage(value));
|
||||
try { setLastTurn({ ...(await api.analysisTurn(id)), id, question }); } catch (refreshError) { if (!onUnauthorized(refreshError)) setError(apiMessage(refreshError)); }
|
||||
try { const detail = await api.analysisTurn(id); if (current()) setLastTurn({ ...detail, id, question }); } catch (refreshError) { if (current() && !onUnauthorized(refreshError)) setError(apiMessage(refreshError)); }
|
||||
}
|
||||
} finally {
|
||||
if (streamController.current === controller) {
|
||||
if (current() && streamController.current === controller) {
|
||||
streamController.current = null; setBusy(false); setActiveTurnId('');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (deepLinkStarted.current || (!initialSessionId && !initialTurnId)) return;
|
||||
deepLinkStarted.current = true;
|
||||
mounted.current = true;
|
||||
let cancelled = false;
|
||||
const restore = async () => {
|
||||
const requestedAt = navigationGeneration.current;
|
||||
setHistoryLoading(true);
|
||||
try {
|
||||
const items = collectionItems(await api.analysisSessions());
|
||||
if (cancelled || requestedAt !== navigationGeneration.current) return;
|
||||
setSessions(items);
|
||||
let linkedSession = initialSessionId;
|
||||
let linkedTurn: Record<string, unknown> | undefined;
|
||||
if (initialTurnId) {
|
||||
linkedTurn = await api.analysisTurn(initialTurnId);
|
||||
const linkedTurn = await api.analysisTurn(initialTurnId);
|
||||
if (cancelled || requestedAt !== navigationGeneration.current) return;
|
||||
const turnSession = String(linkedTurn.sessionId || '');
|
||||
if (linkedSession && turnSession && linkedSession !== turnSession) throw new Error('分析轮次与会话链接不匹配');
|
||||
linkedSession ||= turnSession;
|
||||
}
|
||||
if (!linkedSession) throw new Error('链接缺少可恢复的会话编号');
|
||||
if (cancelled) return;
|
||||
const opened = await openSession(linkedSession, initialTurnId || undefined);
|
||||
if (!opened || cancelled || !linkedTurn) return;
|
||||
const question = typeof linkedTurn.question === 'string' ? linkedTurn.question : '';
|
||||
const restored = { ...linkedTurn, id: initialTurnId, question, sessionId: linkedSession };
|
||||
setLastTurn(restored);
|
||||
const turnStatus = String(linkedTurn.status || '').toUpperCase();
|
||||
if (['QUEUED', 'RUNNING', 'PLANNING', 'TOOL_RUNNING', 'PROCESSING'].includes(turnStatus)) {
|
||||
await followTurn(initialTurnId, question, linkedSession);
|
||||
}
|
||||
} catch (value) {
|
||||
if (!cancelled && !onUnauthorized(value)) setError(apiMessage(value));
|
||||
} finally { if (!cancelled) setHistoryLoading(false); }
|
||||
if (!linkedSession && !initialLink.present) linkedSession = defaultAnalysisSession(user.id, items);
|
||||
if (!cancelled && requestedAt === navigationGeneration.current && linkedSession) await openSession(linkedSession, initialTurnId || undefined);
|
||||
} catch (value) { if (!cancelled && !onUnauthorized(value)) setError(apiMessage(value)); }
|
||||
finally { if (!cancelled && requestedAt === navigationGeneration.current && !initialLink.present) setHistoryLoading(false); }
|
||||
};
|
||||
void restore();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
deepLinkStarted.current = false;
|
||||
streamController.current?.abort();
|
||||
cancelled = true; mounted.current = false;
|
||||
navigationGeneration.current += 1; subscriptionGeneration.current += 1;
|
||||
// Unsubscribe from updates only. The accepted server task continues independently.
|
||||
streamController.current?.abort(); streamController.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const cancelTurn = async () => {
|
||||
if (!activeTurnId) return;
|
||||
const generation = navigationGeneration.current;
|
||||
const id = activeTurnId;
|
||||
try {
|
||||
await api.cancelAnalysisTurn(id, '用户请求停止');
|
||||
streamController.current?.abort();
|
||||
if (!mounted.current || generation !== navigationGeneration.current) return;
|
||||
setStreamProgress('正在停止分析…');
|
||||
const detail = await api.analysisTurn(id);
|
||||
setLastTurn(previous => ({ ...detail, id, question: previous?.question }));
|
||||
if (mounted.current && generation === navigationGeneration.current) setLastTurn(previous => ({ ...detail, id, question: previous?.question }));
|
||||
} catch (value) { if (!onUnauthorized(value)) setError(apiMessage(value)); }
|
||||
};
|
||||
|
||||
const retryTurn = async (turn: Record<string, unknown>) => {
|
||||
if (busy) return;
|
||||
if (busy || historyLoading) return;
|
||||
const id = String(turn.id || '');
|
||||
const status = String(turn.status || '').toUpperCase();
|
||||
if (!id || !['FAILED', 'CANCELLED', 'PARTIAL'].includes(status)) return;
|
||||
const selection = beginAnalysisSelection(user.id);
|
||||
const generation = navigationGeneration.current;
|
||||
const current = () => mounted.current && generation === navigationGeneration.current;
|
||||
const question = typeof turn.question === 'string' ? turn.question : '';
|
||||
const targetSessionId = String(turn.sessionId || sessionId || '');
|
||||
setError(''); setBusy(true); setActiveTurnId(id); setStreamProgress('正在按原冻结计划重新排队…');
|
||||
try {
|
||||
const response = await api.retryAnalysisTurn(id);
|
||||
const retried = response.turn;
|
||||
if (!current()) { rememberPendingAnalysisSession(user.id, String(retried.sessionId || targetSessionId), selection); return; }
|
||||
const retryId = String(retried.id || id);
|
||||
const retrySessionId = String(retried.sessionId || targetSessionId);
|
||||
if (!retrySessionId) throw new Error('无法确定原分析会话,已停止重试。');
|
||||
setSessionId(retrySessionId);
|
||||
setTurns(previous => previous.filter(item => String(item.id || '') !== id));
|
||||
const retriedDetail = await api.analysisTurn(retryId);
|
||||
if (!current()) return;
|
||||
setLastTurn({ ...retriedDetail, ...retried, id: retryId, sessionId: retrySessionId, question });
|
||||
writeAnalysisLocation(retrySessionId, retryId);
|
||||
await loadSessions();
|
||||
if (!current()) return;
|
||||
setBusy(false);
|
||||
await followTurn(retryId, question, retrySessionId);
|
||||
if (current()) await followTurn(retryId, question, retrySessionId);
|
||||
} catch (value) {
|
||||
if (!current()) return;
|
||||
if (!onUnauthorized(value)) setError(apiMessage(value));
|
||||
try {
|
||||
const detail = await api.analysisTurn(id);
|
||||
if (!current()) return;
|
||||
setLastTurn({ ...turn, ...detail, id, question, sessionId: targetSessionId });
|
||||
} catch (refreshError) { if (!onUnauthorized(refreshError)) setError(apiMessage(refreshError)); }
|
||||
setBusy(false); setActiveTurnId(''); setStreamProgress('');
|
||||
@@ -1248,7 +1343,11 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
|
||||
const submit = async (question = query) => {
|
||||
if (!question.trim()) return;
|
||||
if (busy) return;
|
||||
if (busy || historyLoading) return;
|
||||
const selection = beginAnalysisSelection(user.id);
|
||||
rememberAnalysisSession(user.id, '');
|
||||
const generation = navigationGeneration.current;
|
||||
const current = () => mounted.current && generation === navigationGeneration.current;
|
||||
setBusy(true);
|
||||
setError('');
|
||||
setRetryQuestion(question.trim());
|
||||
@@ -1266,19 +1365,23 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
const created = await api.createAnalysisSession({ title: question.trim().slice(0, 60), ...(releaseId ? { releaseId } : {}), ...(context ? { context } : {}) });
|
||||
selectedSessionId = String(created.session.id || '');
|
||||
if (!selectedSessionId) throw new Error('服务端未返回会话编号');
|
||||
setSessionId(selectedSessionId);
|
||||
rememberPendingAnalysisSession(user.id, selectedSessionId, selection);
|
||||
if (current()) setSessionId(selectedSessionId);
|
||||
}
|
||||
const started = await api.startAnalysisTurn(selectedSessionId, { question: question.trim(), ...(context ? { context } : {}), idempotencyKey: crypto.randomUUID() });
|
||||
const turn = started.turn;
|
||||
const turnId = String(turn.id || '');
|
||||
if (!turnId) throw new Error('服务端未返回分析任务编号');
|
||||
rememberPendingAnalysisSession(user.id, selectedSessionId, selection);
|
||||
if (!current()) return;
|
||||
setLastTurn({ ...turn, id: turnId, question: question.trim(), sessionId: selectedSessionId });
|
||||
writeAnalysisLocation(selectedSessionId, turnId);
|
||||
await loadSessions();
|
||||
if (!current()) return;
|
||||
setBusy(false);
|
||||
await followTurn(turnId, question.trim(), selectedSessionId);
|
||||
}
|
||||
catch (value) { if (!onUnauthorized(value)) { setError(apiMessage(value)); message.error(apiMessage(value)); } setBusy(false); }
|
||||
catch (value) { if (current()) { if (!onUnauthorized(value)) { setError(apiMessage(value)); message.error(apiMessage(value)); } setBusy(false); } }
|
||||
};
|
||||
|
||||
return <div className="management-page analysis-simple-page">
|
||||
@@ -1286,20 +1389,20 @@ function AnalysisPage({ onUnauthorized, user }: { onUnauthorized: (error: unknow
|
||||
{error && <Alert type="error" showIcon message="智能分析状态" description={error} action={retryQuestion && <Button size="small" onClick={() => void submit(retryQuestion)}>重试上一问</Button>} />}
|
||||
<div className="analysis-workspace">
|
||||
<aside className="panel analysis-session-panel">
|
||||
<div className="analysis-session-heading"><strong>会话</strong><Button type="primary" size="small" disabled={busy} onClick={newSession}>新会话</Button></div>
|
||||
{historyLoading ? <div className="loading-panel compact"><Spin />正在读取会话…</div> : sessions.length ? <div className="analysis-session-list">{sessions.map(item => <div key={String(item.id)} className={`analysis-session-row ${sessionId === item.id ? 'active' : ''}`}><button disabled={busy} className="analysis-session-item" onClick={() => void openSession(String(item.id))}><strong>{toText(item.title || '未命名会话')}</strong><small>{String(item.updatedAt || item.createdAt || '').slice(0, 10)}</small></button><Popconfirm title="删除此会话及其分析记录?" description="删除后无法恢复" okText="删除" cancelText="取消" okButtonProps={{ danger: true }} onConfirm={() => void deleteSession(String(item.id))}><Button className="analysis-session-delete" type="text" danger icon={<DeleteOutlined />} aria-label={`删除会话 ${toText(item.title || '未命名会话')}`} disabled={busy} /></Popconfirm></div>)}</div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无历史会话" />}
|
||||
<div className="analysis-session-heading"><strong>会话</strong><Button type="primary" size="small" onClick={newSession}>新会话</Button></div>
|
||||
{historyLoading ? <div className="loading-panel compact"><Spin />正在读取会话…</div> : sessions.length ? <div className="analysis-session-list">{sessions.map(item => <div key={String(item.id)} className={`analysis-session-row ${sessionId === item.id ? 'active' : ''}`}><button className="analysis-session-item" onClick={() => void openSession(String(item.id))}><strong>{toText(item.title || '未命名会话')}</strong><small>{String(item.updatedAt || item.createdAt || '').slice(0, 10)}{analysisIsRunning(item.activeTurnStatus) && <span className="analysis-session-state">{item.activeTurnStatus === 'QUEUED' ? '排队中' : '分析中'}</span>}</small></button><Popconfirm title="删除此会话及其分析记录?" description="删除后无法恢复" okText="删除" cancelText="取消" okButtonProps={{ danger: true }} onConfirm={() => void deleteSession(String(item.id))}><Button className="analysis-session-delete" type="text" danger icon={<DeleteOutlined />} aria-label={`删除会话 ${toText(item.title || '未命名会话')}`} disabled={analysisIsRunning(item.activeTurnStatus)} /></Popconfirm></div>)}</div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无历史会话" />}
|
||||
</aside>
|
||||
<section className="panel analysis-chat-panel">
|
||||
<div className="analysis-conversation" aria-live="polite">
|
||||
{turns.map((turn, index) => <AnalysisTurn key={String(turn.id || index)} turn={turn} onRetry={(id) => void retryTurn(turns.find(item => String(item.id || '') === id) || turn)} onResume={id => void followTurn(id, String(turn.question || ''))} onGenerateReport={() => void submit(generateReportPrompt(turn))} retryDisabled={busy} />)}
|
||||
{lastTurn && <AnalysisTurn turn={lastTurn} onRetry={() => void retryTurn(lastTurn)} onResume={id => void followTurn(id, String(lastTurn.question || ''))} onGenerateReport={() => void submit(generateReportPrompt(lastTurn))} retryDisabled={busy} />}
|
||||
{busy && <div className="analysis-progress"><Spin size="small" />正在分析…<Button size="small" danger onClick={() => void cancelTurn()}>停止分析</Button></div>}
|
||||
{turns.map((turn, index) => <AnalysisTurn key={String(turn.id || index)} turn={turn} onRetry={(id) => void retryTurn(turns.find(item => String(item.id || '') === id) || turn)} onResume={id => { if (!historyLoading) void followTurn(id, String(turn.question || '')); }} onGenerateReport={() => void submit(generateReportPrompt(turn))} retryDisabled={busy || historyLoading} />)}
|
||||
{lastTurn && <AnalysisTurn turn={lastTurn} onRetry={() => void retryTurn(lastTurn)} onResume={id => { if (!historyLoading) void followTurn(id, String(lastTurn.question || '')); }} onGenerateReport={() => void submit(generateReportPrompt(lastTurn))} retryDisabled={busy || historyLoading} />}
|
||||
{busy && <div className="analysis-progress"><span>{streamProgress || '正在分析…'}</span><Button size="small" danger onClick={() => void cancelTurn()}>停止分析</Button></div>}
|
||||
{!turns.length && !lastTurn && !busy && <div className="analysis-empty"><RobotOutlined /><strong>想了解哪些质量情况?</strong><span>例如:9月汽车交通的合格率为什么下降?</span></div>}
|
||||
<div ref={conversationEnd} />
|
||||
</div>
|
||||
<div className="analysis-composer">
|
||||
<Input.TextArea id="analysis-query" value={query} onChange={event => setQuery(event.target.value)} autoSize={{ minRows: 2, maxRows: 5 }} maxLength={1600} aria-label="质量问题" placeholder="直接描述问题,或继续追问…" onPressEnter={event => { if (!event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); void submit(); } }} />
|
||||
<div className="ai-actions"><span>Enter 发送 · Shift + Enter 换行</span><div className="analysis-composer-buttons">{user.roles.includes('SYSTEM_ADMIN') && <AnalysisApiSettings onUnauthorized={onUnauthorized} />}<Button type="primary" aria-label="发送" loading={busy} disabled={!query.trim() || busy} onClick={() => void submit()}>发送</Button></div></div>
|
||||
<Input.TextArea id="analysis-query" disabled={historyLoading} value={query} onChange={event => setQuery(event.target.value)} autoSize={{ minRows: 2, maxRows: 5 }} maxLength={1600} aria-label="质量问题" placeholder="直接描述问题,或继续追问…" onPressEnter={event => { if (!event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); void submit(); } }} />
|
||||
<div className="ai-actions"><span>Enter 发送 · Shift + Enter 换行</span><div className="analysis-composer-buttons">{user.roles.includes('SYSTEM_ADMIN') && <AnalysisApiSettings onUnauthorized={onUnauthorized} />}<Button type="primary" aria-label="发送" loading={busy} disabled={!query.trim() || busy || historyLoading} onClick={() => void submit()}>发送</Button></div></div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -1323,6 +1426,7 @@ function AnalysisTurn({ turn, onResume, onRetry, onGenerateReport, retryDisabled
|
||||
: failure;
|
||||
return <article className="analysis-turn">
|
||||
{question && <div className="analysis-question"><p>{question}</p></div>}
|
||||
<AnalysisProcess turn={turn} />
|
||||
{(answer || !resumable || !retryDisabled) && <div className="analysis-answer">
|
||||
{answer ? <AiMarkdown content={answer} className="ai-answer" /> : <p className={resumable ? 'analysis-chat-notice' : undefined}>{resumable ? '分析任务仍在运行,尚未返回完整回答。' : emptyStatus}</p>}
|
||||
{status === 'PARTIAL' && <p className="analysis-chat-notice">部分分析尚未完成,可以重试或继续追问。</p>}
|
||||
@@ -1331,7 +1435,7 @@ function AnalysisTurn({ turn, onResume, onRetry, onGenerateReport, retryDisabled
|
||||
{!reportMarkdown.trim() && engine === 'NAO' && status === 'COMPLETED' && answer && onGenerateReport && <Button type="text" size="small" icon={<DownloadOutlined />} disabled={retryDisabled} onClick={onGenerateReport}>生成报告</Button>}
|
||||
{!reportMarkdown.trim() && engine !== 'NAO' && answer && ['COMPLETED', 'PARTIAL'].includes(status) && <AnalysisReportExport turn={turn} />}
|
||||
{['FAILED', 'CANCELLED', 'PARTIAL'].includes(status) && typeof turn.id === 'string' && onRetry && <Button size="small" type="text" disabled={retryDisabled} onClick={() => onRetry(String(turn.id))}>重新分析</Button>}
|
||||
{resumable && typeof turn.id === 'string' && onResume && <Button size="small" type="text" disabled={retryDisabled} onClick={() => onResume(String(turn.id))}>继续分析</Button>}
|
||||
{resumable && !retryDisabled && typeof turn.id === 'string' && onResume && <Button size="small" type="text" onClick={() => onResume(String(turn.id))}>继续分析</Button>}
|
||||
</div>
|
||||
</div>}
|
||||
</article>;
|
||||
@@ -1377,7 +1481,7 @@ function ResourceTab({ onUnauthorized }: { onUnauthorized: (error: unknown) => b
|
||||
return <div className="resource-tab">
|
||||
{error && <Alert type="error" showIcon message="审计记录读取失败" description={error} />}
|
||||
<div className="resource-toolbar"><strong>审计事件</strong><span>{result?.total !== undefined ? `共 ${result.total} 条` : `${items.length} 条`}</span><Button icon={<ReloadOutlined />} onClick={() => void load(page)}>刷新</Button></div>
|
||||
{loading ? <div className="loading-panel"><Spin />正在读取…</div> : <DynamicTable items={items} paginate={false} />}
|
||||
{loading ? <div className="loading-panel"><Spin />正在读取…</div> : <DynamicTable items={items} paginate={false} indexOffset={(page - 1) * TABLE_PAGE_SIZE} />}
|
||||
{total > TABLE_PAGE_SIZE && <Pagination className="records-pagination" current={page} pageSize={TABLE_PAGE_SIZE} total={total} showTotal={count => `共 ${count} 条`} onChange={setPage} />}
|
||||
</div>;
|
||||
}
|
||||
|
||||
+106
-73
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Alert, App, Button, Checkbox, Empty, Form, Input, InputNumber, Modal, Progress, Select, Spin, Steps, Table, Tag } from 'antd';
|
||||
import { Alert, App, Button, Checkbox, Empty, Form, Input, InputNumber, Modal, Progress, Select, Spin, Steps, Tag } from 'antd';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import { ArrowRightOutlined, DeleteOutlined, FileExcelOutlined, ReloadOutlined, SwapOutlined, UndoOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import { api, collectionItems } from './api';
|
||||
import type { AuthUser, SourceItem } from './types';
|
||||
@@ -41,100 +42,131 @@ function WorkflowOperationFeedback({ operation, error, busy, onResume }: { opera
|
||||
</section>;
|
||||
}
|
||||
|
||||
function SimplifiedDataWorkflow({ options, workflowStatus, onUnauthorized, onRefresh }: { options: SourceUploadOptions; workflowStatus: DataWorkflowStatus; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
export type PendingSourceDeletion = { ids: string[]; releaseId: string | null };
|
||||
type SourceDraft = { id: string; file: File; workbook: WorkbookPreview; stage: DataStage; year: number; month: number; sheetName: string; headerRow: number; fieldMap: Record<string, string>; mode: 'ADD' | 'REPLACE'; targetId: string; scopeCode: string };
|
||||
|
||||
function SimplifiedDataWorkflow({ options, workflowStatus, pendingDeletion, onDeleted, onBusyChange, onUnauthorized, onRefresh }: { options: SourceUploadOptions; workflowStatus: DataWorkflowStatus; pendingDeletion: PendingSourceDeletion; onDeleted: (ids: string[]) => void; onBusyChange: (busy: boolean) => void; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
const { message } = App.useApp();
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const configuredUploadId = useRef<string | null>(null);
|
||||
const [workbook, setWorkbook] = useState<WorkbookPreview | null>(null);
|
||||
const [stage, setStage] = useState<DataStage>('black');
|
||||
const [year, setYear] = useState(new Date().getFullYear()); const [month, setMonth] = useState(new Date().getMonth() + 1);
|
||||
const [sheetName, setSheetName] = useState(''); const [headerRow, setHeaderRow] = useState(1); const [fieldMap, setFieldMap] = useState<Record<string, string>>({});
|
||||
const [mode, setMode] = useState<'ADD' | 'REPLACE'>('ADD'); const [targetId, setTargetId] = useState(''); const [scopeCode, setScopeCode] = useState(options.scopes[0] || 'ALL');
|
||||
const [configuredSourceId, setConfiguredSourceId] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState('');
|
||||
const uploadOperation = useDataWorkflowOperation('source-import', () => { onRefresh(); message.success('来源已导入,报表已更新'); });
|
||||
const recalcOperation = useDataWorkflowOperation('recalculate', () => { onRefresh(); message.success('已按当前来源重新计算并更新报表'); });
|
||||
const configured = useRef(new Map<string, { signature: string; sourceId: string }>());
|
||||
const consumed = useRef(new Set<string>());
|
||||
const [drafts, setDrafts] = useState<SourceDraft[]>([]);
|
||||
const [activeId, setActiveId] = useState('');
|
||||
const [reading, setReading] = useState<{ done: number; total: number } | null>(null);
|
||||
const [busy, setBusy] = useState(false); const [error, setError] = useState('');
|
||||
const uploadOperation = useDataWorkflowOperation('source-import', () => { setDrafts([]); setActiveId(''); configured.current.clear(); consumed.current.clear(); onRefresh(); message.success('所选来源已统一导入,报表已更新'); });
|
||||
const recalcOperation = useDataWorkflowOperation('recalculate', value => { if (Array.isArray(value.sourceIds)) onDeleted(value.sourceIds.map(String)); onRefresh(); message.success('报表已更新'); });
|
||||
const active = drafts.find(item => item.id === activeId) || drafts[0];
|
||||
const workbook = active?.workbook || null;
|
||||
const stage = active?.stage || 'black'; const year = active?.year || new Date().getFullYear(); const month = active?.month || 1;
|
||||
const sheetName = active?.sheetName || ''; const headerRow = active?.headerRow || 1; const fieldMap = active?.fieldMap || {};
|
||||
const mode = active?.mode || 'ADD'; const targetId = active?.targetId || ''; const scopeCode = active?.scopeCode || options.scopes[0] || 'ALL';
|
||||
const patch = (values: Partial<SourceDraft>) => { if (active) setDrafts(previous => previous.map(item => item.id === active.id ? { ...item, ...values } : item)); };
|
||||
const setWorkbook = (value: WorkbookPreview) => patch({ workbook: value });
|
||||
const setStage = (value: DataStage) => patch({ stage: value }); const setYear = (value: number) => patch({ year: value }); const setMonth = (value: number) => patch({ month: value });
|
||||
const setSheetName = (value: string) => patch({ sheetName: value }); const setHeaderRow = (value: number) => patch({ headerRow: value });
|
||||
const setFieldMap = (value: Record<string, string>) => patch({ fieldMap: value }); const setMode = (value: 'ADD' | 'REPLACE') => patch({ mode: value });
|
||||
const setTargetId = (value: string) => patch({ targetId: value }); const setScopeCode = (value: string) => patch({ scopeCode: value });
|
||||
const fields = options.fields[stage] || []; const headers = workbook?.preview.headers || [];
|
||||
const missing = fields.filter(field => field.required && !fieldMap[field.name]);
|
||||
const duplicate = Object.values(fieldMap).length !== new Set(Object.values(fieldMap)).size;
|
||||
const target = options.targets.find(item => item.documentId === targetId);
|
||||
const importBusy = busy || uploadOperation.busy;
|
||||
const missing = fields.filter(field => field.required && !fieldMap[field.name]); const duplicate = Object.values(fieldMap).length !== new Set(Object.values(fieldMap)).size;
|
||||
const importBusy = busy || uploadOperation.busy || recalcOperation.busy;
|
||||
useEffect(() => { onBusyChange(importBusy); return () => onBusyChange(false); }, [importBusy, onBusyChange]);
|
||||
const hasImportCapability = workflowStatus.capabilities?.canImport !== false;
|
||||
const needsNewFile = Boolean(workbook && configuredUploadId.current === workbook.uploadId && !configuredSourceId);
|
||||
const canImport = Boolean(hasImportCapability && !needsNewFile && workbook && !missing.length && !duplicate && (mode !== 'REPLACE' || target));
|
||||
const draftReady = (item: SourceDraft) => (options.fields[item.stage] || []).filter(field => field.required).every(field => item.fieldMap[field.name]) && Object.values(item.fieldMap).length === new Set(Object.values(item.fieldMap)).size && (item.mode !== 'REPLACE' || options.targets.some(target => target.documentId === item.targetId));
|
||||
const slots = drafts.map(item => `${item.year}:${item.month}:${item.stage}:${item.scopeCode}`);
|
||||
const duplicateSlots = new Set(slots).size !== slots.length;
|
||||
const canImport = hasImportCapability && drafts.length > 0 && drafts.every(draftReady) && !duplicateSlots && !pendingDeletion.ids.length;
|
||||
const reportError = (value: unknown) => { if (!onUnauthorized(value)) setError(failure(value)); };
|
||||
const invalidateConfiguredSource = () => {
|
||||
setConfiguredSourceId('');
|
||||
};
|
||||
const readFile = async (file?: File) => {
|
||||
if (!file) return; setBusy(true); setError(''); setConfiguredSourceId('');
|
||||
try {
|
||||
const result = await api.previewSourceWorkbook(file);
|
||||
setWorkbook(result); configuredUploadId.current = null; setSheetName(result.preview.sheetName); setHeaderRow(result.preview.headerRow);
|
||||
const scores = (['black', 'bright'] as DataStage[]).map(value => {
|
||||
const required = (options.fields[value] || []).filter(field => field.required);
|
||||
const matched = matchFields(options.fields[value] || [], result.preview.headers);
|
||||
return { stage: value, score: required.length ? required.filter(field => matched[field.name]).length / required.length : 0 };
|
||||
});
|
||||
const detected = scores.sort((a, b) => b.score - a.score)[0];
|
||||
const nextStage = detected.score > 0 ? detected.stage : stage;
|
||||
setStage(nextStage); setFieldMap(matchFields(options.fields[nextStage] || [], result.preview.headers));
|
||||
if (mode === 'ADD') {
|
||||
const monthMatch = file.name.match(/(?:^|\D)(0?[1-9]|1[0-2])月/);
|
||||
if (monthMatch) setMonth(Number(monthMatch[1]));
|
||||
}
|
||||
} catch (value) { reportError(value); }
|
||||
finally { setBusy(false); if (input.current) input.current.value = ''; }
|
||||
const removeDraft = (id: string) => { setDrafts(previous => previous.filter(item => item.id !== id)); configured.current.delete(id); };
|
||||
const readFiles = async (files: File[]) => {
|
||||
if (!files.length || importBusy) return;
|
||||
if (files.length + drafts.length > 50) { setError('一次最多导入50个文件'); if (input.current) input.current.value = ''; return; }
|
||||
setBusy(true); setError(''); const failures: string[] = [];
|
||||
const known = new Set(drafts.map(item => `${item.file.name}:${item.file.size}:${item.file.lastModified}`));
|
||||
const selected = files.filter(file => { const key = `${file.name}:${file.size}:${file.lastModified}`; if (known.has(key)) return false; known.add(key); return true; });
|
||||
setReading({ done: 0, total: selected.length });
|
||||
for (let index = 0; index < selected.length; index += 2) {
|
||||
const results = await Promise.all(selected.slice(index, index + 2).map(async file => {
|
||||
try {
|
||||
const result = await api.previewSourceWorkbook(file);
|
||||
const scores = (['black', 'bright'] as DataStage[]).map(value => { const required = (options.fields[value] || []).filter(field => field.required); const matched = matchFields(options.fields[value] || [], result.preview.headers); return { stage: value, score: required.length ? required.filter(field => matched[field.name]).length / required.length : 0 }; });
|
||||
const detected = scores.sort((a, b) => b.score - a.score)[0].stage;
|
||||
const nextMonth = Number(file.name.match(/(?:^|\D)(0?[1-9]|1[0-2])月/)?.[1] || new Date().getMonth() + 1);
|
||||
const nextYear = Number(file.name.match(/(20\d{2})年/)?.[1] || new Date().getFullYear());
|
||||
return { id: crypto.randomUUID(), file, workbook: result, stage: detected, year: nextYear, month: nextMonth, sheetName: result.preview.sheetName, headerRow: result.preview.headerRow, fieldMap: matchFields(options.fields[detected] || [], result.preview.headers), mode: 'ADD' as const, targetId: '', scopeCode: options.scopes[0] || 'ALL' };
|
||||
} catch (value) { if (!onUnauthorized(value)) failures.push(`${file.name}:${failure(value)}`); return null; }
|
||||
}));
|
||||
const ready = results.filter(item => item !== null);
|
||||
setDrafts(previous => [...previous, ...ready]);
|
||||
setReading({ done: Math.min(index + 2, selected.length), total: selected.length });
|
||||
}
|
||||
if (failures.length) setError(`以下文件未加入导入列表,可重新选择:${failures.join(';')}`);
|
||||
setReading(null); setBusy(false); if (input.current) input.current.value = '';
|
||||
};
|
||||
const changePreview = async (nextSheet: string, nextHeader = headerRow, nextStage = stage, preferredMap?: Record<string, string>) => {
|
||||
if (!workbook) return; setBusy(true); setError(''); invalidateConfiguredSource();
|
||||
if (!workbook) return; setBusy(true); setError('');
|
||||
try {
|
||||
const result = await api.sourceWorkbookPreview(workbook.uploadId, { sheetName: nextSheet, headerRow: nextHeader, stage: nextStage });
|
||||
setWorkbook(result); setSheetName(result.preview.sheetName); setHeaderRow(result.preview.headerRow);
|
||||
const previous = preferredMap || fieldMap;
|
||||
setFieldMap({ ...matchFields(options.fields[nextStage] || [], result.preview.headers), ...Object.fromEntries(Object.entries(previous).filter(([, header]) => result.preview.headers.includes(header))) });
|
||||
} catch (value) { reportError(value); }
|
||||
finally { setBusy(false); }
|
||||
} catch (value) { reportError(value); } finally { setBusy(false); }
|
||||
};
|
||||
const importAndUpdate = async () => {
|
||||
if (!workbook || !canImport) return; setBusy(true); setError('');
|
||||
if (!canImport || importBusy) return; setBusy(true); setError('');
|
||||
try {
|
||||
let sourceId = configuredSourceId;
|
||||
if (!sourceId) {
|
||||
const configured = await api.configureSourceWorkbook({ uploadId: workbook.uploadId, stage, year, month, sheetName, headerRow, fieldMap, mode, expectedCurrentReleaseId: workflowStatus.currentReleaseId ?? options.currentReleaseId, ...(target ? { targetDocumentId: target.documentId, targetRevisionId: target.revisionId } : {}), reason: mode === 'REPLACE' ? '测试阶段更新来源数据' : '测试阶段导入来源数据', scopeCode });
|
||||
sourceId = configured.source.id; configuredUploadId.current = workbook.uploadId; setConfiguredSourceId(sourceId);
|
||||
const sourceIds: string[] = [];
|
||||
for (const draft of drafts) {
|
||||
const target = options.targets.find(item => item.documentId === draft.targetId);
|
||||
const body = { stage: draft.stage, year: draft.year, month: draft.month, sheetName: draft.sheetName, headerRow: draft.headerRow, fieldMap: draft.fieldMap, mode: draft.mode, expectedCurrentReleaseId: workflowStatus.currentReleaseId ?? options.currentReleaseId, ...(draft.mode === 'REPLACE' && target ? { targetDocumentId: target.documentId, targetRevisionId: target.revisionId } : {}), reason: '批量导入来源数据', scopeCode: draft.scopeCode };
|
||||
const signature = JSON.stringify(body); const prior = configured.current.get(draft.id);
|
||||
if (prior?.signature === signature) { sourceIds.push(prior.sourceId); continue; }
|
||||
let uploadId = draft.workbook.uploadId;
|
||||
if (consumed.current.has(uploadId)) uploadId = (await api.previewSourceWorkbook(draft.file)).uploadId;
|
||||
const result = await api.configureSourceWorkbook({ ...body, uploadId });
|
||||
consumed.current.add(uploadId); configured.current.set(draft.id, { signature, sourceId: result.source.id }); sourceIds.push(result.source.id);
|
||||
}
|
||||
await uploadOperation.start(() => api.importDataWorkflow({ sourceIds: [sourceId] }));
|
||||
} catch (value) { reportError(value); }
|
||||
finally { setBusy(false); }
|
||||
await uploadOperation.start(() => api.importDataWorkflow({ sourceIds }));
|
||||
} catch (value) { reportError(value); } finally { setBusy(false); }
|
||||
};
|
||||
const recalculate = async () => {
|
||||
setError('');
|
||||
try { await recalcOperation.start(() => api.recalculateDataWorkflow()); }
|
||||
try { await recalcOperation.start(() => pendingDeletion.ids.length ? api.deleteDataWorkflowSources({ sourceIds: pendingDeletion.ids, expectedCurrentReleaseId: pendingDeletion.releaseId }) : api.recalculateDataWorkflow()); }
|
||||
catch (value) { reportError(value); }
|
||||
};
|
||||
return <div className="nc-simplified-intake">
|
||||
<section className="panel nc-simple-upload-panel">
|
||||
<div className="nc-simple-upload-heading"><div><span className="nc-eyebrow">测试数据维护</span><h2>导入来源并更新报表</h2><p>Excel 标准表头自动识别;如有列未识别,可展开“列识别与预览”修正。</p></div><div className="nc-simple-upload-actions">{workflowStatus.capabilities?.canRecalculate !== false && <Button icon={<ReloadOutlined />} disabled={importBusy} loading={recalcOperation.busy} onClick={() => void recalculate()}>按当前来源重新计算</Button>}</div></div>
|
||||
<div className="nc-simple-upload-heading"><div><span className="nc-eyebrow">测试数据维护</span><h2>导入来源并更新报表</h2><p>支持一次选择多个 Excel 文件,分别核对年月与阶段后统一导入。</p></div><div className="nc-simple-upload-actions">{workflowStatus.capabilities?.canRecalculate !== false && <Button icon={<ReloadOutlined />} disabled={importBusy} loading={recalcOperation.busy} onClick={() => void recalculate()}>{pendingDeletion.ids.length ? `更新报表(${pendingDeletion.ids.length}项删除)` : '更新报表'}</Button>}</div></div>
|
||||
{!hasImportCapability && <Alert showIcon type="info" message="当前账号没有导入权限" description="可查看来源;导入和更新报表需要发布权限。" />}
|
||||
{error && <Alert showIcon type="error" message="操作未完成,输入内容已保留" description={error} />}
|
||||
{needsNewFile && <Alert showIcon type="info" message="导入设置已修改" description="这份文件已提交过导入,请点击“更换文件”重新选择文件后再导入。" />}
|
||||
{!workbook ? <div className="nc-file-drop nc-simple-file-drop"><FileExcelOutlined /><h3>选择 Excel 来源文件</h3><p>系统自动识别标准表头,文件年月可在下方设置。</p><input className="visually-hidden-file" ref={input} type="file" accept=".xlsx" onChange={event => void readFile(event.target.files?.[0])} aria-label="选择质量数据Excel文件" />{hasImportCapability && <Button type="primary" icon={<UploadOutlined />} loading={busy} onClick={() => input.current?.click()}>选择 Excel 文件</Button>}</div> : <>
|
||||
<div className="nc-simple-file-line"><FileExcelOutlined /><strong>{workbook.sourceFile}</strong>{hasImportCapability && <Button type="link" disabled={importBusy} onClick={() => { setWorkbook(null); setConfiguredSourceId(''); }}>更换文件</Button>}</div>
|
||||
<input className="visually-hidden-file" ref={input} type="file" multiple accept=".xlsx" onChange={event => void readFiles(Array.from(event.target.files || []))} aria-label="选择质量数据Excel文件" />
|
||||
{pendingDeletion.ids.length > 0 && <Alert type="warning" showIcon message={`有 ${pendingDeletion.ids.length} 个来源待删除,报表尚未改变`} description="可继续标记或撤销删除,完成后点击“更新报表”。请先处理待删除文件,再导入新文件。" />}
|
||||
{reading && <div className="nc-section-title"><Spin size="small" /><span>正在上传并识别文件 {reading.done} / {reading.total}</span></div>}
|
||||
{drafts.length > 0 && <><div className="nc-section-title"><strong>待导入文件 · {drafts.length} 个</strong><Button disabled={importBusy} icon={<UploadOutlined />} onClick={() => input.current?.click()}>继续添加文件</Button></div><Table size="small" rowKey="id" pagination={false} scroll={{ x: 700 }} dataSource={drafts} columns={[
|
||||
{ title: '文件', key: 'file', render: (_, item) => <Button type="link" onClick={() => setActiveId(item.id)}>{item.workbook.sourceFile}</Button> },
|
||||
{ title: '阶段', key: 'stage', render: (_, item) => stageName(item.stage) },
|
||||
{ title: '统计期间', key: 'period', render: (_, item) => `${item.year}年${item.month}月` },
|
||||
{ title: '识别结果', key: 'validation', render: (_, item) => draftReady(item) ? <Tag color="green">已识别</Tag> : <Tag color="orange">需核对列或替换对象</Tag> },
|
||||
{ title: '操作', key: 'action', render: (_, item) => <Button type="link" disabled={importBusy} onClick={() => removeDraft(item.id)}>移除</Button> },
|
||||
]} /></>}
|
||||
{duplicateSlots && <Alert type="warning" showIcon message="多个文件对应同一期间、阶段和范围,请调整或移除重复文件后再导入" />}
|
||||
{!workbook ? <div className="nc-file-drop nc-simple-file-drop"><FileExcelOutlined /><h3>选择 Excel 来源文件</h3><p>可多选文件;系统自动识别阶段和月份,每个文件都可单独调整。</p>{hasImportCapability && <Button type="primary" icon={<UploadOutlined />} loading={busy} onClick={() => input.current?.click()}>选择 Excel 文件</Button>}</div> : <>
|
||||
<div className="nc-simple-file-line"><FileExcelOutlined /><strong>{workbook.sourceFile}</strong>{hasImportCapability && <Button type="link" disabled={importBusy} onClick={() => { if (active) removeDraft(active.id); }}>移除此文件</Button>}</div>
|
||||
<div className="nc-simple-upload-fields">
|
||||
<label>导入方式<Select disabled={importBusy} value={mode} options={[{ value: 'ADD', label: '新增数据' }, { value: 'REPLACE', label: '替换已有数据' }]} onChange={value => { setMode(value); invalidateConfiguredSource(); }} /></label>
|
||||
<label>数据阶段<Select disabled={importBusy} value={stage} options={[{ value: 'black', label: '黑片' }, { value: 'bright', label: '亮片' }]} onChange={value => { setStage(value); invalidateConfiguredSource(); setFieldMap(matchFields(options.fields[value] || [], headers)); }} /></label>
|
||||
<label>统计年份<InputNumber disabled={importBusy} min={2000} max={2100} value={year} onChange={value => { if (value) setYear(value); invalidateConfiguredSource(); }} /></label>
|
||||
<label>统计月份<Select disabled={importBusy} value={month} options={Array.from({ length: 12 }, (_, index) => ({ value: index + 1, label: `${index + 1}月` }))} onChange={value => { setMonth(value); invalidateConfiguredSource(); }} /></label>
|
||||
{options.scopes.length > 1 && <label>数据范围<Select disabled={importBusy} value={scopeCode} options={options.scopes.map(value => ({ value, label: value === 'ALL' ? '全部范围' : value }))} onChange={value => { setScopeCode(value); invalidateConfiguredSource(); }} /></label>}
|
||||
{mode === 'REPLACE' && <label className="nc-simple-replace-target">替换对象<Select {...readableSelectPopup} disabled={importBusy} showSearch optionFilterProp="label" value={targetId || undefined} placeholder="选择已发布期间和阶段" options={options.targets.map(item => ({ value: item.documentId, label: `${item.year}年${item.month}月 · ${stageName(item.stage)} · ${item.sourceFile}` }))} onChange={value => { setTargetId(value); invalidateConfiguredSource(); }} /></label>}
|
||||
<label>导入方式<Select disabled={importBusy} value={mode} options={[{ value: 'ADD', label: '新增数据' }, { value: 'REPLACE', label: '替换已有数据' }]} onChange={value => { setMode(value); }} /></label>
|
||||
<label>数据阶段<Select disabled={importBusy} value={stage} options={[{ value: 'black', label: '黑片' }, { value: 'bright', label: '亮片' }]} onChange={value => { setStage(value); setFieldMap(matchFields(options.fields[value] || [], headers)); }} /></label>
|
||||
<label>统计年份<InputNumber disabled={importBusy} min={2000} max={2100} value={year} onChange={value => { if (value) setYear(value); }} /></label>
|
||||
<label>统计月份<Select disabled={importBusy} value={month} options={Array.from({ length: 12 }, (_, index) => ({ value: index + 1, label: `${index + 1}月` }))} onChange={value => { setMonth(value); }} /></label>
|
||||
{options.scopes.length > 1 && <label>数据范围<Select disabled={importBusy} value={scopeCode} options={options.scopes.map(value => ({ value, label: value === 'ALL' ? '全部范围' : value }))} onChange={value => { setScopeCode(value); }} /></label>}
|
||||
{mode === 'REPLACE' && <label className="nc-simple-replace-target">替换对象<Select {...readableSelectPopup} disabled={importBusy} showSearch optionFilterProp="label" value={targetId || undefined} placeholder="选择已发布期间和阶段" options={options.targets.map(item => ({ value: item.documentId, label: `${item.year}年${item.month}月 · ${stageName(item.stage)} · ${item.sourceFile}` }))} onChange={value => { setTargetId(value); }} /></label>}
|
||||
</div>
|
||||
<details className="nc-advanced-import-settings"><summary>列识别与预览</summary>
|
||||
<div className="nc-form-grid"><label>工作表<Select disabled={importBusy} value={sheetName} options={workbook.sheets.map(item => ({ value: item.sheetName, label: item.sheetName }))} onChange={value => void changePreview(value)} /></label><label>表头所在行<InputNumber disabled={importBusy} min={1} max={100} value={headerRow} onChange={value => { if (value) setHeaderRow(value); invalidateConfiguredSource(); }} onBlur={() => { if (workbook.preview.headerRow !== headerRow) void changePreview(sheetName, headerRow); }} /></label></div>
|
||||
<div className="nc-section-title"><h3>业务字段对应 Excel 列</h3><span>{missing.length ? `还有 ${missing.length} 个必填字段待匹配` : duplicate ? '同一 Excel 列不能重复对应' : '已匹配'}</span></div><ColumnMatching disabled={importBusy} fields={fields} headers={headers} value={fieldMap} onChange={value => { setFieldMap(value); invalidateConfiguredSource(); }} />
|
||||
<div className="nc-form-grid"><label>工作表<Select disabled={importBusy} value={sheetName} options={workbook.sheets.map(item => ({ value: item.sheetName, label: item.sheetName }))} onChange={value => void changePreview(value)} /></label><label>表头所在行<InputNumber disabled={importBusy} min={1} max={100} value={headerRow} onChange={value => { if (value) setHeaderRow(value); }} onBlur={() => { if (workbook.preview.headerRow !== headerRow) void changePreview(sheetName, headerRow); }} /></label></div>
|
||||
<div className="nc-section-title"><h3>业务字段对应 Excel 列</h3><span>{missing.length ? `还有 ${missing.length} 个必填字段待匹配` : duplicate ? '同一 Excel 列不能重复对应' : '已匹配'}</span></div><ColumnMatching disabled={importBusy} fields={fields} headers={headers} value={fieldMap} onChange={value => { setFieldMap(value); }} />
|
||||
<h3>原表预览</h3><SampleTable headers={headers} rows={workbook.preview.sampleRows.map(row => row.values)} />
|
||||
</details>
|
||||
{missing.length > 0 && <Alert showIcon type="warning" message="有必填列尚未识别" description={`请展开“列识别与预览”完成:${missing.map(item => item.name).join('、')}`} />}
|
||||
<div className="nc-simple-submit-row"><span>{mode === 'REPLACE' ? '替换后会按当前规则重算并更新对应报表。' : `${year}年${String(month).padStart(2, '0')}月 · ${stageName(stage)} · 完成后自动刷新报表`}</span>{hasImportCapability && <Button type="primary" size="large" loading={busy || uploadOperation.busy} disabled={!canImport || busy || uploadOperation.busy} onClick={() => void importAndUpdate()}>导入并更新报表</Button>}</div>
|
||||
<div className="nc-simple-submit-row"><span>{mode === 'REPLACE' ? '替换后会按当前规则重算并更新对应报表。' : `${year}年${String(month).padStart(2, '0')}月 · ${stageName(stage)} · 完成后自动刷新报表`}</span>{hasImportCapability && <Button type="primary" size="large" loading={busy || uploadOperation.busy} disabled={!canImport || busy || uploadOperation.busy} onClick={() => void importAndUpdate()}>{`导入 ${drafts.length} 个文件并更新报表`}</Button>}</div>
|
||||
</>}
|
||||
<WorkflowOperationFeedback operation={uploadOperation.operation} error={uploadOperation.error} busy={uploadOperation.busy} onResume={uploadOperation.resume} />
|
||||
<WorkflowOperationFeedback operation={recalcOperation.operation} error={recalcOperation.error} busy={recalcOperation.busy} onResume={recalcOperation.resume} />
|
||||
@@ -148,7 +180,7 @@ function ValidationNotice({ value }: { value: unknown }) {
|
||||
return errors.length ? <Alert showIcon type="warning" message="校验仍有需要处理的事项" description={<ul className="nc-issue-list">{errors.map((item, index) => <li key={index}>{txt(item)}</li>)}</ul>} /> : result.complete === true ? <Alert showIcon type="success" message="来源及对应关系校验通过" /> : result.complete === false ? <Alert showIcon type="warning" message="候选校验尚未通过" description="请核对来源是否齐备,以及基础数据和对应关系是否完整。" /> : null;
|
||||
}
|
||||
|
||||
export function DataWorkflowHub({ user, sources, currentReleaseId, onUnauthorized, onRefresh }: { user: AuthUser; sources: SourceItem[]; currentReleaseId: string | null; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
export function DataWorkflowHub({ user, sources, currentReleaseId, pendingDeletion, onDeleted, onBusyChange, onUnauthorized, onRefresh }: { user: AuthUser; sources: SourceItem[]; currentReleaseId: string | null; pendingDeletion: PendingSourceDeletion; onDeleted: (ids: string[]) => void; onBusyChange: (busy: boolean) => void; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
const { message } = App.useApp();
|
||||
const [mode, setMode] = useState<'ADD' | 'REPLACE' | 'REBUILD' | null>(null);
|
||||
const [options, setOptions] = useState<SourceUploadOptions | null>(null);
|
||||
@@ -177,7 +209,7 @@ export function DataWorkflowHub({ user, sources, currentReleaseId, onUnauthorize
|
||||
const opened = mode !== null || Boolean(resumeId);
|
||||
const open = (next: 'ADD' | 'REPLACE' | 'REBUILD') => { setMode(next); setResumeId(''); void loadOptions(); };
|
||||
if (!workflowStatusLoaded) return <section className="panel nc-operation-status"><div><strong>读取当前维护模式</strong><span>正在加载可执行操作</span></div><Spin /></section>;
|
||||
if (workflowStatus?.simplified === true && workflowStatus.mode === 'TEST' && options) return <SimplifiedDataWorkflow options={options} workflowStatus={workflowStatus} onUnauthorized={onUnauthorized} onRefresh={onRefresh} />;
|
||||
if (workflowStatus?.simplified === true && workflowStatus.mode === 'TEST' && options) return <SimplifiedDataWorkflow options={options} workflowStatus={workflowStatus} pendingDeletion={pendingDeletion} onDeleted={onDeleted} onBusyChange={onBusyChange} onUnauthorized={onUnauthorized} onRefresh={onRefresh} />;
|
||||
return <>
|
||||
<section className="nc-intake-start panel">
|
||||
<div className="nc-intake-intro"><span className="nc-eyebrow">日常数据维护</span><h2>选择文件,核对后发布</h2><p>文件名可以保持原样。黑片或亮片、统计年月和表头均在下一步选择。</p></div>
|
||||
@@ -191,7 +223,7 @@ export function DataWorkflowHub({ user, sources, currentReleaseId, onUnauthorize
|
||||
</>;
|
||||
}
|
||||
|
||||
export function SourceFilesPanel({ user, sources, loading, onUnauthorized, onRefresh }: { user: AuthUser; sources: SourceItem[]; loading: boolean; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
export function SourceFilesPanel({ user, sources, loading, pendingIds, maintenanceBusy, onToggleDelete, onClearDeletes, onUnauthorized, onRefresh }: { user: AuthUser; sources: SourceItem[]; loading: boolean; pendingIds: string[]; maintenanceBusy: boolean; onToggleDelete: (id: string) => void; onClearDeletes: () => void; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
const { message } = App.useApp();
|
||||
const [showDeleted, setShowDeleted] = useState(false);
|
||||
const [deleted, setDeleted] = useState<SourceDeletionPreview[]>([]);
|
||||
@@ -226,21 +258,22 @@ export function SourceFilesPanel({ user, sources, loading, onUnauthorized, onRef
|
||||
};
|
||||
return <>
|
||||
<section className="panel section-panel nc-source-files">
|
||||
<div className="resource-toolbar"><strong>{showDeleted ? '已删除的来源文件' : '已接收的来源文件'}</strong><span>{showDeleted ? `${deleted.length} 个文件 · 原件和处理记录保留` : simplified ? `${sources.length} 个文件 · 来源变化会自动重算并更新报表` : `${sources.length} 个文件 · 上传或接收不等于已经发布`}</span>{canOperate && <Checkbox checked={showDeleted} onChange={event => setShowDeleted(event.target.checked)}>查看已删除来源</Checkbox>}</div>
|
||||
{simplified && <p className="nc-source-maintenance-note">删除会从当前数据中移除来源并更新报表;恢复会自动重新计算。原文件和处理记录保留。</p>}
|
||||
{deletedError && showDeleted && <Alert showIcon type="error" message="已删除来源读取失败" description={deletedError} action={<Button size="small" onClick={() => void loadDeleted()}>重试</Button>} />}
|
||||
<div className="resource-toolbar"><strong>{showDeleted ? '已删除的来源文件' : '已接收的来源文件'}</strong><span>{showDeleted ? `${deleted.length} 个文件 · 原件和处理记录保留` : simplified ? `${sources.length} 个文件${pendingIds.length ? ` · ${pendingIds.length} 个待删除` : ''}` : `${sources.length} 个文件 · 上传或接收不等于已经发布`}</span>{canOperate && <Checkbox checked={showDeleted} onChange={event => setShowDeleted(event.target.checked)}>查看已删除来源</Checkbox>}</div>
|
||||
{simplified && <p className="nc-source-maintenance-note">删除先标记为待删除,可连续操作和撤销,点击上方“更新报表”后统一生效。原文件和处理记录保留。</p>}
|
||||
{simplified && pendingIds.length > 0 && <div className="nc-source-maintenance-note"><Button disabled={maintenanceBusy} onClick={onClearDeletes}>撤销全部待删除({pendingIds.length})</Button></div>}
|
||||
{deletedError && <Alert showIcon type="error" message="已删除来源读取失败" description={deletedError} action={<Button size="small" onClick={() => void loadDeleted()}>重试</Button>} />}
|
||||
{sourceOperation.operation && <WorkflowOperationFeedback operation={sourceOperation.operation} error={sourceOperation.error} busy={sourceOperation.busy} onResume={sourceOperation.resume} />}
|
||||
<Table<DeletionSource> size="small" bordered loading={showDeleted ? deletedLoading : loading} dataSource={showDeleted ? deleted.map(item => item.source) : sources} rowKey="id" pagination={{ pageSize: 12, showSizeChanger: false }} scroll={{ x: 980 }} columns={[
|
||||
{ title: '来源文件', dataIndex: 'sourceFile', key: 'sourceFile', width: 340, ellipsis: true },
|
||||
{ title: '阶段', dataIndex: 'stage', key: 'stage', align: 'center', width: 90, render: value => <Tag>{stageName(value)}</Tag> },
|
||||
{ title: '统计期间', key: 'period', align: 'center', width: 140, render: (_, row) => period(row) },
|
||||
{ title: showDeleted ? '删除理由' : '文件大小', dataIndex: showDeleted ? 'deletionReason' : 'sizeBytes', key: 'sizeBytes', align: showDeleted ? 'left' : 'right', width: showDeleted ? 220 : 120, ellipsis: true, render: value => showDeleted ? txt(value) : typeof value === 'number' ? `${(value / 1024).toFixed(1)} KB` : '—' },
|
||||
{ title: '接入状态', dataIndex: 'status', key: 'status', align: 'center', width: 130, render: value => showDeleted ? <Tag>已删除</Tag> : ({ DISCOVERED: '已接收', QUEUED: '等待校验', RUNNING: '正在校验', IMPORTED: '已校验', UNIDENTIFIED: '待确认', RETURNED: '已退回', COVERAGE_CONFLICT: '范围待确认', WRITING: '文件写入中' } as Record<string, string>)[String(value)] || value },
|
||||
{ title: '接入状态', dataIndex: 'status', key: 'status', align: 'center', width: 130, render: (value, row) => simplified && pendingIds.includes(row.id) ? <Tag color="orange">待删除</Tag> : showDeleted ? <Tag>已删除</Tag> : ({ DISCOVERED: '已接收', QUEUED: '等待校验', RUNNING: '正在校验', IMPORTED: '已校验', UNIDENTIFIED: '待确认', RETURNED: '已退回', COVERAGE_CONFLICT: '范围待确认', WRITING: '文件写入中' } as Record<string, string>)[String(value)] || value },
|
||||
{ title: '操作', key: 'actions', align: 'center', fixed: 'right', width: 170, render: (_, row) => {
|
||||
const onCurrentRelease = currentSourceIds?.includes(row.id) ?? false;
|
||||
const permitted = !simplified || (showDeleted ? workflowStatus?.capabilities?.canRestoreSource !== false : currentSourceIds !== null && workflowStatus?.capabilities?.canDeleteSource !== false && (!onCurrentRelease || workflowStatus?.capabilities?.canDeleteCurrentSource !== false));
|
||||
if (!workflowStatusLoaded || !canOperate || !permitted) return null;
|
||||
return <Button type="link" danger={!showDeleted} icon={showDeleted ? <UndoOutlined /> : <DeleteOutlined />} disabled={sourceOperation.busy} onClick={() => simplified ? void runSourceOperation(row.id, showDeleted) : setSelected({ id: row.id, restore: showDeleted })}>{simplified ? showDeleted ? '恢复并更新报表' : '删除并更新报表' : showDeleted ? '恢复' : '删除'}</Button>;
|
||||
return <Button type="link" danger={!showDeleted} icon={showDeleted ? <UndoOutlined /> : <DeleteOutlined />} disabled={sourceOperation.busy || maintenanceBusy || loading} onClick={() => simplified ? showDeleted ? void runSourceOperation(row.id, true) : onToggleDelete(row.id) : setSelected({ id: row.id, restore: showDeleted })}>{simplified ? showDeleted ? '恢复并更新报表' : pendingIds.includes(row.id) ? '撤销删除' : '删除' : showDeleted ? '恢复' : '删除'}</Button>;
|
||||
} },
|
||||
]} locale={{ emptyText: showDeleted ? '没有已删除的来源。' : '尚无来源文件,点击“上传新数据”开始。' }} />
|
||||
</section>
|
||||
@@ -420,7 +453,7 @@ function DataUploadWizard({ user, mode, purpose, handoffSourceId, initialReason,
|
||||
const publishReady = release?.complete === true && reconciliation?.publishReady === true;
|
||||
const steps = purpose === 'WITHDRAW' ? ['确认来源', '提交申请', '审批与候选', '来源校验', '对账与发布'] : mode === 'REBUILD' ? ['确认重算', '选择期间', '表头匹配', '计算校验', '对账与发布'] : ['选择文件', '确认期间', '工作表与表头', '预览与校验', '对账与发布'];
|
||||
const close = () => { generation.current++; onClose(); };
|
||||
return <Modal className="management-modal nc-workflow-modal" open width={1120} title={published ? purpose === 'WITHDRAW' ? '来源删除已发布' : '数据已发布' : purpose === 'WITHDRAW' ? '核对并发布删除候选' : resumeId ? '继续处理候选数据' : mode === 'REPLACE' ? '替换已有数据' : mode === 'REBUILD' ? '按当前来源重新计算' : '上传新数据'} onCancel={close} maskClosable={!busy} footer={<div className="nc-modal-footer"><span>{runId ? '关闭后任务继续,可在“导入与校验”查看;完成后从候选继续。' : '确认发布前,当前查询结果保持不变。'}</span><div>{step > 0 && step < 4 && !runId && !configuredSourceId && !busy && <Button onClick={() => { setStep(step - 1); setError(''); }}>上一步</Button>}<Button onClick={close}>{published ? '完成' : busy ? '关闭并稍后查看' : '关闭'}</Button>{!published && step === 1 && <Button type="primary" disabled={mode === 'REPLACE' && !target} loading={busy} onClick={() => { setStep(2); void changePreview(sheetName, headerRow); }}>下一步:匹配表头</Button>}{!published && step === 2 && <Button type="primary" loading={busy} disabled={Boolean(missingFields.length) || duplicateColumns || !sheetName} onClick={() => { if (workbook && (workbook.preview.headerRow !== headerRow || workbook.preview.sheetName !== sheetName)) { void changePreview(sheetName, headerRow); return; } setStep(3); }}>下一步:预览验证</Button>}{!published && step === 3 && !runId && mode !== 'REBUILD' && <Button type="primary" loading={busy} disabled={mode === 'REPLACE' && !reason.trim()} onClick={() => void beginImport()}>确认导入并校验</Button>}</div></div>}>
|
||||
return <Modal className="management-modal nc-workflow-modal" open width={1120} title={published ? purpose === 'WITHDRAW' ? '来源删除已发布' : '数据已发布' : purpose === 'WITHDRAW' ? '核对并发布删除候选' : resumeId ? '继续处理候选数据' : mode === 'REPLACE' ? '替换已有数据' : mode === 'REBUILD' ? '按当前来源重新计算' : '上传新数据'} onCancel={close} maskClosable={!busy} footer={<div className="nc-modal-footer"><span>{runId ? '关闭后任务继续,可在“数据接入”的“导入记录”查看;完成后从候选继续。' : '确认发布前,当前查询结果保持不变。'}</span><div>{step > 0 && step < 4 && !runId && !configuredSourceId && !busy && <Button onClick={() => { setStep(step - 1); setError(''); }}>上一步</Button>}<Button onClick={close}>{published ? '完成' : busy ? '关闭并稍后查看' : '关闭'}</Button>{!published && step === 1 && <Button type="primary" disabled={mode === 'REPLACE' && !target} loading={busy} onClick={() => { setStep(2); void changePreview(sheetName, headerRow); }}>下一步:匹配表头</Button>}{!published && step === 2 && <Button type="primary" loading={busy} disabled={Boolean(missingFields.length) || duplicateColumns || !sheetName} onClick={() => { if (workbook && (workbook.preview.headerRow !== headerRow || workbook.preview.sheetName !== sheetName)) { void changePreview(sheetName, headerRow); return; } setStep(3); }}>下一步:预览验证</Button>}{!published && step === 3 && !runId && mode !== 'REBUILD' && <Button type="primary" loading={busy} disabled={mode === 'REPLACE' && !reason.trim()} onClick={() => void beginImport()}>确认导入并校验</Button>}</div></div>}>
|
||||
<Steps className="nc-steps" current={published ? 5 : step} size="small" items={steps.map(title => ({ title }))} />
|
||||
{error && <Alert showIcon type="error" message="本次操作未完成" description={error} />}
|
||||
{published ? <div className="nc-success"><FileExcelOutlined /><h2>{purpose === 'WITHDRAW' ? '该来源已从当前查询结果移除' : '当前查询数据已更新'}</h2><p>来源原件和本次对账记录均已保留。</p></div> : <>
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Table as AntdTable } from 'antd';
|
||||
import type { ColumnType, TableProps } from 'antd/es/table';
|
||||
|
||||
type QualityTableProps<T extends object> = TableProps<T> & {
|
||||
/** Offset for tables whose page is controlled outside Ant Design. */
|
||||
indexOffset?: number;
|
||||
};
|
||||
|
||||
export function QualityTable<T extends object>({
|
||||
columns,
|
||||
dataSource,
|
||||
pagination,
|
||||
indexOffset = 0,
|
||||
className,
|
||||
size = 'small',
|
||||
...props
|
||||
}: QualityTableProps<T>) {
|
||||
const pageConfig = typeof pagination === 'object' && pagination !== null ? pagination : undefined;
|
||||
const page = pageConfig?.current ?? 1;
|
||||
const pageSize = pageConfig?.pageSize ?? (pagination === undefined ? 10 : dataSource?.length ?? 0);
|
||||
const pageOffset = indexOffset + Math.max(0, page - 1) * pageSize;
|
||||
const indexColumn: ColumnType<T> = {
|
||||
title: '序号',
|
||||
key: '__quality-row-number__',
|
||||
width: 68,
|
||||
align: 'center',
|
||||
fixed: 'left',
|
||||
className: 'quality-table-index-column',
|
||||
render: (_value, _record, index) => pageOffset + index + 1,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="quality-table-frame">
|
||||
<AntdTable<T>
|
||||
{...props}
|
||||
className={['quality-table', className].filter(Boolean).join(' ')}
|
||||
columns={[indexColumn, ...(columns ?? [])]}
|
||||
dataSource={dataSource}
|
||||
pagination={pagination}
|
||||
size={size}
|
||||
bordered
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Spin,
|
||||
Tooltip,
|
||||
@@ -15,19 +14,15 @@ import {
|
||||
AppstoreOutlined,
|
||||
ApartmentOutlined,
|
||||
BgColorsOutlined,
|
||||
CheckSquareOutlined,
|
||||
CheckOutlined,
|
||||
DatabaseOutlined,
|
||||
DownOutlined,
|
||||
DeploymentUnitOutlined,
|
||||
FileSearchOutlined,
|
||||
KeyOutlined,
|
||||
LineChartOutlined,
|
||||
LoadingOutlined,
|
||||
LogoutOutlined,
|
||||
RobotOutlined,
|
||||
SearchOutlined,
|
||||
QuestionCircleOutlined,
|
||||
SettingOutlined,
|
||||
TeamOutlined,
|
||||
ToolOutlined,
|
||||
@@ -50,8 +45,9 @@ const pageNames: Record<PageKey, string> = {
|
||||
|
||||
const pageFromLocation = (): PageKey => {
|
||||
const key = new URLSearchParams(window.location.search).get('page');
|
||||
if (key === 'headers' || key === 'releases') return 'sources';
|
||||
if (key === 'headers' || key === 'releases' || key === 'imports') return 'sources';
|
||||
if (key === 'scrap') return 'product';
|
||||
if (key === 'basis') return 'overall';
|
||||
return key && key in pageNames ? key as PageKey : 'overall';
|
||||
};
|
||||
|
||||
@@ -83,7 +79,6 @@ const navGroups = [
|
||||
label: '数据中心',
|
||||
items: [
|
||||
['sources', '数据接入', DatabaseOutlined],
|
||||
['imports', '导入与校验', CheckSquareOutlined],
|
||||
] as const,
|
||||
},
|
||||
{
|
||||
@@ -98,11 +93,6 @@ const navGroups = [
|
||||
},
|
||||
];
|
||||
|
||||
const searchablePages: { key: PageKey; label: string }[] = [
|
||||
...navGroups.flatMap(group => group.items.map(([key, label]) => ({ key, label }))),
|
||||
{ key: 'basis', label: pageNames.basis },
|
||||
];
|
||||
|
||||
function shownDepartment(value: string): string {
|
||||
return value === '质量管理部' ? '质量中心' : value;
|
||||
}
|
||||
@@ -122,28 +112,14 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
const [user, setUser] = useState<AuthUser | null>(null);
|
||||
const [sessionLoading, setSessionLoading] = useState(true);
|
||||
const [sessionError, setSessionError] = useState('');
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
const onShortcut = (event: KeyboardEvent) => {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
|
||||
event.preventDefault();
|
||||
setSearchTerm('');
|
||||
setSearchOpen(true);
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', onShortcut);
|
||||
return () => window.removeEventListener('keydown', onShortcut);
|
||||
}, [user]);
|
||||
|
||||
useEffect(() => {
|
||||
const syncFromLocation = () => {
|
||||
const url = new URL(window.location.href);
|
||||
const currentPage = url.searchParams.get('page') || '';
|
||||
if (['headers', 'releases', 'scrap'].includes(currentPage)) {
|
||||
url.searchParams.set('page', currentPage === 'scrap' ? 'product' : 'sources');
|
||||
if (['headers', 'releases', 'scrap', 'basis', 'imports'].includes(currentPage)) {
|
||||
if (currentPage === 'imports') url.searchParams.set('showImportHistory', '1');
|
||||
url.searchParams.set('page', currentPage === 'basis' ? 'overall' : currentPage === 'scrap' ? 'product' : 'sources');
|
||||
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
}
|
||||
setPage(pageFromLocation());
|
||||
@@ -175,6 +151,8 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
|
||||
const navigate = (next: PageKey, query?: QueryParams, resultRef?: TopResultRef) => {
|
||||
const url = new URL(window.location.href);
|
||||
if (next === 'imports') { next = 'sources'; url.searchParams.set('showImportHistory', '1'); }
|
||||
else url.searchParams.delete('showImportHistory');
|
||||
url.searchParams.set('page', next);
|
||||
if (next !== 'analysis' || query || resultRef) {
|
||||
url.searchParams.delete('sessionId');
|
||||
@@ -184,14 +162,8 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
else url.searchParams.delete('context');
|
||||
window.history.pushState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
setPage(next);
|
||||
setSearchOpen(false);
|
||||
};
|
||||
|
||||
const matchingPages = searchablePages.filter(({ key, label }) => {
|
||||
const normalized = searchTerm.trim().toLocaleLowerCase();
|
||||
return !normalized || `${label} ${key}`.toLocaleLowerCase().includes(normalized);
|
||||
});
|
||||
|
||||
const handleUnauthorized = useCallback((error: unknown) => {
|
||||
if (error instanceof ApiError && error.status === 401) {
|
||||
setUser(null);
|
||||
@@ -230,12 +202,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<div className="nav-group nav-group-tail">
|
||||
<div className="nav-group-label">数据口径</div>
|
||||
<button className={`nav-item ${page === 'basis' ? 'active' : ''}`} aria-current={page === 'basis' ? 'page' : undefined} onClick={() => navigate('basis')}>
|
||||
<FileSearchOutlined aria-hidden="true" /><span>数据与计算依据</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
<div className="user-block">
|
||||
<span className="avatar">{(user.displayName || user.username).slice(0, 1)}</span>
|
||||
@@ -251,9 +217,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<header className="topbar">
|
||||
<div className="breadcrumb"><span>质量分析</span><span className="breadcrumb-slash">/</span><strong>{pageNames[page]}</strong></div>
|
||||
<div className="topbar-actions">
|
||||
<Button className="topbar-search" type="text" aria-label="搜索功能页面" onClick={() => { setSearchTerm(''); setSearchOpen(true); }}>
|
||||
<SearchOutlined /><span>搜索功能页面…</span><kbd>⌘ K</kbd>
|
||||
</Button>
|
||||
<Dropdown
|
||||
trigger={['click']}
|
||||
classNames={{ root: 'workspace-theme-dropdown' }}
|
||||
@@ -270,9 +233,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<BgColorsOutlined /><span>{appearance.name}</span><DownOutlined />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
<Tooltip title="查看数据与计算依据">
|
||||
<Button className="topbar-help" type="text" icon={<QuestionCircleOutlined />} aria-label="查看数据与计算依据" onClick={() => navigate('basis')} />
|
||||
</Tooltip>
|
||||
<span className="top-organization"><TeamOutlined />质量中心</span>
|
||||
</div>
|
||||
</header>
|
||||
@@ -280,7 +240,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<span className="brand-mark" aria-hidden="true"><i /><i /><i /></span><strong>质量中心</strong>
|
||||
<Select<PageKey> {...readableSelectPopup} aria-label="页面导航" value={page} onChange={value => navigate(value)} options={[
|
||||
...navGroups.map(group => ({ label: group.label, options: group.items.map(([value, label]) => ({ value, label })) })),
|
||||
{ label: '数据口径', options: [{ value: 'basis' as PageKey, label: '数据与计算依据' }] },
|
||||
]} />
|
||||
<Button type="text" icon={<LogoutOutlined />} aria-label="退出登录" onClick={async () => {
|
||||
try { await api.logout(); setUser(null); }
|
||||
@@ -297,33 +256,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
</Suspense>
|
||||
</div>
|
||||
</main>
|
||||
<Modal
|
||||
className="navigation-search-modal"
|
||||
title="搜索功能页面"
|
||||
open={searchOpen}
|
||||
footer={null}
|
||||
centered
|
||||
width={520}
|
||||
onCancel={() => setSearchOpen(false)}
|
||||
>
|
||||
<Input
|
||||
autoFocus
|
||||
allowClear
|
||||
prefix={<SearchOutlined />}
|
||||
placeholder="输入页面名称"
|
||||
value={searchTerm}
|
||||
onChange={event => setSearchTerm(event.target.value)}
|
||||
onPressEnter={() => matchingPages[0] && navigate(matchingPages[0].key)}
|
||||
/>
|
||||
<div className="navigation-search-results" role="listbox" aria-label="功能页面">
|
||||
{matchingPages.length ? matchingPages.map(item => (
|
||||
<button className="navigation-result" type="button" key={item.key} role="option" aria-selected={page === item.key} onClick={() => navigate(item.key)}>
|
||||
<span>{item.label}</span><kbd>Enter</kbd>
|
||||
</button>
|
||||
)) : <div className="navigation-search-empty">没有匹配的功能页面</div>}
|
||||
</div>
|
||||
<div className="navigation-search-footnote">按 Enter 打开首项,Esc 关闭</div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+136
-90
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import * as echarts from 'echarts/core';
|
||||
import { BarChart, LineChart } from 'echarts/charts';
|
||||
import { GridComponent, LegendComponent, MarkLineComponent, TooltipComponent } from 'echarts/components';
|
||||
import { GraphicComponent, GridComponent, LegendComponent, MarkLineComponent, TooltipComponent } from 'echarts/components';
|
||||
import { SVGRenderer } from 'echarts/renderers';
|
||||
import {
|
||||
Alert,
|
||||
@@ -42,14 +42,17 @@ import { M01Insights } from './AnalyticsCompletion';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
import { isInternalDataField } from './publicDataDisplay';
|
||||
import { previousCompleteMonth, previousCompleteQuarter } from './periodDefaults';
|
||||
import { defectWeightRate } from './trendMetrics';
|
||||
import './query-motion.css';
|
||||
import { ExtraQueryFilters } from './ExtraQueryFilters';
|
||||
|
||||
echarts.use([BarChart, LineChart, GridComponent, LegendComponent, MarkLineComponent, TooltipComponent, SVGRenderer]);
|
||||
echarts.use([BarChart, LineChart, GraphicComponent, GridComponent, LegendComponent, MarkLineComponent, TooltipComponent, SVGRenderer]);
|
||||
|
||||
const MONTHS = Array.from({ length: 12 }, (_, index) => `${String(index + 1).padStart(2, '0')}月`);
|
||||
const TABLE_PAGE_SIZE = 20;
|
||||
const SUMMARY_PAGE_SIZE = 15;
|
||||
const SUMMARY_PAGE_SIZE_OPTIONS = ['10', '15', '20', '50', '100'];
|
||||
const EMPTY_PRODUCT_SEARCH = '__codex_no_product_search_match__';
|
||||
const SCOPE: Record<string, ViewKind> = { overall: 'overall', department: 'department', group: 'group', product: 'product' };
|
||||
const SCOPE_NAMES: Record<string, string> = { overall: '总体', department: '产业部', group: '产业部-业务分组', product: '产品' };
|
||||
const RETIRED_DEPARTMENTS = new Set(['美洲产业部', '欧洲产业部', '欧洲磁钢']);
|
||||
@@ -110,7 +113,7 @@ function visibleStageRate(row: MetricRow | undefined, stage: Stage, rateBasis: '
|
||||
}
|
||||
|
||||
function visibleCompositeRate(row: MetricRow | undefined, rateBasis: 'original' | 'withoutHeadquartersScrap' = 'original'): number | null {
|
||||
if (!(hasStageRows(row, 'black') && hasStageRows(row, 'bright'))) return null;
|
||||
if (!(hasStageRows(row, 'black') || hasStageRows(row, 'bright'))) return null;
|
||||
return rateBasis === 'withoutHeadquartersScrap'
|
||||
? (row as (MetricRow & { compositeRateWithoutHeadquartersScrap?: number | null }) | undefined)?.compositeRateWithoutHeadquartersScrap ?? null
|
||||
: row?.compositeRate ?? null;
|
||||
@@ -221,18 +224,22 @@ function toApiParams(args: {
|
||||
department?: string[];
|
||||
group?: string[];
|
||||
product?: string[];
|
||||
productSearch?: string;
|
||||
projectGroup?: string[];
|
||||
extraFilters?: Record<string, string[]>;
|
||||
trendGranularity: 'month' | 'quarter' | 'year';
|
||||
view: ViewKind;
|
||||
includeUnassigned: boolean;
|
||||
}): QueryParams {
|
||||
return {
|
||||
year: args.year,
|
||||
...(args.extraFilters && Object.keys(args.extraFilters).length ? { extraFilters: args.extraFilters } : {}),
|
||||
...(args.period === 'month' ? { month: args.month } : {}),
|
||||
...(args.period === 'quarter' ? { quarter: args.quarter } : {}),
|
||||
...(encodeQueryValueList(args.department) ? { department: encodeQueryValueList(args.department) } : {}),
|
||||
...(encodeQueryValueList(args.group) ? { group: encodeQueryValueList(args.group) } : {}),
|
||||
...(encodeQueryValueList(args.product) ? { product: encodeQueryValueList(args.product) } : {}),
|
||||
...(args.productSearch?.trim() ? { productSearch: args.productSearch.trim() } : {}),
|
||||
...(encodeQueryValueList(args.projectGroup) ? { projectGroup: encodeQueryValueList(args.projectGroup) } : {}),
|
||||
...(args.includeUnassigned ? { includeUnassigned: true } : {}),
|
||||
trendGranularity: args.trendGranularity,
|
||||
@@ -240,6 +247,19 @@ function toApiParams(args: {
|
||||
};
|
||||
}
|
||||
|
||||
function applyTrendObject(query: QueryParams, trendObject: string, view: ViewKind): QueryParams {
|
||||
if (!trendObject) return query;
|
||||
const params: QueryParams = { ...query };
|
||||
if (view === 'department') params.department = trendObject;
|
||||
if (view === 'group') params.group = trendObject;
|
||||
if (view === 'product') {
|
||||
const selectedProducts = decodeQueryValueList(params.product);
|
||||
params.product = selectedProducts.length === 0 || selectedProducts.includes(trendObject) ? trendObject : EMPTY_PRODUCT_SEARCH;
|
||||
}
|
||||
if (view === 'projectGroup') params.projectGroup = trendObject;
|
||||
return params;
|
||||
}
|
||||
|
||||
type TopResultRef = { kind: 'TOP'; resultId: string; releaseId: string };
|
||||
export default function QueryPage({ page, onUnauthorized }: {
|
||||
page: PageKey;
|
||||
@@ -249,7 +269,10 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const { message } = App.useApp();
|
||||
const baseView = SCOPE[page] || 'overall';
|
||||
const initialQuery = queryFromLocation();
|
||||
const [viewOverride, setViewOverride] = useState<ViewKind | undefined>(() => initialQuery.view && initialQuery.view !== baseView ? initialQuery.view : undefined);
|
||||
const [viewOverrideState, setViewOverrideState] = useState<{ page: PageKey; view: ViewKind } | undefined>(() => initialQuery.view && initialQuery.view !== baseView ? { page, view: initialQuery.view } : undefined);
|
||||
const routeViewOverride = initialQuery.view && initialQuery.view !== baseView ? initialQuery.view : undefined;
|
||||
const viewOverride = routeViewOverride || (viewOverrideState?.page === page ? viewOverrideState.view : undefined);
|
||||
const setViewOverride = (next?: ViewKind) => setViewOverrideState(next ? { page, view: next } : undefined);
|
||||
const view = viewOverride || baseView;
|
||||
const scopeName = viewOverride ? ({ overall: '总体', department: '产业部', group: '产业部-业务分组', product: '产品', projectGroup: '项目组' } as Record<ViewKind, string>)[viewOverride] : SCOPE_NAMES[page] || '总体';
|
||||
const [options, setOptions] = useState<OptionsResponse | null>(null);
|
||||
@@ -265,15 +288,18 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [group, setGroup] = useState<string[]>(() => decodeQueryValueList(initialQuery.group));
|
||||
const [product, setProduct] = useState<string[]>(() => decodeQueryValueList(initialQuery.product));
|
||||
const [projectGroup, setProjectGroup] = useState<string[]>(() => decodeQueryValueList(initialQuery.projectGroup));
|
||||
const [extraFilters, setExtraFilters] = useState<Record<string,string[]>>(initialQuery.extraFilters || {});
|
||||
const [includeUnassigned, setIncludeUnassigned] = useState(initialQuery.includeUnassigned === true);
|
||||
const [trendGranularity, setTrendGranularity] = useState<'month' | 'quarter' | 'year'>(initialQuery.trendGranularity || (initialQuery.quarter ? 'quarter' : 'month'));
|
||||
const [search, setSearch] = useState('');
|
||||
const [appliedSearch, setAppliedSearch] = useState('');
|
||||
const [fullFields, setFullFields] = useState(false);
|
||||
const [data, setData] = useState<MetricsResponse | null>(null);
|
||||
const [dataKey, setDataKey] = useState('');
|
||||
const [trendData, setTrendData] = useState<TrendMetricRow[]>([]);
|
||||
const [trendDataKey, setTrendDataKey] = useState('');
|
||||
const [trendTarget, setTrendTarget] = useState<number | null>(null);
|
||||
const [trendTargetKey, setTrendTargetKey] = useState('');
|
||||
const [trendObject, setTrendObject] = useState('');
|
||||
const [drilledProduct, setDrilledProduct] = useState('');
|
||||
const [trendObjectMetrics, setTrendObjectMetrics] = useState<{ key: string; data: MetricsResponse } | null>(null);
|
||||
@@ -285,6 +311,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [trendLoading, setTrendLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [errorKey, setErrorKey] = useState('');
|
||||
const [queryRevision, setQueryRevision] = useState(0);
|
||||
const [selectedRecord, setSelectedRecord] = useState<MetricRow | null>(null);
|
||||
const [recordsOpen, setRecordsOpen] = useState(false);
|
||||
@@ -293,18 +320,19 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const [basisOpen, setBasisOpen] = useState(false);
|
||||
const trendAnchorTop = useRef<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setAppliedSearch(search), 300);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [search]);
|
||||
|
||||
useEffect(() => {
|
||||
setTrendObject('');
|
||||
setDrilledProduct('');
|
||||
setSearch('');
|
||||
setViewOverride(undefined);
|
||||
if (!new URLSearchParams(window.location.search).has('context')) {
|
||||
const previous = previousCompleteMonth();
|
||||
setPeriod(page === 'overall' ? 'year' : 'month');
|
||||
setYear(page === 'overall' ? new Date().getFullYear() : previous.year);
|
||||
setMonth(previous.month);
|
||||
setTrendGranularity('month');
|
||||
}
|
||||
setAppliedSearch('');
|
||||
setViewOverrideState(undefined);
|
||||
setRecordsOpen(false);
|
||||
setSelectedRecord(null);
|
||||
}, [page]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -341,38 +369,38 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
if (next.length !== group.length) { setGroup(next); setProduct([]); }
|
||||
}, [options, department, group, allowedGroupSet]);
|
||||
|
||||
const queryParams = useMemo(() => toApiParams({ year, period, month, quarter, department, group, product, projectGroup, view, includeUnassigned, trendGranularity }), [year, period, month, quarter, department, group, product, projectGroup, view, includeUnassigned, trendGranularity]);
|
||||
const exactProductSearch = useMemo(() => {
|
||||
const term = view === 'product' ? appliedSearch.trim().toLocaleLowerCase() : '';
|
||||
return term ? (options?.products || []).find(name => name.trim().toLocaleLowerCase() === term) || '' : '';
|
||||
}, [view, appliedSearch, options]);
|
||||
const productFilterForQuery = useMemo(() => {
|
||||
if (!exactProductSearch) return product;
|
||||
if (product.length && !product.includes(exactProductSearch)) return [EMPTY_PRODUCT_SEARCH];
|
||||
return [exactProductSearch];
|
||||
}, [exactProductSearch, product]);
|
||||
const queryParams = useMemo(() => toApiParams({ year, period, month, quarter, department, group, product: productFilterForQuery, productSearch: view === 'product' ? appliedSearch : undefined, projectGroup, extraFilters, view, includeUnassigned, trendGranularity }), [year, period, month, quarter, department, group, productFilterForQuery, appliedSearch, projectGroup, extraFilters, view, includeUnassigned, trendGranularity]);
|
||||
const queryKey = useMemo(() => JSON.stringify(queryParams), [queryParams]);
|
||||
const drilldownContextKey = JSON.stringify({ view, year, department, group, product, projectGroup, includeUnassigned });
|
||||
const drilldownContextKey = JSON.stringify({ view, year, department, group, product, projectGroup, extraFilters, includeUnassigned });
|
||||
useEffect(() => {
|
||||
setDrilledProduct('');
|
||||
}, [drilldownContextKey]);
|
||||
const metricParams = useMemo<QueryParams>(() => ({ ...queryParams, trendGranularity: 'month' }), [queryParams]);
|
||||
const metricKey = useMemo(() => JSON.stringify(metricParams), [metricParams]);
|
||||
const currentMetricsData = dataKey === metricKey ? data : null;
|
||||
const currentMetricsError = errorKey === metricKey ? error : '';
|
||||
const queryPending = !currentMetricsData && !currentMetricsError;
|
||||
const queryBusy = loading || queryPending;
|
||||
const metricKeyRef = useRef(metricKey);
|
||||
metricKeyRef.current = metricKey;
|
||||
const useSummaryTrend = period === 'year' && !trendObject && trendGranularity === 'month';
|
||||
const trendParams = useMemo<QueryParams>(() => {
|
||||
const params: QueryParams = { ...queryParams };
|
||||
const params = applyTrendObject(queryParams, trendObject, view);
|
||||
delete params.month;
|
||||
delete params.quarter;
|
||||
if (trendGranularity === 'year') Reflect.deleteProperty(params, 'year');
|
||||
if (trendObject) {
|
||||
if (view === 'department') params.department = trendObject;
|
||||
if (view === 'group') params.group = trendObject;
|
||||
if (view === 'product') params.product = trendObject;
|
||||
if (view === 'projectGroup') params.projectGroup = trendObject;
|
||||
}
|
||||
return params;
|
||||
}, [queryKey, trendObject, trendGranularity, view]);
|
||||
const defectQueryParams = useMemo<QueryParams>(() => {
|
||||
const params: QueryParams = { ...queryParams };
|
||||
if (trendObject) {
|
||||
if (view === 'department') params.department = trendObject;
|
||||
if (view === 'group') params.group = trendObject;
|
||||
if (view === 'product') params.product = trendObject;
|
||||
if (view === 'projectGroup') params.projectGroup = trendObject;
|
||||
}
|
||||
return params;
|
||||
}, [queryKey, trendObject, view]);
|
||||
const defectQueryParams = useMemo<QueryParams>(() => applyTrendObject(queryParams, trendObject, view), [queryKey, trendObject, view]);
|
||||
const defectQueryKey = JSON.stringify(defectQueryParams);
|
||||
const trendKey = JSON.stringify(trendParams);
|
||||
const trendKeyRef = useRef(trendKey);
|
||||
@@ -393,7 +421,9 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
setErrorKey('');
|
||||
api.metrics(metricParams, controller.signal).then(result => {
|
||||
if (controller.signal.aborted || metricKeyRef.current !== metricKey) return;
|
||||
setData(result);
|
||||
setDataKey(metricKey);
|
||||
if (useSummaryTrend && trendKeyRef.current === trendKey) {
|
||||
@@ -401,10 +431,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
setTrendDataKey(trendKey);
|
||||
}
|
||||
setError('');
|
||||
setErrorKey('');
|
||||
}).catch(errorValue => {
|
||||
if (controller.signal.aborted) return;
|
||||
if (onUnauthorized(errorValue)) return;
|
||||
setError(chooseError(errorValue));
|
||||
setErrorKey(metricKey);
|
||||
}).finally(() => { if (!controller.signal.aborted) setLoading(false); });
|
||||
return () => controller.abort();
|
||||
}, [metricKey, queryRevision, onUnauthorized]);
|
||||
@@ -451,20 +483,26 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setTrendTarget(null);
|
||||
setTrendTargetKey('');
|
||||
const targetContext = Object.fromEntries(Object.entries(trendParams).filter(([key]) => key !== 'view' && key !== 'trendGranularity'));
|
||||
api.analyticsTarget({ ...targetContext, metric: 'COMPOSITE_RATE' }).then(result => {
|
||||
const target = result.target && typeof result.target === 'object' ? result.target as Record<string, unknown> : {};
|
||||
const value = typeof target.value === 'number' ? target.value : target.targetRate;
|
||||
if (!alive) return;
|
||||
setTrendTarget(result.status === 'CONFIGURED' && typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1 ? value * 100 : null);
|
||||
setTrendTargetKey(trendKey);
|
||||
}).catch(errorValue => {
|
||||
if (!alive) return;
|
||||
if (!onUnauthorized(errorValue)) setTrendTarget(null);
|
||||
if (!onUnauthorized(errorValue)) {
|
||||
setTrendTarget(null);
|
||||
setTrendTargetKey(trendKey);
|
||||
}
|
||||
});
|
||||
return () => { alive = false; };
|
||||
}, [trendKey, onUnauthorized]);
|
||||
|
||||
const visibleTrendData = useMemo(() => fullYearTrend(trendData, year, trendGranularity), [trendData, year, trendGranularity]);
|
||||
const currentTrendTarget = trendTargetKey === trendKey ? trendTarget : null;
|
||||
const visibleTrendData = useMemo(() => fullYearTrend(trendDataKey === trendKey ? trendData : [], year, trendGranularity), [trendData, trendDataKey, trendKey, year, trendGranularity]);
|
||||
const drilledTrendData = useMemo(
|
||||
() => trendDataKey === trendKey ? visibleTrendData : fullYearTrend([], year, 'month'),
|
||||
[trendDataKey, trendKey, visibleTrendData, year],
|
||||
@@ -477,12 +515,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
const rawRows: MetricRow[] = page === 'overall' && period === 'year'
|
||||
? (() => {
|
||||
const byMonth = new Map<number, TrendMetricRow>();
|
||||
for (const item of data?.trend || []) { const parsed = monthNumber(item.month); if (parsed) byMonth.set(parsed, item); }
|
||||
for (const item of currentMetricsData?.trend || []) { const parsed = monthNumber(item.month); if (parsed) byMonth.set(parsed, item); }
|
||||
return Array.from({ length: 12 }, (_, index) => byMonth.get(index + 1) || blankMonthRow(year, index + 1));
|
||||
})()
|
||||
: page === 'overall' && data
|
||||
? data.rows.length ? data.rows : [data.summary]
|
||||
: data?.rows || [];
|
||||
: page === 'overall' && currentMetricsData
|
||||
? currentMetricsData.rows.length ? currentMetricsData.rows : [currentMetricsData.summary]
|
||||
: currentMetricsData?.rows || [];
|
||||
const scopedRows = view === 'department'
|
||||
? rawRows.filter(row => !RETIRED_DEPARTMENTS.has(row.department || row.label))
|
||||
: view === 'group' && department.length
|
||||
@@ -497,10 +535,10 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
- (typeof aWeight === 'number' && Number.isFinite(aWeight) ? aWeight : -Infinity) || 0;
|
||||
})
|
||||
: scopedRows;
|
||||
if (!search.trim()) return orderedRows;
|
||||
const term = search.trim().toLocaleLowerCase();
|
||||
if (!appliedSearch.trim()) return orderedRows;
|
||||
const term = appliedSearch.trim().toLocaleLowerCase();
|
||||
return orderedRows.filter(row => [row.label, row.department, row.group, row.product, row.projectGroup].filter(Boolean).join(' ').toLocaleLowerCase().includes(term));
|
||||
}, [page, period, data, search, year, view, department, allowedGroupSet]);
|
||||
}, [page, period, currentMetricsData, appliedSearch, year, view, department, allowedGroupSet]);
|
||||
|
||||
const openRecords = useCallback((row: MetricRow | null, stage: Stage, selectedMonth?: number) => {
|
||||
setSelectedRecord(row);
|
||||
@@ -552,15 +590,16 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
|
||||
const years = (options?.years || []).map(value => { const numeric = Number(String(value).match(/\d{4}/)?.[0]); return { label: `${numeric}年`, value: numeric }; }).filter(item => Number.isFinite(item.value));
|
||||
const filterSelect = (label: string, value: string[], choices: string[] | undefined, change: (value: string[]) => void, allowUnassigned = true) => (
|
||||
<label className="query-field" key={label}>
|
||||
<label className="query-field query-primary-field" key={label}>
|
||||
<span>{label}</span>
|
||||
<Select
|
||||
maxTagCount="responsive"
|
||||
mode="multiple"
|
||||
allowClear
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
{...readableSelectPopup}
|
||||
placeholder={`全部${label} · 可多选`}
|
||||
placeholder="全部"
|
||||
value={value}
|
||||
options={[...(label === '业务分组' ? [...(choices || [])].sort((a, b) => groupRank(a) - groupRank(b)) : choices || []).map(item => ({ label: item, value: item })), ...(allowUnassigned ? [{ label: '未分类', value: '__UNASSIGNED__' }] : [])]}
|
||||
onChange={change}
|
||||
@@ -569,12 +608,11 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
</label>
|
||||
);
|
||||
|
||||
const currentMetricsData = dataKey === metricKey ? data : null;
|
||||
const activeDefectData = trendObject
|
||||
? defectQueryKey === queryKey ? currentMetricsData : trendObjectMetrics?.key === defectQueryKey ? trendObjectMetrics.data : null
|
||||
: currentMetricsData;
|
||||
const rowForSummary = data?.summary;
|
||||
const rawFormulaDescriptions = data?.context.metricFormulaDescriptions;
|
||||
const rowForSummary = currentMetricsData?.summary;
|
||||
const rawFormulaDescriptions = currentMetricsData?.context.metricFormulaDescriptions;
|
||||
const formulaDescriptions = rawFormulaDescriptions && typeof rawFormulaDescriptions === 'object' && !Array.isArray(rawFormulaDescriptions) ? rawFormulaDescriptions as Record<string, unknown> : {};
|
||||
const compositeFormula = formulaDescriptions[rateBasis === 'original' ? 'compositeRate' : 'compositeRateWithoutHeadquartersScrap'];
|
||||
const brightFormula = formulaDescriptions[rateBasis === 'original' ? 'brightRate' : 'brightRateWithoutHeadquartersScrap'];
|
||||
@@ -644,17 +682,18 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}}
|
||||
aria-label="统计周期"
|
||||
/>
|
||||
<label className="query-field"><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"><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"><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={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>}
|
||||
{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)}
|
||||
{options?.projectGroupStatus === 'READY' && filterSelect('项目组', projectGroup, options.projectGroups, setProjectGroup)}
|
||||
<Checkbox checked={includeUnassigned} onChange={event => setIncludeUnassigned(event.target.checked)}>包含未分类行</Checkbox>
|
||||
|
||||
<ExtraQueryFilters projectGroup={projectGroup} projectGroups={options?.projectGroupStatus === 'READY' ? options.projectGroups : undefined} onProjectGroup={setProjectGroup} value={extraFilters} onChange={setExtraFilters} onUnauthorized={onUnauthorized} />
|
||||
<Checkbox className="query-unassigned" checked={includeUnassigned} onChange={event => setIncludeUnassigned(event.target.checked)}>包含未分类行</Checkbox>
|
||||
<div className="query-toolbar-tail">
|
||||
<span className={`query-status ${loading ? 'busy' : error ? 'failed' : ''}`}><i />{loading ? '正在查询' : error ? '查询失败' : '查询完成'}</span>
|
||||
<Button type="text" onClick={() => { const previous = previousCompleteMonth(); const previousQuarter = previousCompleteQuarter(); setDepartment([]); setGroup([]); setProduct([]); setProjectGroup([]); setIncludeUnassigned(false); setSearch(''); setTrendObject(''); setYear(page === 'overall' ? new Date().getFullYear() : previous.year); setMonth(previous.month); setQuarter(previousQuarter.quarter); setPeriod(page === 'overall' ? 'year' : 'month'); setTrendGranularity('month'); }}>重置</Button>
|
||||
<span className={`query-status ${queryBusy ? 'busy' : currentMetricsError ? 'failed' : ''}`}><i />{queryBusy ? '正在查询' : currentMetricsError ? '查询失败' : '查询完成'}</span>
|
||||
<Button type="text" onClick={() => { const previous = previousCompleteMonth(); const previousQuarter = previousCompleteQuarter(); setDepartment([]); setGroup([]); setProduct([]); setProjectGroup([]); setExtraFilters({}); setIncludeUnassigned(false); setSearch(''); 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>
|
||||
@@ -662,10 +701,10 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
</div>}
|
||||
</section>
|
||||
|
||||
{error && <Alert showIcon type="error" message="质量指标查询失败" description={error} action={<Button size="small" icon={<ReloadOutlined />} onClick={() => setQueryRevision(value => value + 1)}>重试</Button>} />}
|
||||
{currentMetricsError && <Alert showIcon type="error" message="质量指标查询失败" description={currentMetricsError} action={<Button size="small" icon={<ReloadOutlined />} onClick={() => setQueryRevision(value => value + 1)}>重试</Button>} />}
|
||||
<section className="metric-strip" aria-label="质量指标">
|
||||
<div className="rate-basis-control"><span>亮片本部报废调整</span><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={rateBasis === 'original' ? '综合合格率' : '综合调整率'} value={rateText(visibleCompositeRate(rowForSummary, rateBasis))} note={visibleCompositeRate(rowForSummary, rateBasis) == null ? '需同时有黑片与亮片来源' : '按当前启用规则计算'} onClick={() => setBasisOpen(true)} />
|
||||
<MetricCard primary label={rateBasis === 'original' ? '综合合格率' : '综合调整率'} value={rateText(visibleCompositeRate(rowForSummary, rateBasis))} onClick={() => setBasisOpen(true)} />
|
||||
<MetricCard label="黑片合格率" value={rateText(visibleStageRate(rowForSummary, 'black'))} note={hasStageRows(rowForSummary, 'black') ? hasValidRateDenominator(rowForSummary, 'black') ? `合格重量 ${numberText(rowForSummary?.black?.qualifiedWeight)} kg` : '按当前启用规则及空值策略计算' : '缺少黑片来源'} stage="black" onClick={() => openRecords(null, 'black')} />
|
||||
<MetricCard label={rateBasis === 'original' ? '亮片合格率' : '亮片调整率'} value={rateText(visibleStageRate(rowForSummary, 'bright', rateBasis))} note={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((rowForSummary.black.scrapWeight ?? 0) + (rowForSummary.bright.scrapWeight ?? 0))} kg` : '—'} note={hasStageRows(rowForSummary, 'black') || hasStageRows(rowForSummary, 'bright') ? `黑片 ${numberText(rowForSummary?.black?.scrapWeight)} kg · 亮片 ${numberText(rowForSummary?.bright?.scrapWeight)} kg` : '缺少阶段来源'} onClick={() => openRecords(null, 'black')} />
|
||||
@@ -680,7 +719,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
<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)} prefix={<SearchOutlined />} placeholder={`搜索${view === 'group' ? '业务分组' : view === 'product' ? '产品' : '汇总对象'}`} value={drilledProduct || search} onChange={event => setSynchronizedSearch(event.target.value)} aria-label="搜索汇总对象" />
|
||||
<Input allowClear={!drilledProduct} disabled={Boolean(drilledProduct)} maxLength={view === 'product' ? 256 : undefined} prefix={<SearchOutlined />} placeholder={view === 'product' ? '输入关键词或完整产品名称' : `搜索${view === 'group' ? '业务分组' : '汇总对象'}`} value={drilledProduct || search} onChange={event => setSynchronizedSearch(event.target.value)} aria-label={view === 'product' ? '搜索产品名称并同步筛选指标和趋势' : '搜索汇总对象'} />
|
||||
<Segmented value={fullFields ? 'full' : 'key'} options={[{ label: '关键指标', value: 'key' }, { label: '完整字段', value: 'full' }]} onChange={value => setFullFields(value === 'full')} aria-label="字段显示" />
|
||||
<Tooltip title="点击综合合格率可查看计算依据"><Button type="text" icon={<InfoCircleOutlined />} aria-label="查看计算依据" onClick={() => setBasisOpen(true)} /></Tooltip>
|
||||
{drilledProduct && <Button onClick={() => { setDrilledProduct(''); setTrendObject(''); setTrendMode('production'); }}>返回产品汇总</Button>}
|
||||
@@ -702,7 +741,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
onBasis={() => setBasisOpen(true)}
|
||||
onDrilldown={() => undefined}
|
||||
/>
|
||||
) : loading && !data ? <div className="loading-panel"><Spin />正在查询真实指标数据…</div> : visibleRows.length === 0 ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={error ? '查询失败,暂无可展示结果' : '当前条件下暂无数据'} /> : (
|
||||
) : queryPending ? <div className="loading-panel query-metrics-loading"><Spin />正在查询真实指标数据…</div> : visibleRows.length === 0 ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={currentMetricsError ? '查询失败,暂无可展示结果' : '当前条件下暂无数据'} /> : (
|
||||
<MetricTable
|
||||
rows={visibleRows}
|
||||
view={view}
|
||||
@@ -728,7 +767,7 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div className="table-footer"><span>{drilledProduct ? trendLoading && trendDataKey !== trendKey ? `${drilledProduct} · 正在查询月度数据` : `${drilledProduct} · 共 ${drilledTrendData.length} 个月` : page === 'overall' && period === 'year' ? `年度月份 12 行 · 已有数据 ${new Set((data?.trend || []).map(item => String(item.month))).size} 个月` : `共 ${visibleRows.length} 行`}</span></div>
|
||||
<div className="table-footer"><span>{drilledProduct ? trendLoading && trendDataKey !== trendKey ? `${drilledProduct} · 正在查询月度数据` : `${drilledProduct} · 共 ${drilledTrendData.length} 个月` : page === 'overall' && period === 'year' ? `年度月份 12 行 · 已有数据 ${new Set((currentMetricsData?.trend || []).map(item => String(item.month))).size} 个月` : `共 ${visibleRows.length} 行`}</span></div>
|
||||
</section>
|
||||
|
||||
<div className="analysis-stack">
|
||||
@@ -746,8 +785,8 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
<div className="trend-chart-shell" aria-busy={trendLoading}>
|
||||
{trendMode === 'data'
|
||||
? <TrendTable rows={visibleTrendData} rateBasis={rateBasis} onMonth={selectTrendPeriod} />
|
||||
: <TrendChart rows={visibleTrendData} mode={trendMode} stage={trendStage} rateBasis={rateBasis} targetRate={trendTarget} selectedPeriod={selectedTrendPeriod} onMonth={selectTrendPeriod} />}
|
||||
{trendLoading && <span className="trend-refresh-indicator"><Spin size="small" />正在更新趋势</span>}
|
||||
: <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>}
|
||||
</div>
|
||||
<div className="chart-footnote"><span>全年期间均显示;无数据期间留空,指标由源分量重新汇总。</span><span>点击期间筛选,再次点击可取消</span></div>
|
||||
</section>
|
||||
@@ -771,12 +810,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
</section>;
|
||||
})}
|
||||
</div>
|
||||
<DefectParetoPanel releaseId={data?.release?.id} query={defectQueryParams} externalScrapWeight={blackDefectItems.find(item => item.name === '外废')?.weight} onUnauthorized={onUnauthorized} />
|
||||
<DefectParetoPanel key={defectQueryKey} releaseId={currentMetricsData?.release?.id} query={defectQueryParams} externalScrapWeight={blackDefectItems.find(item => item.name === '外废')?.weight} onUnauthorized={onUnauthorized} />
|
||||
</section>
|
||||
</div>
|
||||
</>
|
||||
|
||||
<M01Insights query={queryParams} onUnauthorized={onUnauthorized} />
|
||||
<M01Insights key={queryKey} query={queryParams} onUnauthorized={onUnauthorized} />
|
||||
|
||||
<div className="query-footer"><span>查询数据由服务端按当前数据返回</span><Button type="link" onClick={() => setBasisOpen(true)}>计算口径</Button></div>
|
||||
|
||||
@@ -810,12 +849,12 @@ export default function QueryPage({ page, onUnauthorized }: {
|
||||
);
|
||||
}
|
||||
|
||||
function MetricCard({ primary, label, value, note, stage, onClick }: { primary?: boolean; label: string; value: string; note: string; stage?: Stage; onClick: () => void }) {
|
||||
function MetricCard({ primary, label, value, note, stage, onClick }: { primary?: boolean; label: string; value: string; note?: string; stage?: Stage; onClick: () => void }) {
|
||||
const parts = value.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>
|
||||
<small>{note}</small>
|
||||
{note && <small>{note}</small>}
|
||||
</button>;
|
||||
}
|
||||
|
||||
@@ -827,7 +866,7 @@ function DefectBreakdown({ items, stage, totalWeight, maximum, onDetail }: { ite
|
||||
<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(item.weight != null && totalWeight != null && totalWeight > 0 ? item.weight / totalWeight : null)}</span>
|
||||
<span className="defect-rate">{rateText(defectWeightRate(item.weight, totalWeight))}</span>
|
||||
</button>)}
|
||||
</div>;
|
||||
}
|
||||
@@ -845,6 +884,8 @@ function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUnauthoriz
|
||||
const [themeRevision, setThemeRevision] = useState(0);
|
||||
const fineQuery = useMemo(() => ({
|
||||
year: query.year,
|
||||
...(query.productSearch ? { productSearch: query.productSearch } : {}),
|
||||
...(query.extraFilters ? { extraFilters: query.extraFilters } : {}),
|
||||
...(query.month != null ? { month: query.month } : {}),
|
||||
...(query.quarter != null ? { quarter: query.quarter } : {}),
|
||||
...(query.department ? { department: query.department } : {}),
|
||||
@@ -852,7 +893,7 @@ function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUnauthoriz
|
||||
...(query.product ? { product: query.product } : {}),
|
||||
...(query.projectGroup ? { projectGroup: query.projectGroup } : {}),
|
||||
...(query.includeUnassigned ? { includeUnassigned: true } : {}),
|
||||
}), [query.year, query.month, query.quarter, query.department, query.group, query.product, query.projectGroup, query.includeUnassigned]);
|
||||
}), [query.year, query.month, query.quarter, query.department, query.group, query.product, query.productSearch, query.projectGroup, query.extraFilters, query.includeUnassigned]);
|
||||
const fineQueryKey = JSON.stringify(fineQuery);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -956,8 +997,8 @@ function DefectParetoPanel({ releaseId, query, externalScrapWeight, onUnauthoriz
|
||||
{ type: 'value', name: '累计占比', min: 0, max: 100, nameTextStyle: { color: ink, fontSize: 10 }, axisLabel: { color: ink, fontSize: 10, formatter: '{value}%' }, splitLine: { show: false } },
|
||||
],
|
||||
series: [
|
||||
{ name: '报废重量', type: 'bar', barMaxWidth: 36, data: items.map(item => ({ value: item.weight, itemStyle: { color: item.kind === 'category' ? '#9aa4b2' : item.key.startsWith('black:') ? blue : teal } })) },
|
||||
{ name: '累计占比', type: 'line', yAxisIndex: 1, symbol: 'circle', symbolSize: 5, lineStyle: { width: 2, color: '#d58c35' }, itemStyle: { color: '#d58c35', borderColor: surface, borderWidth: 1 }, data: cumulative },
|
||||
{ name: '报废重量', type: 'bar', z: 1, barMaxWidth: 36, data: items.map(item => ({ value: item.weight, itemStyle: { color: item.kind === 'category' ? '#9aa4b2' : item.key.startsWith('black:') ? blue : teal } })) },
|
||||
{ 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 },
|
||||
],
|
||||
};
|
||||
instance.setOption(option, { notMerge: true, lazyUpdate: false });
|
||||
@@ -1076,7 +1117,7 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
const rowsRef = useRef(rows);
|
||||
const modeRef = useRef(mode);
|
||||
const stageRef = useRef(stage);
|
||||
const maskNodes = useRef(new Map<string, HTMLDivElement>());
|
||||
const graphicIds = useRef(new Set<string>());
|
||||
const previousSelection = useRef<string | undefined>(undefined);
|
||||
const selectionReady = useRef(false);
|
||||
const [lineSelectedPeriod, setLineSelectedPeriod] = useState<string | undefined>(undefined);
|
||||
@@ -1118,6 +1159,7 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
if (!container.current || !hasRows) return;
|
||||
const instance = echarts.init(container.current, undefined, { renderer: 'svg' });
|
||||
chart.current = instance;
|
||||
graphicIds.current.clear();
|
||||
instance.on('click', params => {
|
||||
if (params.componentType !== 'series' && params.componentType !== 'xAxis') return;
|
||||
const currentRows = rowsRef.current;
|
||||
@@ -1177,7 +1219,7 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
xAxis: { type: 'category', data: labels, triggerEvent: true, axisLine: { lineStyle: { color: line } }, axisLabel: { color: ink, margin: 12 }, axisTick: { show: false } },
|
||||
};
|
||||
let option: echarts.EChartsCoreOption;
|
||||
const pointStyle = { symbol: 'circle', symbolSize: 5, showSymbol: true, emphasis: { focus: 'none' as const, scale: 1.35 }, connectNulls: false };
|
||||
const pointStyle = { z: 10, symbol: 'circle', symbolSize: 5, showSymbol: true, emphasis: { focus: 'none' as const, scale: 1.35 }, connectNulls: false };
|
||||
if (mode === 'production') {
|
||||
const rates = [...rows.flatMap(row => [visibleCompositeRate(row, rateBasis), visibleStageRate(row, 'black'), visibleStageRate(row, 'bright', rateBasis)]).filter((value): value is number => value != null).map(value => value * 100), ...(targetRate == null ? [] : [targetRate])];
|
||||
const minRate = rates.length ? Math.max(0, Math.floor(Math.min(...rates) - 2)) : 0;
|
||||
@@ -1198,8 +1240,8 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
{ type: 'value', name: '合格率 / %', nameGap: 18, min: minRate, max: maxRate, nameTextStyle: { color: ink, align: 'right', fontSize: 11 }, axisLabel: { color: ink, formatter: '{value}%', fontSize: 11 }, axisLine: { show: false }, axisTick: { show: false }, splitLine: { show: false } },
|
||||
],
|
||||
series: [
|
||||
{ id: 'qualified-weight', name: `${stageName}合格重量`, type: 'bar', stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: barColor }, emphasis: { itemStyle: { color: blue } }, data: barData('qualifiedWeight') },
|
||||
{ id: 'scrap-weight', name: `${stageName}报废重量`, type: 'bar', stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: '#edaa83' }, emphasis: { itemStyle: { color: '#e58e5d' } }, data: barData('scrapWeight') },
|
||||
{ id: 'qualified-weight', name: `${stageName}合格重量`, type: 'bar', z: 1, stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: barColor }, emphasis: { itemStyle: { color: blue } }, data: barData('qualifiedWeight') },
|
||||
{ id: 'scrap-weight', name: `${stageName}报废重量`, type: 'bar', z: 1, stack: 'weight', yAxisIndex: 0, barWidth, itemStyle: { color: '#edaa83' }, emphasis: { itemStyle: { color: '#e58e5d' } }, data: barData('scrapWeight') },
|
||||
{ id: 'composite-rate', name: rateBasis === 'original' ? '综合合格率' : '综合调整率', 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: rateBasis === 'original' ? '亮片合格率' : '亮片不含本部报废调整率', 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))) },
|
||||
@@ -1211,7 +1253,7 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
option = {
|
||||
...base,
|
||||
yAxis: [{ type: 'value', name: '不良率 / %', nameGap: 18, nameTextStyle: { color: ink, align: 'left', fontSize: 11 }, axisLabel: { color: ink, formatter: '{value}%', fontSize: 11 }, axisLine: { show: false }, axisTick: { show: false }, splitLine: { lineStyle: { color: line, type: 'dashed' } } }],
|
||||
series: names.map((name, index) => ({ id: `defect-${stage}-${name}`, name, type: 'line' as const, ...pointStyle, lineStyle: { width: 2, color: palette[index % palette.length] }, itemStyle: { color: palette[index % palette.length] }, data: rows.map(row => { const defect = row[stage].defects.find(item => item.name === name); return defect?.rate == null ? null : defect.rate * 100; }) })),
|
||||
series: names.map((name, index) => ({ id: `defect-${stage}-${name}`, name, type: 'line' as const, ...pointStyle, lineStyle: { width: 2, color: palette[index % palette.length] }, itemStyle: { color: palette[index % palette.length] }, data: rows.map(row => { const defect = row[stage].defects.find(item => item.name === name); return rateNumber(defectWeightRate(defect?.weight, row[stage].totalWeight)); }) })),
|
||||
};
|
||||
}
|
||||
instance.setOption(option, { replaceMerge: ['series', 'yAxis'], lazyUpdate: false });
|
||||
@@ -1225,34 +1267,36 @@ function TrendChart({ rows, mode, stage, rateBasis, targetRate, selectedPeriod,
|
||||
}, [lineSelectedPeriod, selectedPeriod]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const instance = chart.current;
|
||||
if (!instance || !container.current) return;
|
||||
const previous = previousSelection.current;
|
||||
const changed = selectionReady.current && previous !== dimmedPeriod;
|
||||
const animate = changed && !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
for (const mask of barMasks) {
|
||||
const node = maskNodes.current.get(mask.period);
|
||||
if (!node) continue;
|
||||
const wasDimmed = previous != null && mask.period !== previous;
|
||||
const surface = getComputedStyle(container.current).getPropertyValue('--surface').trim() || '#ffffff';
|
||||
const masks = mode === 'production' ? barMasks : [];
|
||||
const nextIds = new Set(masks.flatMap(mask => [`wash-${mask.period}`, `focus-${mask.period}`]));
|
||||
// Keep the animated bar treatment inside the chart's paint order: bars 1,
|
||||
// wash 2, focus 3, lines 10. A DOM overlay would also cover every line.
|
||||
const elements = masks.flatMap(mask => {
|
||||
const dimmed = dimmedPeriod != null && mask.period !== dimmedPeriod;
|
||||
if (!changed && node.getAnimations().length) continue;
|
||||
node.getAnimations().forEach(animation => animation.cancel());
|
||||
const finalClip = dimmed ? 'inset(0 0 0 0)' : 'inset(0 0 100% 0)';
|
||||
node.style.clipPath = finalClip;
|
||||
if (animate && wasDimmed !== dimmed) {
|
||||
node.animate([
|
||||
{ clipPath: dimmed ? 'inset(0 0 100% 0)' : 'inset(0 0 0 0)' },
|
||||
{ clipPath: finalClip },
|
||||
], { duration: 340, easing: 'cubic-bezier(.22, .8, .25, 1)' });
|
||||
}
|
||||
}
|
||||
return [
|
||||
{ id: `wash-${mask.period}`, type: 'rect', silent: true, z: 2, transition: ['shape'],
|
||||
shape: { x: mask.left, y: mask.top, width: mask.width, height: dimmed ? mask.height : 0 }, style: { fill: surface, opacity: .72 } },
|
||||
{ id: `focus-${mask.period}`, type: 'rect', silent: true, z: 3, transition: ['style'],
|
||||
shape: { x: mask.left, y: mask.top, width: mask.width, height: mask.height },
|
||||
style: { fill: 'transparent', stroke: 'rgba(137,165,255,.7)', lineWidth: 1, shadowBlur: 11, shadowColor: 'rgba(117,151,255,.26)', opacity: dimmedPeriod === mask.period ? 1 : 0 } },
|
||||
];
|
||||
});
|
||||
const removed = [...graphicIds.current].filter(id => !nextIds.has(id)).map(id => ({ id, $action: 'remove' as const }));
|
||||
instance.setOption({ graphic: { animation: animate, animationDurationUpdate: 340, animationEasingUpdate: 'cubicOut', elements: [...elements, ...removed] } });
|
||||
graphicIds.current = nextIds;
|
||||
previousSelection.current = dimmedPeriod;
|
||||
selectionReady.current = true;
|
||||
}, [dimmedPeriod, barMasks]);
|
||||
}, [dimmedPeriod, barMasks, mode, themeRevision]);
|
||||
|
||||
return <div className="chart-viewport">
|
||||
<div className="chart-surface">
|
||||
<div className={`chart-container ${rows.length ? '' : 'chart-empty'}`} ref={container} role="img" aria-label={mode === 'production' ? '重量和合格率趋势' : `${stage === 'black' ? '黑片' : '亮片'}不良率趋势`} />
|
||||
{barMasks.map(mask => <div key={mask.period} className="chart-bar-wash" ref={node => { if (node) maskNodes.current.set(mask.period, node); else maskNodes.current.delete(mask.period); }} style={{ left: mask.left, top: mask.top, width: mask.width, height: mask.height }} />)}
|
||||
{barMasks.map(mask => <div key={`focus-${mask.period}`} className={`chart-bar-focus ${dimmedPeriod === mask.period ? 'active' : ''}`} style={{ left: mask.left, top: mask.top, width: mask.width, height: mask.height }} />)}
|
||||
</div>
|
||||
{!rows.length && <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前数据未返回趋势" />}
|
||||
</div>;
|
||||
@@ -1332,11 +1376,13 @@ function RecordsDrawer({
|
||||
const exportRecords = async () => {
|
||||
const params: RecordExportParams = {
|
||||
year: recordQuery.year,
|
||||
...(recordQuery.extraFilters ? { extraFilters: recordQuery.extraFilters } : {}),
|
||||
...(recordQuery.month !== undefined ? { month: recordQuery.month } : {}),
|
||||
...(recordQuery.quarter !== undefined ? { quarter: recordQuery.quarter } : {}),
|
||||
...(recordQuery.department !== undefined ? { department: recordQuery.department } : {}),
|
||||
...(recordQuery.group !== undefined ? { group: recordQuery.group } : {}),
|
||||
...(recordQuery.product !== undefined ? { product: recordQuery.product } : {}),
|
||||
...(recordQuery.productSearch !== undefined ? { productSearch: recordQuery.productSearch } : {}),
|
||||
...(recordQuery.projectGroup !== undefined ? { projectGroup: recordQuery.projectGroup } : {}),
|
||||
...(recordQuery.includeUnassigned !== undefined ? { includeUnassigned: recordQuery.includeUnassigned } : {}),
|
||||
...(recordQuery.releaseId !== undefined ? { releaseId: recordQuery.releaseId } : {}),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { Alert, App, AutoComplete, Button, Checkbox, Form, Input, InputNumber, Modal, Select, Switch, Table, Tabs, Tag } from 'antd';
|
||||
import { Alert, App, AutoComplete, Button, Checkbox, Form, Input, InputNumber, Modal, Select, Switch, Tabs, Tag } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { QualityTable as Table } from './QualityTable';
|
||||
import { DownloadOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
import './structured-config-editors.css';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.management-page.analysis-simple-page{gap:12px}
|
||||
.analysis-simple-page .analysis-workspace{height:calc(100dvh - 105px);min-height:540px;grid-template-columns:205px minmax(0,1fr)}
|
||||
.analysis-simple-page .analysis-workspace{height:calc(var(--dynamic-viewport-height) - 105px);min-height:540px;grid-template-columns:205px minmax(0,1fr)}
|
||||
.page-heading.page-actions-only{min-height:0;margin:0;justify-content:flex-end}
|
||||
.analysis-composer-buttons{display:flex;align-items:center;gap:8px}
|
||||
.analysis-simple-page .analysis-chat-panel{min-height:0;overflow:hidden;background:#fff}
|
||||
@@ -7,6 +7,7 @@
|
||||
.analysis-simple-page .analysis-session-list{flex:1;overflow:auto}
|
||||
.analysis-simple-page .analysis-session-item{padding:14px 12px;gap:5px}
|
||||
.analysis-simple-page .analysis-session-item small{font-size:11px}
|
||||
.analysis-session-state{float:right;color:#1680c5;font-weight:500;margin-left:6px}
|
||||
.analysis-simple-page .analysis-conversation{min-height:0;gap:26px;padding:30px max(24px,calc((100% - 850px)/2));scroll-behavior:smooth;overscroll-behavior:contain}
|
||||
.analysis-simple-page .analysis-turn{gap:16px}
|
||||
.analysis-simple-page .analysis-question{width:auto;max-width:85%;padding:10px 16px;border:0;border-radius:12px;background:#eef2fa}
|
||||
@@ -21,21 +22,38 @@
|
||||
.ai-markdown code{padding:1px 4px;border-radius:3px;background:#f0f3f7;font:0.92em ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere}
|
||||
.ai-markdown pre{max-width:100%;overflow:auto;padding:12px;background:#f4f6f9;border:1px solid #e5eaf0;white-space:pre-wrap;overflow-wrap:anywhere}
|
||||
.ai-markdown pre code{padding:0;background:transparent;white-space:pre-wrap}
|
||||
.ai-markdown-table-wrap{max-width:100%;margin:10px 0 14px;overflow:auto}
|
||||
.ai-markdown-table-wrap{max-width:100%;margin:10px 0 14px;overflow:auto;border:1px solid var(--line,#dfe5ed);border-radius:6px;background:var(--surface,#fff)}
|
||||
.ai-markdown table{width:100%;border-collapse:collapse;table-layout:fixed;font-size:13px;line-height:1.65}
|
||||
.ai-markdown th,.ai-markdown td{padding:7px 9px;border:1px solid #dfe5ed;text-align:left;vertical-align:top;overflow-wrap:anywhere;word-break:break-word}
|
||||
.ai-markdown th{background:#f4f6f9;font-weight:650}
|
||||
.ai-markdown th,.ai-markdown td{padding:9px 12px;border:1px solid var(--line,#dfe5ef);text-align:center;vertical-align:middle;overflow-wrap:anywhere;word-break:break-word}
|
||||
.ai-markdown th{background:color-mix(in srgb,var(--surface,#fff) 84%,var(--blue-soft,#eef1ff));font-weight:650}
|
||||
.ai-markdown tbody tr:nth-child(even)>td{background:color-mix(in srgb,var(--surface,#fff) 96%,var(--blue-soft,#eef1ff))}
|
||||
.ai-markdown .ai-markdown-index{width:64px;color:var(--muted-ink,#738198);font-variant-numeric:tabular-nums;white-space:nowrap}
|
||||
.analysis-simple-page .analysis-message-actions{display:flex;gap:6px;margin-top:10px}
|
||||
.analysis-simple-page .analysis-message-actions .ant-btn{color:#627189}
|
||||
.analysis-simple-page .analysis-chat-notice{font-size:12px;color:#93671e}
|
||||
.analysis-simple-page .analysis-progress{background:transparent;padding:0;gap:10px;color:#63718a}
|
||||
.analysis-process{border:1px solid #e5ebf3;border-radius:8px;background:#fafcfe;min-width:0}
|
||||
.analysis-process-toggle{display:flex;align-items:center;gap:9px;padding:11px 13px;width:100%;border:0;background:transparent;color:#536780;text-align:left;cursor:pointer;font:inherit}
|
||||
.analysis-process-toggle>span:nth-last-child(2){margin-left:auto;font-size:12px;font-weight:400;color:#7b899d}
|
||||
.analysis-process-toggle strong{font-size:13px;font-weight:550}
|
||||
.analysis-process-body{padding:0 14px 12px;max-height:360px;overflow:auto;overscroll-behavior:contain}
|
||||
.analysis-process-body ol{list-style:none;padding:0;margin:0}
|
||||
.analysis-process-body li{padding:10px 0;border-top:1px solid #edf1f6}
|
||||
.analysis-process-step{display:flex;align-items:center;gap:8px;font-size:12px;color:#63758b}
|
||||
.analysis-process-step strong{color:#3e536e;font-weight:500}
|
||||
.analysis-process-step>span:last-child{margin-left:auto;color:#8390a2;white-space:nowrap}
|
||||
.analysis-process-body details{margin:7px 0 0 23px;color:#7b899c;font-size:12px}
|
||||
.analysis-process-body summary{cursor:pointer}
|
||||
.analysis-process-body pre{margin:6px 0;white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.8 inherit;color:#5e7088}
|
||||
.analysis-process-body li p,.analysis-process-current{font-size:12px;line-height:1.8;color:#7b899b;margin:5px 0 0 23px}
|
||||
.analysis-process-current{margin:10px 0 0;color:#526b8a}
|
||||
.analysis-simple-page .analysis-composer{padding:16px max(24px,calc((100% - 850px)/2));border-top:0;gap:7px}
|
||||
.analysis-simple-page .analysis-composer textarea{font-size:14px;padding:13px 15px;border-radius:10px!important;resize:none}
|
||||
.analysis-simple-page .ai-actions{font-size:11px;color:#7a8598}
|
||||
.analysis-simple-page .analysis-empty{gap:10px}
|
||||
.analysis-simple-page .analysis-empty strong{font-size:20px;color:#3c4d67;font-weight:550}
|
||||
.analysis-simple-page .analysis-empty span{font-size:13px;color:#7b8799}
|
||||
.analysis-report-preview{max-height:65dvh;overflow:auto;background:#edf1f5;border:1px solid #e6ebf2}
|
||||
.analysis-report-preview{max-height:calc(var(--dynamic-viewport-height) * .65);overflow:auto;background:#edf1f5;border:1px solid #e6ebf2}
|
||||
.analysis-report-preview .q-report{margin:auto}
|
||||
.analysis-report-preview .native-analysis-report-frame{display:block;width:900px;max-width:none;margin:0 auto;border:0;background:#fff}
|
||||
.analysis-report-preview .native-analysis-report{box-sizing:border-box;width:900px;margin:0 auto;padding:48px;background:#fff;color:#263346;font:15px/1.85 -apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;overflow-wrap:anywhere;word-break:break-word}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
type StorageAccess = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
||||
export const ACTIVE_ANALYSIS_STATUSES = new Set(['QUEUED', 'RUNNING', 'PLANNING', 'TOOL_RUNNING', 'PROCESSING']);
|
||||
export function analysisIsRunning(status: unknown): boolean { return ACTIVE_ANALYSIS_STATUSES.has(String(status || '').toUpperCase()); }
|
||||
const keyFor = (userId: string) => `quality.analysis.lastSession.${userId}`;
|
||||
const selections = new Map<string, number>();
|
||||
export function beginAnalysisSelection(userId: string): number {
|
||||
const next = (selections.get(userId) || 0) + 1;
|
||||
selections.set(userId, next); return next;
|
||||
}
|
||||
export function rememberPendingAnalysisSession(userId: string, id: string, selection: number, storage?: StorageAccess): void {
|
||||
if (selections.get(userId) === selection) rememberAnalysisSession(userId, id, storage);
|
||||
}
|
||||
|
||||
export function rememberAnalysisSession(userId: string, id: string, storage?: StorageAccess): void {
|
||||
try {
|
||||
const target = storage || window.localStorage;
|
||||
if (id) target.setItem(keyFor(userId), id); else target.removeItem(keyFor(userId));
|
||||
} catch { /* Storage may be disabled; server history remains available. */ }
|
||||
}
|
||||
|
||||
export function defaultAnalysisSession(userId: string, sessions: Record<string, unknown>[], storage?: StorageAccess): string {
|
||||
let remembered: string | null = null;
|
||||
try { remembered = (storage || window.localStorage).getItem(keyFor(userId)); } catch { /* use server history */ }
|
||||
if (remembered && sessions.some(item => item.id === remembered)) return remembered;
|
||||
return sessions.length ? String(sessions[0].id || '') : '';
|
||||
}
|
||||
|
||||
export function activeAnalysisTurn(turns: Record<string, unknown>[]): Record<string, unknown> | undefined {
|
||||
return turns.slice().reverse().find(turn => analysisIsRunning(turn.status));
|
||||
}
|
||||
|
||||
export function settledAnalysisTurn(id: string, question: string, detail: Record<string, unknown>, streamed: Record<string, unknown>, terminalEventStatus: string): Record<string, unknown> {
|
||||
const detailResult = detail.result && typeof detail.result === 'object' && !Array.isArray(detail.result) ? detail.result as Record<string, unknown> : {};
|
||||
const finalStatuses = new Set(['COMPLETED', 'PARTIAL', 'FAILED', 'CANCELLED', 'NEEDS_CLARIFICATION']);
|
||||
const detailStatus = String(detail.status || '').toUpperCase();
|
||||
const status = finalStatuses.has(detailStatus) ? detailStatus : terminalEventStatus || detailStatus;
|
||||
// An SSE rotation may stop on a partial answer just before the saved task
|
||||
// finishes. The final durable result must win, even when it is empty/redacted.
|
||||
const durable = { ...detail, ...detailResult };
|
||||
const result = finalStatuses.has(detailStatus) ? { ...streamed, ...durable } : { ...durable, ...streamed };
|
||||
delete result.result;
|
||||
return { ...result, id, question, status, result };
|
||||
}
|
||||
+9
-1
@@ -1,6 +1,7 @@
|
||||
import { publicErrorMessage } from './publicDataDisplay';
|
||||
import type {
|
||||
AuthUser,
|
||||
FilterField,
|
||||
Collection,
|
||||
FineDefectTopResponse,
|
||||
MetricsResponse,
|
||||
@@ -159,6 +160,10 @@ async function mutateForm<T>(path: string, body: FormData): Promise<T> {
|
||||
}
|
||||
|
||||
export const api = {
|
||||
filterFields(manage = false) { return request<FilterField[]>(`/api/filter-fields?manage=${manage}`); },
|
||||
filterFieldOptions(key: string, search = '') { return request<{ values: string[]; hasMore: boolean }>(`/api/filter-fields/options?${toQuery({key, search})}`); },
|
||||
filterFieldColumns() { return request<{ black: string[]; bright: string[] }>('/api/filter-fields/columns'); },
|
||||
saveFilterFields(fields: FilterField[]) { return mutate<FilterField[]>('/api/filter-fields', fields, 'PUT'); },
|
||||
refreshCsrf,
|
||||
async me(): Promise<AuthUser> {
|
||||
const result = await request<{ user: AuthUser }>('/api/auth/me');
|
||||
@@ -350,6 +355,9 @@ export const api = {
|
||||
deleteDataWorkflowSource(id: string) {
|
||||
return mutate<DataWorkflowOperation>(`/api/data-workflow/sources/${encodeURIComponent(id)}/delete`, {});
|
||||
},
|
||||
deleteDataWorkflowSources(body: { sourceIds: string[]; expectedCurrentReleaseId: string | null }) {
|
||||
return mutate<DataWorkflowOperation>('/api/data-workflow/sources/delete-batch', body);
|
||||
},
|
||||
restoreDataWorkflowSource(id: string) {
|
||||
return mutate<DataWorkflowOperation>(`/api/data-workflow/sources/${encodeURIComponent(id)}/restore`, {});
|
||||
},
|
||||
@@ -666,7 +674,7 @@ function toQuery(values: object): string {
|
||||
if (Array.isArray(value)) value.forEach(item => {
|
||||
if (item !== undefined && item !== null && item !== '') query.append(key, String(item));
|
||||
});
|
||||
else query.set(key, String(value));
|
||||
else query.set(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
||||
}
|
||||
return query.toString();
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@
|
||||
}
|
||||
|
||||
.target-rule-list {
|
||||
max-height: 50vh;
|
||||
max-height: calc(var(--viewport-height) * .5);
|
||||
overflow: auto;
|
||||
border: 1px solid #dce3ee;
|
||||
}
|
||||
@@ -410,7 +410,7 @@
|
||||
}
|
||||
|
||||
.target-editor-modal .ant-modal-body {
|
||||
max-height: calc(100vh - 180px);
|
||||
max-height: calc(var(--viewport-height) - 180px);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import QualityWorkspace from './QualityWorkspace';
|
||||
import { getStoredWorkspaceThemeId, getWorkspaceTheme, workspaceThemeStorageKey, type WorkspaceThemeId } from './ui-themes';
|
||||
import './styles.css';
|
||||
import './dark-theme.css';
|
||||
import './quality-table.css';
|
||||
|
||||
function QualityCenterApp() {
|
||||
const [themeId, setThemeId] = useState<WorkspaceThemeId>(getStoredWorkspaceThemeId);
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
}
|
||||
|
||||
.management-page .analysis-workspace {
|
||||
min-height: min(680px, calc(100svh - 170px));
|
||||
min-height: min(680px, calc(var(--small-viewport-height) - 170px));
|
||||
grid-template-columns: minmax(210px, 240px) minmax(0, 1fr);
|
||||
align-items: stretch;
|
||||
gap: 14px;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
.nc-advanced-records[open] > summary { margin-bottom: 12px; }
|
||||
.nc-workflow-modal { top: 24px; padding-bottom: 24px; }
|
||||
.nc-workflow-modal .ant-modal-container, .nc-workflow-modal .ant-modal-content, .nc-workflow-modal .ant-input, .nc-workflow-modal .ant-input-number, .nc-workflow-modal .ant-select-selector, .nc-workflow-modal .ant-btn, .nc-workflow-modal .ant-alert { border-radius: 0 !important; }
|
||||
.nc-workflow-modal .ant-modal-body { display: flex; flex-direction: column; gap: 18px; max-height: calc(100vh - 240px); overflow-y: auto; overflow-x: hidden; padding-right: 4px; color: var(--ink); }
|
||||
.nc-workflow-modal .ant-modal-body { display: flex; flex-direction: column; gap: 18px; max-height: calc(var(--viewport-height) - 240px); overflow-y: auto; overflow-x: hidden; padding-right: 4px; color: var(--ink); }
|
||||
.nc-workflow-modal .ant-modal-title { font-size: 20px; color: var(--ink); }
|
||||
.nc-workflow-modal h3 { font-size: 14px; margin: 4px 0 12px; color: var(--ink); }
|
||||
.nc-workflow-modal .ant-form-item { margin-bottom: 16px; }
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
.quality-table-frame {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--metric-grid-head, #aebccc);
|
||||
border-inline-color: var(--line, #dfe5ef);
|
||||
border-radius: 6px;
|
||||
background: var(--surface, #fff);
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-wrapper,
|
||||
.quality-table-frame .ant-table-container {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table {
|
||||
color: var(--ink, #202a3b);
|
||||
background: transparent;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-container {
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-thead > tr > th {
|
||||
padding: 10px 12px !important;
|
||||
background: color-mix(in srgb, var(--surface, #fff) 84%, var(--blue-soft, #eef1ff)) !important;
|
||||
color: var(--ink, #202a3b);
|
||||
font-size: 12px;
|
||||
font-weight: 650;
|
||||
line-height: 1.45;
|
||||
text-align: center;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-tbody > tr > td {
|
||||
padding: 9px 12px !important;
|
||||
color: var(--ink, #202a3b);
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-bordered .ant-table-cell {
|
||||
border-inline-end: 1px solid var(--line, #dfe5ef) !important;
|
||||
border-bottom: 1px solid var(--line, #dfe5ef) !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-bordered .ant-table-thead > tr > th {
|
||||
border-inline-end-color: var(--line, #dfe5ef) !important;
|
||||
border-bottom-color: var(--metric-grid-head, #aebccc) !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-tbody > tr:nth-child(even) > td {
|
||||
background: color-mix(in srgb, var(--surface, #fff) 96%, var(--blue-soft, #eef1ff));
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-tbody > tr:hover > td,
|
||||
.quality-table-frame .ant-table-tbody > tr.ant-table-row:hover > td {
|
||||
background: var(--hover, #f5f6ff) !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-cell.quality-table-index-column {
|
||||
color: var(--muted-ink, #738198);
|
||||
background: color-mix(in srgb, var(--surface, #fff) 91%, var(--blue-soft, #eef1ff));
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-thead > tr > th.quality-table-index-column {
|
||||
color: var(--ink, #202a3b);
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-pagination {
|
||||
margin: 10px 12px !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-pagination .ant-pagination-total-text {
|
||||
color: var(--muted-ink, #738198);
|
||||
}
|
||||
|
||||
/* Fixed columns need a clear edge, but Ant Design's default sticky shadow is too dark. */
|
||||
.ant-table-wrapper [class*='ant-table-cell-fix']::after {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.ant-table-wrapper .ant-table-container::before,
|
||||
.ant-table-wrapper .ant-table-container::after {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.management-page .quality-table-frame .ant-table-bordered > .ant-table-container {
|
||||
border-inline-start: 0;
|
||||
}
|
||||
|
||||
.management-page .quality-table-frame .ant-table-bordered .ant-table-cell {
|
||||
border-inline-end: 1px solid var(--line, #dfe5ef) !important;
|
||||
border-bottom: 1px solid var(--line, #dfe5ef) !important;
|
||||
}
|
||||
|
||||
.management-page .quality-table-frame .ant-table-bordered .ant-table-thead > tr > th {
|
||||
border-inline-end-color: var(--line, #dfe5ef) !important;
|
||||
border-bottom-color: var(--metric-grid-head, #aebccc) !important;
|
||||
}
|
||||
|
||||
.management-page .quality-table-frame .ant-table-tbody > tr:last-child > td {
|
||||
border-bottom: 1px solid var(--line, #dfe5ef) !important;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table.ant-table-bordered .ant-table-tbody > tr.ant-table-measure-row > td {
|
||||
height: 0 !important;
|
||||
padding: 0 !important;
|
||||
border: 0 !important;
|
||||
font-size: 0 !important;
|
||||
line-height: 0 !important;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.quality-table-frame {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.quality-table-frame .ant-table-thead > tr > th,
|
||||
.quality-table-frame .ant-table-tbody > tr > td {
|
||||
padding: 8px 9px !important;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
.structured-config-editor .ant-table-thead > tr > th { background: #f6f8fd; color: var(--ink); }
|
||||
.structured-config-editor .ant-table-cell { font-size: 12px; overflow-wrap: anywhere; }
|
||||
.structured-config-editor .ant-table-container, .structured-config-editor .ant-btn, .structured-config-editor .ant-input, .structured-config-editor .ant-select-selector, .structured-config-modal .ant-btn, .structured-config-modal .ant-input, .structured-config-modal .ant-select-selector { border-radius: 0 !important; }
|
||||
.structured-config-modal .ant-modal-body { max-height: 72vh; overflow-y: auto; padding-top: 16px; }
|
||||
.structured-config-modal .ant-modal-body { max-height: calc(var(--viewport-height) * .72); overflow-y: auto; padding-top: 16px; }
|
||||
.structured-config-modal p { color: var(--ink); font-size: 12px; line-height: 1.65; }
|
||||
.structured-config-modal .ant-checkbox-wrapper { margin: 12px 0; }
|
||||
.structured-config-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
||||
|
||||
+49
-11
@@ -13,14 +13,20 @@
|
||||
--sidebar-surface: #f8fafd;
|
||||
--sidebar: 202px;
|
||||
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
--ui-scale: .8;
|
||||
--viewport-height: calc(100vh / var(--ui-scale));
|
||||
--dynamic-viewport-height: calc(100dvh / var(--ui-scale));
|
||||
--small-viewport-height: calc(100svh / var(--ui-scale));
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html { zoom: var(--ui-scale); }
|
||||
@media (max-width: 760px) { :root { --ui-scale: 1; } }
|
||||
html, body, #root { min-width: 320px; min-height: 100%; margin: 0; }
|
||||
body { color: var(--ink); background: #f4f6fb; font-size: 14px; }
|
||||
button, input, textarea, select { font: inherit; }
|
||||
button { color: inherit; }
|
||||
.app-shell { min-height: 100vh; }
|
||||
.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); }
|
||||
.brand { display: flex; align-items: center; gap: 11px; min-height: 34px; padding: 0 7px; border: 0; background: transparent; text-align: left; font-size: 19px; font-weight: 700; cursor: pointer; }
|
||||
.brand-mark { display: inline-flex; align-items: center; gap: 2px; width: 22px; height: 23px; transform: skew(-17deg); }
|
||||
@@ -43,14 +49,14 @@ button { color: inherit; }
|
||||
.user-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.user-copy small { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.user-block .ant-btn { width: 28px; padding: 0; }
|
||||
.main-column { min-height: 100vh; margin-left: var(--sidebar); }
|
||||
.main-column { min-height: var(--viewport-height); margin-left: var(--sidebar); }
|
||||
.topbar { position: sticky; top: 0; z-index: 40; display: flex; height: 44px; align-items: center; justify-content: space-between; padding: 0 22px; background: #ffffff; border-bottom: 1px solid var(--line); }
|
||||
.breadcrumb { display: flex; align-items: center; gap: 10px; font-size: 12px; }
|
||||
.breadcrumb strong { font-weight: 650; }
|
||||
.breadcrumb-slash { color: #63738a; }
|
||||
.top-organization { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; }
|
||||
.mobile-brand { display: none; }
|
||||
.page-content { width: 100%; max-width: 1920px; min-width: 0; margin: 0 auto; padding: 15px 20px 20px; }
|
||||
.page-content { width: 100%; min-width: 0; margin: 0; padding: 15px 20px 20px; }
|
||||
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 0 !important; }
|
||||
.query-page { display: flex; min-width: 0; flex-direction: column; gap: 11px; }
|
||||
.query-toolbar { position: sticky; top: 53px; z-index: 35; display: flex; min-height: 48px; flex-wrap: wrap; align-items: center; gap: 10px 13px; padding: 7px 11px; }
|
||||
@@ -73,6 +79,7 @@ button { color: inherit; }
|
||||
.metric-card:hover { background: #f8faff; }
|
||||
.metric-card.primary { background: #e8efff; }
|
||||
.metric-label { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 650; }
|
||||
.metric-card.primary .metric-label { font-size: clamp(15px, 1.5vw, 18px); font-weight: 700; }
|
||||
.metric-value { overflow: hidden; max-width: 100%; font: 600 clamp(22px, 2.15vw, 31px)/1.15 var(--mono); letter-spacing: -1.2px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.metric-card.primary .metric-value { font-size: clamp(26px, 2.5vw, 36px); }
|
||||
.metric-card.black .metric-value { color: var(--blue-dark); }
|
||||
@@ -129,11 +136,8 @@ button { color: inherit; }
|
||||
.trend-object .ant-select { width: min(420px, 100%); }
|
||||
.chart-viewport { width: 100%; overflow-x: auto; }
|
||||
.chart-surface { position: relative; width: 100%; min-width: 0; }
|
||||
.chart-container { width: 100%; height: 380px; min-width: 0; }
|
||||
.chart-bar-wash, .chart-bar-focus { position: absolute; pointer-events: none; }
|
||||
.chart-bar-wash { z-index: 1; background: var(--surface); opacity: .72; clip-path: inset(0 0 100% 0); }
|
||||
.chart-bar-focus { z-index: 2; border: 1px solid rgba(137, 165, 255, .7); box-shadow: 0 0 11px rgba(117, 151, 255, .26); opacity: 0; transition: opacity 240ms ease-out; }
|
||||
.chart-bar-focus.active { opacity: 1; }
|
||||
/* Keep SVG chart coordinates aligned with pointer events under the app's global UI zoom. */
|
||||
.chart-container { width: 100%; height: calc(380px * var(--ui-scale)); min-width: 0; zoom: calc(1 / var(--ui-scale)); }
|
||||
.chart-footnote { display: flex; justify-content: space-between; gap: 12px; padding: 0 13px 10px; font-size: 11px; }
|
||||
.defects-panel { min-height: 120px; }
|
||||
.defect-stage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
|
||||
@@ -141,7 +145,7 @@ button { color: inherit; }
|
||||
.defect-pareto-heading { display: flex; min-height: 38px; flex-wrap: wrap; align-items: baseline; gap: 5px 12px; padding: 8px 1px 0; }
|
||||
.defect-pareto-heading strong { font-size: 13px; font-weight: 650; }
|
||||
.defect-pareto-heading span { color: var(--ink); font-size: 11px; }
|
||||
.defect-pareto-chart { width: 100%; height: 470px; min-width: 0; }
|
||||
.defect-pareto-chart { width: 100%; height: calc(470px * var(--ui-scale)); min-width: 0; zoom: calc(1 / var(--ui-scale)); }
|
||||
.defect-pareto-status { display: flex; min-height: 52px; align-items: center; justify-content: center; gap: 8px; font-size: 12px; }
|
||||
.defect-stage-column { min-width: 0; padding: 0 12px 10px; }
|
||||
.defect-stage-column + .defect-stage-column { border-left: 1px solid var(--line); }
|
||||
@@ -177,6 +181,7 @@ button { color: inherit; }
|
||||
.records-pagination { display: flex; justify-content: flex-end; margin-top: 14px; }
|
||||
.loading-panel { display: flex; min-height: 170px; align-items: center; justify-content: center; gap: 11px; }
|
||||
.loading-panel.compact { min-height: 240px; }
|
||||
.query-metrics-loading { min-height: 525px; }
|
||||
.chart-footnote span:first-child { overflow-wrap: anywhere; }
|
||||
.management-page { display: flex; flex-direction: column; gap: 12px; }
|
||||
.page-heading { display: flex; min-height: 52px; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
@@ -271,11 +276,11 @@ button { color: inherit; }
|
||||
.access-summary strong { overflow-wrap: anywhere; font-size: 13px; }
|
||||
.resource-tab { padding: 8px 0 0; }
|
||||
.basis-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
|
||||
.screen-state { display: flex; min-height: 100vh; align-items: center; justify-content: center; gap: 12px; background: #f3f5f9; }
|
||||
.screen-state { display: flex; min-height: var(--viewport-height); align-items: center; justify-content: center; gap: 12px; background: #f3f5f9; }
|
||||
.state-card { width: min(390px, calc(100vw - 28px)); padding: 24px; background: #fff; border: 1px solid var(--line); }
|
||||
.state-card strong { font-size: 18px; }
|
||||
.state-card p { margin: 10px 0 16px; overflow-wrap: anywhere; }
|
||||
.login-screen { display: grid; min-height: 100vh; min-height: 100svh; grid-template-columns: minmax(0, 1.13fr) minmax(410px, .87fr); overflow: hidden; background: #fff; }
|
||||
.login-screen { display: grid; min-height: var(--small-viewport-height); grid-template-columns: minmax(0, 1.13fr) minmax(410px, .87fr); overflow: hidden; background: #fff; }
|
||||
.login-art { position: relative; isolation: isolate; min-width: 0; min-height: 640px; overflow: hidden; padding: 36px clamp(30px, 5vw, 76px) 25px; color: #fff; background: linear-gradient(148deg, #4d65ca, #253454 60%, #30456c); }
|
||||
/* Shared with the complaint platform's login artwork. */
|
||||
.login-art::before { content: ''; position: absolute; z-index: 0; width: 580px; height: 580px; border-radius: 50%; border: 1px solid rgba(189,204,255,.12); right: -206px; top: 147px; box-shadow: 0 0 0 70px rgba(189,204,255,.03), 0 0 0 145px rgba(189,204,255,.024); pointer-events: none; }
|
||||
@@ -392,6 +397,7 @@ button { color: inherit; }
|
||||
.metric-table-scroll .ant-table-cell { padding: 5px 8px !important; }
|
||||
.table-footer { align-items: flex-start; flex-direction: column; gap: 4px; padding: 7px 10px; }
|
||||
.chart-container { height: 310px; }
|
||||
.query-metrics-loading { min-height: 410px; }
|
||||
.chart-surface { width: 760px; min-width: 760px; }
|
||||
.trend-chart-shell { min-height: 310px; }
|
||||
.trend-controls { align-items: flex-start; flex-direction: column; padding: 0 10px 8px; }
|
||||
@@ -572,3 +578,35 @@ body { background: var(--background); }
|
||||
.analysis-report-plans { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-top: 12px; }
|
||||
.analysis-report-plans label { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.analysis-reports ul { padding-left: 20px; }
|
||||
|
||||
/* Primary dimensions stay legible; optional source fields are below the main row. */
|
||||
/* Let the three main dimensions share remaining space before any toolbar item wraps. */
|
||||
.query-toolbar { column-gap: 10px; }
|
||||
.query-toolbar > .query-primary-field { flex: 1 1 0; min-width: 140px; max-width: 260px; }
|
||||
.query-primary-field .ant-select { flex: 1 1 0; width: 0; min-width: 0; }
|
||||
.query-period-field { flex: 0 0 auto; }
|
||||
.query-period-field .ant-select { width: 90px; min-width: 90px; }
|
||||
.query-period-month .ant-select { width: 80px; min-width: 80px; }
|
||||
.query-unassigned { margin-left: auto; white-space: nowrap; }
|
||||
.query-toolbar-tail { flex: 0 0 auto; margin-left: 0; }
|
||||
.query-more-toggle { display: flex; flex: 0 0 auto; align-items: center; gap: 3px; min-height: 28px; }
|
||||
.query-more-toggle > .ant-btn { flex-shrink: 0; }
|
||||
.query-filter-summary { color: var(--muted-ink, #657087); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.query-extra-fields { display: flex; flex: 1 0 100%; order: 2; flex-wrap: wrap; gap: 12px 20px; padding: 10px 0 3px; border-top: 1px solid var(--line); }
|
||||
.query-extra-error { flex: 1 0 100%; order: 2; }
|
||||
.query-toolbar .organization-breadcrumb { order: 3; }
|
||||
.query-extra-field .ant-select { width: 240px; min-width: 180px; }
|
||||
.query-options-hint { color: var(--muted-ink, #657087); padding: 8px 12px; font-size: 12px; }
|
||||
.filter-field-settings { padding: 16px; margin-bottom: 16px; }
|
||||
.filter-field-settings p { color: var(--muted-ink, #657087); font-size: 13px; }
|
||||
@media (max-width: 760px) {
|
||||
.query-toolbar > .query-primary-field { flex: 1 1 145px; min-width: 0; max-width: none; }
|
||||
.query-primary-field .ant-select, .query-extra-field .ant-select, .query-period-field .ant-select { width: 100%; min-width: 0; flex: initial; }
|
||||
.query-period-field { flex: 1 1 145px; }
|
||||
.query-extra-fields { align-items: stretch; }
|
||||
.query-extra-field { flex: 1 1 180px; }
|
||||
.query-more-toggle { flex-wrap: wrap; }
|
||||
.query-unassigned { margin-left: auto; }
|
||||
.query-toolbar-tail { flex: 1 0 100%; }
|
||||
.query-filter-summary { order: 3; flex-basis: 100%; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/** Defect share and defect rate have different denominators. */
|
||||
export function defectWeightRate(weight: number | null | undefined, totalWeight: number | null | undefined): number | null {
|
||||
return typeof weight === 'number' && Number.isFinite(weight)
|
||||
&& typeof totalWeight === 'number' && Number.isFinite(totalWeight) && totalWeight > 0
|
||||
? weight / totalWeight : null;
|
||||
}
|
||||
+6
-1
@@ -9,7 +9,9 @@ export interface QueryParams {
|
||||
department?: string;
|
||||
group?: string;
|
||||
product?: string;
|
||||
productSearch?: string;
|
||||
projectGroup?: string;
|
||||
extraFilters?: Record<string, string[]>;
|
||||
view: ViewKind;
|
||||
releaseId?: string;
|
||||
includeUnassigned?: boolean;
|
||||
@@ -29,7 +31,8 @@ export interface RecordsParams extends QueryParams {
|
||||
|
||||
export type RecordExportParams = Pick<
|
||||
QueryParams,
|
||||
'year' | 'month' | 'quarter' | 'department' | 'group' | 'product' | 'projectGroup' | 'includeUnassigned' | 'releaseId'
|
||||
'year' | 'month' | 'quarter' | 'department' | 'group' | 'product' | 'projectGroup' | 'includeUnassigned' | 'releaseId' | 'extraFilters'
|
||||
| 'productSearch'
|
||||
>;
|
||||
|
||||
export interface DefectMetric {
|
||||
@@ -181,3 +184,5 @@ export interface ApiEnvelope<T> {
|
||||
data?: T;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface FilterField { key: string; label: string; blackColumn: string; brightColumn: string; enabled: boolean; allowEmpty: boolean; sortOrder: number }
|
||||
|
||||
Reference in New Issue
Block a user