diff --git a/am-web/src/cmvr/common/utils/armMotionUnits.mjs b/am-web/src/cmvr/common/utils/armMotionUnits.mjs index 1acc726..2e6bf9a 100644 --- a/am-web/src/cmvr/common/utils/armMotionUnits.mjs +++ b/am-web/src/cmvr/common/utils/armMotionUnits.mjs @@ -15,6 +15,19 @@ export function armMotionParamLabel(action, name) { if (name === 'jointVelocityLimits') return '各关节速度上限(rad/s,数组)' return '' } +// Velocity and acceleration have different dimensions and must be checked independently. +export function armMotionScalarError(action, param) { + if (param?.type === 'quote' || !['velocity', 'acceleration'].includes(param?.name)) return '' + const label = armMotionParamLabel(action, param.name) + if (!label) return '' + const raw = param.input + const value = Number(raw) + if (raw === '' || raw == null || typeof raw === 'boolean' || !Number.isFinite(value) || value <= 0) + return `${label}必须为大于0的有效数值` + if (Number.isFinite(param.min) && value < param.min) return `${label}不能小于${param.min}` + if (Number.isFinite(param.max) && value > param.max) return `${label}不能大于${param.max}` + return '' +} export const withArmMotionUnits = (action, params = []) => { const source = ['ARM_MOVE_TO_J', 'ARM_MOVE_TO_POINT'].includes(action) && !params.some(p => p.name === 'timeoutMs') ? [...params, {name:'timeoutMs',label:'等待超时(毫秒)',type:'input',componentType:'number',input:ARM_DEFAULT_WAIT_MS,min:100,max:21600000,step:1000,required:true,disabled:true}] : params diff --git a/am-web/src/cmvr/common/utils/armMotionUnits.test.mjs b/am-web/src/cmvr/common/utils/armMotionUnits.test.mjs index a9f2e8e..20923cc 100644 --- a/am-web/src/cmvr/common/utils/armMotionUnits.test.mjs +++ b/am-web/src/cmvr/common/utils/armMotionUnits.test.mjs @@ -1,6 +1,6 @@ import test from 'node:test' import assert from 'node:assert/strict' -import { armMotionParamLabel, withArmMotionUnits, armMotionUnitHint } from './armMotionUnits.mjs' +import { armMotionParamLabel, withArmMotionUnits, armMotionUnitHint, armMotionScalarError } from './armMotionUnits.mjs' test('给历史机械臂参数补充单位时,位置数值、关节数组、上游引用保持原样', () => { const params = [{name:'x',type:'input',input:0.123}, {name:'rx',type:'quote',quote:['start','input','rx'],quoteType:'input'}, {name:'frame',input:'BASE'}] @@ -33,3 +33,12 @@ test('机械臂SDK单位标注不影响底盘与旋转底座的单位选择', () assert.equal(withArmMotionUnits(action,[param])[0],param) } }) + +test('速度与加速度按各自数值范围校验,不比较不同单位的大小', () => { + assert.equal(armMotionScalarError('ARM_MOVE_TO_J', {name:'velocity',type:'input',input:0.5,max:5}), '') + assert.equal(armMotionScalarError('ARM_MOVE_TO_J', {name:'acceleration',type:'input',input:0.2,max:5}), '') + for (const input of ['', null, 0, -1, Infinity, NaN, true, 'abc']) + assert.match(armMotionScalarError('ARM_MOVE_TO_J', {name:'velocity',type:'input',input}), /速度.*大于0/) + assert.match(armMotionScalarError('ARM_MOVE_TO_J', {name:'acceleration',type:'input',input:6,max:5}), /不能大于5/) + assert.equal(armMotionScalarError('ARM_MOVE_TO_J', {name:'velocity',type:'quote',input:'',quote:['speed','output','vec']}), '') +}) diff --git a/am-web/src/cmvr/common/utils/flowValidationIssues.mjs b/am-web/src/cmvr/common/utils/flowValidationIssues.mjs new file mode 100644 index 0000000..4189b74 --- /dev/null +++ b/am-web/src/cmvr/common/utils/flowValidationIssues.mjs @@ -0,0 +1,38 @@ +export function validationMessages(...values) { + const messages = new Set() + const seen = new Set() + const visit = (value) => { + if (!value || seen.has(value) || messages.size >= 50) return + if (typeof value === 'string') { + if (value.trim()) messages.add(value.trim()) + return + } + if (typeof value !== 'object') return + seen.add(value) + if (Array.isArray(value)) value.forEach(visit) + else if (typeof value.message === 'string') visit(value.message) + else Object.values(value).forEach(visit) + } + values.forEach(visit) + return [...messages] +} + +export function nodeValidationIssues(nodes, errors) { + const byId = new Map(nodes.map(node => [node.id, node])) + const issues = new Map() + for (const error of errors) { + const id = error.nodeId || error.id || (error.global ? '__flow__' : '') + const node = byId.get(id) + if (!node && !error.global) continue + const previous = issues.get(id) + issues.set(id, { + id, + name: node?.properties?.name || node?.text?.value || (node?.type === 'start' ? '流程开始' : error.global ? '流程整体' : id), + messages: validationMessages(previous?.messages, error.messages, error.message) + }) + } + return [...issues.values()].map(issue => ({ + ...issue, + messages: issue.messages.length ? issue.messages : ['参数未通过校验,请打开节点配置检查必填项及引用'] + })) +} diff --git a/am-web/src/cmvr/common/views/flow/components/ParamsDrawer.vue b/am-web/src/cmvr/common/views/flow/components/ParamsDrawer.vue index e4085ca..2eae11c 100644 --- a/am-web/src/cmvr/common/views/flow/components/ParamsDrawer.vue +++ b/am-web/src/cmvr/common/views/flow/components/ParamsDrawer.vue @@ -28,7 +28,7 @@ componentIdentity.category }} - + /> +