am-freescan/am-web/tests/arm-trajectory-picker-ui.html

45 lines
4.1 KiB
HTML
Raw Normal View History

<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><title>轨迹选择组件检查</title>
<style>body{font:14px Arial;margin:24px;background:#f5f7fa;color:#303133}main{max-width:560px;margin:auto;background:white;padding:24px}#result{white-space:pre-wrap;overflow:auto;max-height:180px}.test-tools{display:flex;gap:8px;margin:14px 0}#release{position:fixed;bottom:10px;right:10px;z-index:10000}</style>
<main><h2>平滑回放所选轨迹</h2><p>隔离测试:模拟只读设备接口,不连接设备,不保存业务数据。</p>
<div class="test-tools"><label>列表场景 <select id="scenario"><option>正常列表</option><option>没有轨迹</option><option>读取失败</option><option>延迟旧列表</option></select></label><button id="release">返回旧列表</button></div>
<div id="app"></div><pre id="result" role="status"></pre></main>
<script type="module">
import {createApp,h} from 'vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import Params from '/src/cmvr/common/views/flow/components/params/ArmTeachingParams.vue'
import {createArmTeachingGroup} from '/src/cmvr/common/utils/armTeaching.mjs'
import request from '/src/cmvr/request.ts'
import {service} from '/src/config/axios/service.ts'
const log=[], report=()=>document.querySelector('#result').textContent=JSON.stringify(log,null,2)
let pending
const response=(config,data)=>({data:{code:200,data},status:200,statusText:'OK',headers:{},config})
request.defaults.adapter=async config=>{
const url=config.url, method=config.method||'get'
if(method==='post'&&url==='/api/arm/teaching/validate')return response(config,true)
if(method!=='get')throw Error('禁止真实控制请求')
if(url==='/resource/robots')return {...response(config,null),data:{code:200,rows:[{robotId:'QA-ARM-1',robotName:'测试机械臂一'},{robotId:'QA-ARM-2',robotName:'测试机械臂二'}]}}
if(/^\/resource\/robots\/QA-ARM-[12]\/devices$/.test(url))return response(config,[{deviceId:'qa-arm',deviceName:'测试六轴机械臂'}])
if(url==='/api/arm/teaching/listRecordedTrajectories'&&['QA-ARM-1','QA-ARM-2'].includes(config.params.robotId)){
log.push({query:config.params.robotId,deviceId:config.params.deviceId});report()
const scene=document.querySelector('#scenario').value
const data={success:true,recording:false,recordingError:'',trajectories:[{fileName:config.params.robotId==='QA-ARM-1'?'工件扫描.csv':'二号机械臂.csv',samples:'9007199254740993',durationS:60,samplingFrequencyHz:100},{fileName:'回程.csv',samples:'6000',durationS:30,samplingFrequencyHz:100}]}
if(scene==='读取失败')throw Error('模拟:机械臂暂时离线')
if(scene==='没有轨迹')data.trajectories=[]
if(scene==='延迟旧列表')return await new Promise(resolve=>pending=()=>resolve(response(config,data)))
return response(config,data)
}
throw Error('未声明的请求已拒绝:'+url)
}
service.defaults.adapter=async()=>{throw Error('禁止业务请求')}
document.querySelector('#release').onclick=()=>{pending?.();pending=null}
const action=new URLSearchParams(location.search).get('action')||'ARM_REPLAY_RECORDED_TRAJECTORY'
const node={id:'qa-trajectory-node',type:'serviceNode',properties:{...structuredClone(createArmTeachingGroup().nodeList.find(n=>n.action===action)),executionTarget:{roleKey:'arm',deviceSlotKey:'arm'}}}
node.properties.nodeParams.find(p=>p.name==='fileName').input='手动轨迹.csv'
const start={id:'qa-start',type:'start',properties:{resourceRoles:[{roleKey:'arm',displayName:'机械臂工位',deviceSlots:[{slotKey:'arm',deviceKind:2,displayName:'机械臂'}]}]}}
const upstream={id:'qa-record',type:'serviceNode',properties:structuredClone(createArmTeachingGroup().nodeList.find(n=>n.action==='ARM_START_TRAJECTORY_RECORDING'))}
window.lf={getGraphData:()=>({nodes:[start,upstream,node],edges:[{sourceNodeId:start.id,targetNodeId:upstream.id},{sourceNodeId:upstream.id,targetNodeId:node.id}]}),setProperties:(id,value)=>{log.push({saved:id,parameters:value.nodeParams,target:value.executionTarget});report()}}
createApp({render:()=>h(Params,{data:node})}).use(ElementPlus,{locale:zhCn}).mount('#app')
</script></html>