|
@@ -5,16 +5,151 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup name="Fruit" lang="ts">
|
|
|
+import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech';
|
|
|
+import { useWebSocket } from '@/utils/bodyposeWs';
|
|
|
+const { proxy } = getCurrentInstance() as any;
|
|
|
+const router = useRouter();
|
|
|
+const { bodyposeWs, startDevice, checkBodypose, openBodypose, terminateBodypose, suspendBodypose, resumeBodypose, getBodyposeState, closeWS } = useWebSocket();
|
|
|
+
|
|
|
const data = reactive<any>({
|
|
|
+ bodyposeData: {},//姿态信息
|
|
|
+ bodyposeState: false,//姿态识别窗口状态
|
|
|
+ parameter: {},//参数
|
|
|
+ deviceInfo: {},//设备信息
|
|
|
+ againNum: 0,//再次启动次数
|
|
|
+ againTimer: null,//定时状态
|
|
|
+ wsState: false,//WS状态
|
|
|
});
|
|
|
-const {
|
|
|
-} = toRefs(data);
|
|
|
|
|
|
+const { bodyposeData, bodyposeState, parameter, deviceInfo, againNum, againTimer, wsState } = toRefs(data);
|
|
|
+
|
|
|
+/**
|
|
|
+ * 初始化
|
|
|
+ */
|
|
|
+const getInit = async () => {
|
|
|
+ console.log("触发姿态识别")
|
|
|
+ let deviceid = localStorage.getItem('deviceid') || '';
|
|
|
+ if (!deviceid) {
|
|
|
+ proxy?.$modal.msgError(`请重新登录绑定设备号后使用`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bodyposeState.value = true;
|
|
|
+ if (wsState.value) {
|
|
|
+ proxy?.$modal.msgWarning(`操作过快,请稍后重试`);
|
|
|
+ setTimeout(() => {
|
|
|
+ bodyposeState.value = false;
|
|
|
+ }, 1000)
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ speckText("请举右手看摄像头进行姿态识别");
|
|
|
+ bodyposeWs((e: any) => {
|
|
|
+ console.log("bodyposeWS", e)
|
|
|
+ if (e?.wksid) {
|
|
|
+ wsState.value = true;
|
|
|
+ //获取设备信息
|
|
|
+ startDevice({ deviceid: deviceid });
|
|
|
+ console.log("获取设备信息")
|
|
|
+ }
|
|
|
+ if (e?.type == 'fe_device_init_result') {
|
|
|
+ //接收设备信息并发送请求
|
|
|
+ if (e?.device_info) {
|
|
|
+ deviceInfo.value = e.device_info;
|
|
|
+ getCheckBodypose();
|
|
|
+ console.log("返回设备信息,检查是否支持姿态识别")
|
|
|
+ } else {
|
|
|
+ proxy?.$modal.msgError(`设备信息缺失,请重新登录绑定设备号后使用`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e?.cmd == 'check_bodyposecontroller_available') {
|
|
|
+ let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
+ if (e?.code == 0) {
|
|
|
+ //查看姿态识别状态,如果不处于关闭就先关闭再重新启动(可能会APP退出然后工作站还在运行的可能性)
|
|
|
+ getBodyposeState(handcontroller_id);
|
|
|
+ againNum.value = 0;
|
|
|
+ againTimer.value = null;
|
|
|
+ clearTimeout(againTimer.value);
|
|
|
+ console.log("查看姿态识别状态")
|
|
|
+ } else {
|
|
|
+ //尝试多次查询姿态识别状态
|
|
|
+ if (againNum.value <= 2) {
|
|
|
+ againTimer.value = setTimeout(() => {
|
|
|
+ getCheckBodypose();
|
|
|
+ }, 500)
|
|
|
+ againNum.value++;
|
|
|
+ } else {
|
|
|
+ let msg = "";
|
|
|
+ if (e.code == 102402) {
|
|
|
+ msg = `多次连接失败请重试,姿态识别模块被占用`;
|
|
|
+ } else {
|
|
|
+ msg = `多次连接失败请重试,姿态识别模块不可用,code:${e.code}`;
|
|
|
+ }
|
|
|
+ proxy?.$modal.msgWarning(msg);
|
|
|
+ againNum.value = 0;
|
|
|
+ againTimer.value = null;
|
|
|
+ clearTimeout(againTimer.value);
|
|
|
+ getCloseBodypose();//直接关闭
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e?.cmd == 'get_bodyposecontroller_state') {
|
|
|
+ let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
+ //state说明: 0:关闭,3:空闲,36:工作中
|
|
|
+ if ([3, 36].includes(e.state)) {
|
|
|
+ getCloseBodypose();
|
|
|
+ proxy?.$modal.msgWarning(`请重新姿态识别`);
|
|
|
+ } else {
|
|
|
+ openBodypose(handcontroller_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e?.type == 'bodyposecontroller_result') {
|
|
|
+ console.log("data", e.data)
|
|
|
+ bodyposeData.value = e.data;
|
|
|
+ }
|
|
|
+ if (e?.cmd == 'terminate_bodyposecontroller') {
|
|
|
+ if (e?.code == 0) {
|
|
|
+ closeWS();
|
|
|
+ bodyposeState.value = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e?.type == 'disconnect') {
|
|
|
+ wsState.value = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
-onBeforeMount(() => {
|
|
|
|
|
|
+/**
|
|
|
+ * 查询姿态识别状态
|
|
|
+*/
|
|
|
+const getCheckBodypose = () => {
|
|
|
+ let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
+ //检查是否支持姿态识别
|
|
|
+ checkBodypose(handcontroller_id);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 关闭姿态识别
|
|
|
+*/
|
|
|
+const getCloseBodypose = () => {
|
|
|
+ let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
+ terminateBodypose(handcontroller_id);
|
|
|
+ bodyposeState.value = false;
|
|
|
+ speckCancel(); //停止播报
|
|
|
+ setTimeout(() => {
|
|
|
+ if (wsState.value) {
|
|
|
+ closeWS();
|
|
|
+ }
|
|
|
+ }, 3000)
|
|
|
+};
|
|
|
+
|
|
|
+onBeforeMount(() => {
|
|
|
+ getInit();
|
|
|
});
|
|
|
|
|
|
+onMounted(() => {
|
|
|
+})
|
|
|
+
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
|
});
|