am-freescan/am-web/tests/performance-regression-ui.html
lixiaolong 64db825a9f feat: 完善设备工作流集成、组合执行与主题适配
集成旋转底座、机械臂示教与坐标系,完善扫描参数、电量和框架点复用。增加组合执行、步骤进度与日志,优化首屏和流程画布性能,修复表头主题适配,并保留验证脚本和回归测试。
2026-11-02 17:38:34 +08:00

49 lines
5.3 KiB
HTML

<!doctype html>
<html lang="zh-CN"><meta charset="UTF-8"><title>E2E 性能回归</title>
<style>body{font:14px Arial;margin:16px;background:#f5f7fa}button{margin:0 10px 12px 0}#result{white-space:pre-wrap;background:white;padding:12px}.canvas{height:640px;background:white}.chart-area{height:220px;background:white}</style>
<h1>性能回归</h1><p>仅使用内存数据,不保存测试用例,不执行设备动作。</p><div id="app"></div><pre id="result" role="status">等待测试</pre>
<script type="module">
import {createApp,defineComponent,h,ref,computed,provide,onMounted,onUnmounted,nextTick,KeepAlive,resolveComponent} from 'vue'
import {VueFlow,useVueFlow} from '@vue-flow/core'
import '@vue-flow/core/dist/style.css'
import '@vue-flow/core/dist/theme-default.css'
import {setupStore} from '/src/store/index.ts'
import {setupI18n} from '/src/plugins/vueI18n/index.ts'
import {setupGlobCom} from '/src/components/index.ts'
import {setupCmvr} from '/src/cmvr/setup.ts'
import FlowNode from '/src/cmvr/common/views/flow/vue-flow/FlowNode.vue'
import {createFlowFacade} from '/src/cmvr/common/views/flow/vue-flow/adapter.js'
import {createFlowViewIndex,FLOW_VIEW_INDEX} from '/src/cmvr/common/views/flow/vue-flow/viewIndex.mjs'
import Echart from '/src/components/Echart/src/Echart.vue'
import echarts from '/src/plugins/echarts/index.ts'
const result=value=>{document.querySelector('#result').textContent=JSON.stringify(value,null,2)}
const graph={nodes:[{id:'E2E-start',type:'start',x:150,y:80,properties:{name:'开始',resourceRoles:[{roleKey:'scan',displayName:'现场扫描工位',deviceSlots:[{slotKey:'scanner',displayName:'FreeScan扫描仪'}]}]}},
...Array.from({length:300},(_,i)=>({id:`E2E-n${i}`,type:'serviceNode',x:150+(i%10)*300,y:200+Math.floor(i/10)*160,properties:{name:`扫描步骤${i}`,action:'SCANNER_STATE',executionTarget:{roleKey:'scan',deviceSlotKey:'scanner'},nodeParams:[]}}))],edges:[]}
const FlowPanel=defineComponent({setup(){
const vf=useVueFlow('main-flow'),facade=createFlowFacade(vf)
window.lf=facade
provide(FLOW_VIEW_INDEX,createFlowViewIndex(vf.getNodes))
onMounted(()=>{facade.render(graph);nextTick(()=>vf.fitView())})
onUnmounted(()=>{if(window.lf===facade)delete window.lf})
const rename=async()=>{const t=performance.now();const start=vf.findNode('E2E-start');start.data.properties.resourceRoles[0].displayName='改名后扫描工位';await nextTick();result({operation:'rename',nodes:document.querySelectorAll('.vue-flow__node').length,labels:[...document.querySelectorAll('.flow-node-executor')].filter(el=>el.textContent.includes('改名后扫描工位')).length,renderUpdateMs:Math.round(performance.now()-t)})}
return()=>h('section',[h('button',{onClick:rename},'角色改名'),h('div',{class:'canvas'},[h(VueFlow,{id:'main-flow',minZoom:0.1},{'node-flow-node':props=>h(FlowNode,props)})])])
}})
const ChartPanel=defineComponent({setup(){
const show=ref(true)
const options=Object.freeze({xAxis:{type:'category',data:['A','B']},yAxis:{type:'value'},series:[{type:'bar',data:[12,20]}]})
const dom=()=>document.querySelector('.chart-area [_echarts_instance_]')
const cycles=async()=>{let leaked=0;for(let i=0;i<20;i++){show.value=true;await nextTick();const el=dom();if(!el||!echarts.getInstanceByDom(el))throw Error('Chart did not initialize');show.value=false;await nextTick();if(echarts.getInstanceByDom(el))leaked++}result({operation:'chart-mount-unmount',cycles:20,leakedInstances:leaked,optionsMutated:Object.hasOwn(options,'darkMode')})}
return()=>h('section',[h('button',{onClick:cycles},'连续创建销毁20次'),h('div',{class:'chart-area'},[show.value?h(Echart,{options,height:'200px'}):null])])
}})
const CachedChartPanel=defineComponent({setup(){
const show=ref(true),options={series:[{type:'pie',data:[{value:1},{value:2}]}]}
const suspend=async()=>{const el=document.querySelector('.chart-area [_echarts_instance_]'),chart=echarts.getInstanceByDom(el);let resizeCalls=0;const original=chart.resize;chart.resize=function(...args){resizeCalls++;return original.apply(this,args)};window.dispatchEvent(new Event('resize'));show.value=false;await nextTick();await new Promise(resolve=>setTimeout(resolve,150));const hiddenResizeCalls=resizeCalls;show.value=true;await nextTick();chart.resize=original;result({operation:'chart-deactivate-activate',hiddenResizeCalls,reactivatedResizeCalls:resizeCalls-hiddenResizeCalls,instancePreserved:echarts.getInstanceByDom(el)===chart})}
return()=>h('section',[h('button',{onClick:suspend},'检查缓存页面暂停与恢复'),h('div',{class:'chart-area'},[h(KeepAlive,null,{default:()=>show.value?h(Echart,{options,height:'200px'}):null})])])
}})
const app=createApp({setup(){const mode=ref('');return()=>h('main',[
...[['flow','300节点画布'],['chart','图表销毁'],['cached','图表缓存切换'],['json','JSON结果查看']].map(([key,label])=>h('button',{onClick:()=>{mode.value=key;result({mode:key})}},label)),
mode.value==='flow'?h(FlowPanel):mode.value==='chart'?h(ChartPanel):mode.value==='cached'?h(CachedChartPanel):mode.value==='json'?h(resolveComponent('JsonViewer'),{value:{status:'SUCCESS',id:'9223372036854775807',result:'按需加载结果成功'},copyable:true,boxed:true,sort:true,theme:'light'}):null
])}})
setupStore(app);await setupI18n(app);setupGlobCom(app);setupCmvr(app);app.mount('#app')
</script></html>