am-freescan/scripts/prepare_scanner_dictionary_ui.py
lixiaolong ba0f749d40 feat: 完善检测任务、夹具轨迹与设备工作流
完善扫描成果与比对资料管理,精简业务菜单和任务工作台,更新批量导入模板。

适配机械臂新协议、坐标系管理及目标位姿组件,增加扫描参数字典和角色自动分配。

修复试运行终止状态与过期扫描任务资源释放,补充回归测试、迁移脚本及接口文档。
2026-11-06 10:50:49 +08:00

26 lines
3.6 KiB
Python

"""Actual scanner parameter panel with injected memory readers; never connects to a scanner."""
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
PAGE=r'''<!doctype html><html lang="zh"><meta charset="utf-8"><title>扫描字典离线验证</title><body><div id="app"></div><script type="module">
import {createApp,h,ref,reactive} from '/node_modules/.vite/deps/vue.js';
import ElementPlus from '/node_modules/.vite/deps/element-plus.js';
import '/node_modules/element-plus/dist/index.css';
import zhCn from '/node_modules/element-plus/es/locale/lang/zh-cn.mjs';
import Panel from '/src/cmvr/common/views/flow/components/params/ScannerParams.vue';
import {createWorkcellNodeGroups,validateWorkcellLiterals} from '/src/cmvr/common/utils/scanMotorNodes.mjs';
const nodes=createWorkcellNodeGroups()[0].nodeList,saved=ref('尚未保存'),calls=ref([]),current=ref('SCANNER_CALIBRATION_MODE');
const roles=[{roleKey:'station',displayName:'现场扫描工位',required:true,deviceSlots:[{slotKey:'scanner',displayName:'扫描仪',deviceKind:14}]}];
const make=action=>{const n=nodes.find(n=>n.action===action);return {id:action,type:'serviceNode',properties:{...structuredClone(n),executionTarget:{roleKey:'station',deviceSlotKey:'scanner'}}}};
const data=reactive(make(current.value));
window.lf={getGraphData:()=>({nodes:[{id:'start',type:'start',properties:{name:'开始',resourceRoles:roles}},data],edges:[{sourceNodeId:'start',targetNodeId:data.id}]}),setProperties:(id,p)=>{const errors=validateWorkcellLiterals(p.action,p.nodeParams);if(errors.length)throw Error(errors[0]);Object.assign(data.properties,p);saved.value=JSON.stringify({action:p.action,requestJson:p.nodeParams.find(f=>f.name==='requestJson')?.input,requestFields:p.nodeParams.find(f=>f.name==='requestFields')?.children},null,2)}};
const app=createApp({setup(){return()=>h('main',{style:'max-width:760px;margin:24px auto;padding:20px;font:14px sans-serif'},[h('h2','扫描组件字典 · 离线验证(不连接设备)'),h('p','验证中文选项、原数字参数回显和保存;所有读取与校验均使用内存数据。'),h('div',{style:'display:flex;gap:8px;flex-wrap:wrap'},nodes.filter(n=>['SCANNER_CALIBRATION_MODE','SCANNER_CALIBRATION_APPLY_LAST','SCANNER_CREATE_PROJECT','SCANNER_MESH'].includes(n.action)).map(n=>h('button',{onClick:()=>{current.value=n.action;Object.assign(data,make(n.action));saved.value='尚未保存'}},n.name))),h(Panel,{key:current.value,data,onSaveSuccess:()=>calls.value.push('保存内存配置')}),h('h3','保存的请求'),h('pre',{'data-testid':'saved'},saved.value),h('details',[h('summary','内存调用记录'),h('pre',calls.value.join('\n'))])])}});
app.provide('scannerConfigurationReader',async()=>({data:{configured:true}}));
app.provide('scannerSupplierQuery',async op=>{if(op!=='CAPABILITIES')throw Error('禁止真实设备请求');calls.value.push('读取内存字典');return {data:{exportFormats:['PLY','STL'],calibrationModes:[{mode:0,modeName:'跟踪仪标定'},{mode:1,modeName:'系统标定'},{mode:2,modeName:'探针标定'},{mode:3,modeName:'UE Nova 激光标定'}]}}});
app.provide('scannerRequestValidator',async(op,body)=>{const p=JSON.parse(body);if(['CALIBRATION_MODE','CALIBRATION_APPLY_LAST'].includes(op)&&(!Number.isInteger(p.mode)||p.mode<0||p.mode>3))throw Error('标定类别必须保留0至3整数');calls.value.push('仅校验请求:'+body);return {data:true}});
app.use(ElementPlus,{locale:zhCn});app.mount('#app');
</script></body></html>'''
if __name__=='__main__':
path=ROOT/'am-web/scanner-dictionary-verification.html'
path.write_text(PAGE,encoding='utf-8')
print(path)