CMVR-IOT-UI/src/utils/robotDevice.js
2026-08-13 10:23:55 +08:00

55 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 平台设备类型枚举,供流程资源匹配、机器人设备筛选和界面展示共同使用。
* Object.freeze 防止运行期间被改写,数值与后端 deviceKind 协议保持一致。
*/
export const DEVICE_KIND = Object.freeze({
AGV: 1,
ARM: 2,
BIO_HEAD: 4,
CAMERA: 5,
MICROPHONE: 9,
ROBOT: 12,
SPEAKER: 13,
})
/**
* 流程动作到所需设备类型的全局映射。
* 作用范围为所有根据 action 判断执行设备的流程模块;未列出的动作视为没有固定设备类型。
*/
export const DEVICE_KIND_BY_ACTION = Object.freeze({
AGV_MOVE_TO_POINT: DEVICE_KIND.AGV,
AGV_MOVE_TO_STATION: DEVICE_KIND.AGV,
ARM_MOVE_TO_POINT: DEVICE_KIND.ARM,
ARM_MOVE_TO_J: DEVICE_KIND.ARM,
TOUCH: DEVICE_KIND.ARM,
BIO_HEAD_SPEAK_START: DEVICE_KIND.BIO_HEAD,
BIO_HEAD_SPEAK_STOP: DEVICE_KIND.BIO_HEAD,
BIO_HEAD_SPECIAL_EXPRESSION: DEVICE_KIND.BIO_HEAD,
CAMERA_START: DEVICE_KIND.CAMERA,
CAMERA_STOP: DEVICE_KIND.CAMERA,
CAMERA_GETRGBIMAGE: DEVICE_KIND.CAMERA,
CAMERA_RECORDING_START: DEVICE_KIND.CAMERA,
CAMERA_RECORDING_STOP: DEVICE_KIND.CAMERA,
MICROPHONE_START: DEVICE_KIND.MICROPHONE,
MICROPHONE_STOP: DEVICE_KIND.MICROPHONE,
SPEAKER_PLAYAUDIO: DEVICE_KIND.SPEAKER,
VI_PLAY_CORPUS: DEVICE_KIND.SPEAKER,
})
/**
* 查询某个流程动作所需的设备类型。
* 直接读取统一映射;未知或无需固定设备的动作返回 undefined,由调用方决定降级策略。
*/
export const getDeviceKindForAction = (action) => DEVICE_KIND_BY_ACTION[action]
/**
* 将机器人设备接口数据转换为 Element Plus 下拉框选项,供全局设备选择器复用。
* 每项以 deviceId 作为值;设备名有效且不同于 ID 时展示“名称 (ID)”,否则仅展示 ID。
*/
export const toDeviceOptions = (devices = []) => devices.map((device) => ({
value: device.deviceId,
label: device.deviceName && device.deviceName !== device.deviceId
? `${device.deviceName} (${device.deviceId})`
: device.deviceId,
}))