同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
// Local browser acceptance only. No API, database, model, or production writes.
|
||||
import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { App, ConfigProvider } from 'antd';
|
||||
import QueryPage from '../src/QueryPage';
|
||||
import ManagementPages from '../src/ManagementPages';
|
||||
import '../src/styles.css';
|
||||
import '../src/analysis-chat.css';
|
||||
|
||||
const scenario = new URL(location.href).searchParams.get('case') || 'live';
|
||||
const fixtureUser = { id: 'acceptance-fixture', username: 'fixture', displayName: '本地验收', roles: ['SYSTEM_ADMIN'], departments: [], groups: [] };
|
||||
const input = { mode: 'defects', period: { year: 2026, month: 9 }, stage: 'black' };
|
||||
const timeline = [
|
||||
{ sequence: 1, kind: 'assistant', text: '先核查9月黑片来源细分及对账覆盖。' },
|
||||
{ sequence: 2, kind: 'tool_start', tool: 'mcp_call', toolCallId: 'q1', label: '分析具体缺陷', input, status: 'started' },
|
||||
{ sequence: 3, kind: 'tool_result', tool: 'mcp_call', toolCallId: 'q1', label: '分析具体缺陷', status: 'completed', text: '证据:Q-fixture;返回 1 条结果;来源 10 行;细分与正式大类未对账:仅作为变化线索,不能据此判定正式报废主因' },
|
||||
{ sequence: 4, kind: 'assistant', text: '来源细分缺角重量为12.5 kg;这是变化线索,需核对正式大类。证据 Q-fixture。' },
|
||||
];
|
||||
let state = scenario === 'partial' ? 'PARTIAL' : ['history','legacy'].includes(scenario) ? 'COMPLETED' : scenario === 'retry' ? 'FAILED' : 'RUNNING';
|
||||
let sent = ['history','legacy','partial'].includes(scenario) ? 4 : scenario === 'retry' ? 3 : 0;
|
||||
let sessionTitle = '验收模拟会话';
|
||||
let attempt = 0;
|
||||
const answer = timeline[3].text;
|
||||
const turn = () => ({ id: 'fixture-turn', sessionId: 'fixture-session', status: state, startedAt: '2026-10-23T05:21:11Z', ...(scenario==='partial'?{finishedAt:'2026-10-23T05:25:23Z',durationMs:252000,stopReason:'mcp_error'}:{}),question: '验收模拟:核查9月黑片来源缺陷', engine: 'NAO', answer: sent === 4 ? answer : '', plan: scenario==='legacy'?{nativeRuntime:true,steps:[{label:'核查来源',status:'completed',outputSummary:'已返回结果'}]}:{ nativeRuntime: true, timeline: timeline.slice(0, sent) }, context: { year: 2026, view: 'overall' }, result: { engine: 'NAO', answer: sent === 4 ? answer : '', ...(scenario==='legacy'?{}:{timeline: timeline.slice(0,sent)}) } });
|
||||
const json = (value: unknown) => new Response(JSON.stringify(value), {headers:{'Content-Type':'application/json'}});
|
||||
const encoder = new TextEncoder();
|
||||
window.fetch = async (target, init) => {
|
||||
const url = new URL(String(target), location.origin);
|
||||
const path = url.pathname;
|
||||
if (path === '/api/auth/csrf') return json({token:'fixture-only'});
|
||||
if (path === '/api/options') {
|
||||
if (scenario === 'gateway') return new Response('<html><h1>502 Bad Gateway</h1></html>', {status:502});
|
||||
return json({years:[2026],departments:[],groups:[],products:[],releases:[{id:'fixture-release',name:'本地验收',status:'PUBLISHED'}]});
|
||||
}
|
||||
if (path === '/api/metrics' && scenario==='network') throw new TypeError('Failed to fetch');
|
||||
if (path === '/api/metrics' && scenario==='empty') {
|
||||
const stage={qualifiedWeight:null,scrapWeight:null,totalWeight:null,rate:null,defects:[]};
|
||||
const summary={key:'overall',label:'全公司',department:null,group:null,product:null,compositeRate:null,black:stage,bright:stage,coverage:{blackRows:0,brightRows:0}};
|
||||
return json({release:null,context:{},summary,rows:[],trend:[],defects:{black:[],bright:[]},coverage:{rawRows:0,includedRows:0,excludedBlankRows:0,unmappedRows:0,projectGroupUnconfiguredRows:0,missingStages:[],sourceMonths:[]}});
|
||||
}
|
||||
if (path === '/api/metrics') return new Response('<html><h1>502 Bad Gateway</h1></html>', {status:502});
|
||||
if (path === '/api/filter-fields') return json([]);
|
||||
if (path === '/api/analytics/targets') return json({items:[]});
|
||||
if (path === '/api/analysis/sessions/fixture-session' && init?.method==='PATCH') {sessionTitle=JSON.parse(String(init.body)).title;return json({sessionId:'fixture-session',title:sessionTitle});}
|
||||
if (path === '/api/analysis/sessions') return json({items:[{id:'fixture-session',title:sessionTitle,activeTurnStatus:state,updatedAt:'2026-10-23'}]});
|
||||
if (path === '/api/analysis/sessions/fixture-session') return json({id:'fixture-session',releaseId:'fixture-release',context:{year:2026,view:'overall'},turns:[{...turn(),result:turn().result}]});
|
||||
if (path === '/api/analysis/sessions/fixture-session/turns') return json({items:[turn()]});
|
||||
if (path === '/api/analysis/turns/fixture-turn') return json(turn());
|
||||
if (path.endsWith('/cancel')) { state='CANCELLED'; return json({status:state}); }
|
||||
if (path.endsWith('/retry')) {state='RUNNING';sent=0;attempt=0;return json({turn:turn()});}
|
||||
if (path.endsWith('/events')) {
|
||||
attempt++;
|
||||
const currentAttempt=attempt;
|
||||
let cancelled=false;
|
||||
const body=new ReadableStream({
|
||||
start(controller) {
|
||||
const emit=(id:number, event:string, data:unknown) => { if (!cancelled) controller.enqueue(encoder.encode(`id: ${id}\nevent: ${event}\ndata: ${JSON.stringify(data)}\n\n`)); };
|
||||
const send=(count:number,id:number) => {sent=count;emit(id,'progress',{status:'RUNNING',message:'正在核查模拟数据',timeline:timeline.slice(0,count)});};
|
||||
send(1,1);
|
||||
setTimeout(()=>send(2,2),250);
|
||||
setTimeout(()=>{
|
||||
if (scenario==='disconnect' && currentAttempt===1) { cancelled=true;controller.error(new TypeError('fixture disconnect'));return; }
|
||||
if (scenario==='cancel') return;
|
||||
send(3,3);
|
||||
// A duplicate and an out-of-order snapshot must not overwrite the newer state.
|
||||
emit(3,'progress',{status:'RUNNING',timeline:[]});
|
||||
emit(2,'progress',{status:'RUNNING',timeline:[]});
|
||||
},550);
|
||||
setTimeout(()=>{
|
||||
if (cancelled) return;
|
||||
if (scenario==='cancel') {if(state==='CANCELLED'){emit(4,'cancelled',{status:state,result:turn().result});controller.close();cancelled=true;}return;}
|
||||
sent=4;state='COMPLETED';
|
||||
emit(4,'completed',{status:state,result:turn().result});
|
||||
controller.close();cancelled=true;
|
||||
},scenario==='cancel'?7000:1600);
|
||||
},
|
||||
cancel(){cancelled=true;},
|
||||
});
|
||||
init?.signal?.addEventListener('abort',()=>{void body.cancel().catch(()=>{});});
|
||||
return new Response(body,{headers:{'Content-Type':'text/event-stream'}});
|
||||
}
|
||||
return json({items:[]});
|
||||
};
|
||||
const stopUnauthorized=()=>false;
|
||||
createRoot(document.getElementById('root')!).render(<ConfigProvider><App><main style={{padding:24,maxWidth:1400,margin:'auto'}}><p role="note">本地验收模拟数据,不是业务结论 · 场景 {scenario}</p>{['gateway','empty','network'].includes(scenario)?<QueryPage page="overall" onUnauthorized={stopUnauthorized}/>:<ManagementPages page="analysis" user={fixtureUser} onUnauthorized={stopUnauthorized} onNavigate={()=>{}}/>}</main></App></ConfigProvider>);
|
||||
Reference in New Issue
Block a user