瀏覽代碼

refactor(frontend): 优化拍照功能并移除冗余日志输出

- 移除了 camera.js 和 check.vue 中的多余 console.log 语句
- 重构了 check.vue 中的拍照逻辑,提取创建主图功能为单独函数- 增加了 SmartShooter 拍照成功的事件处理
- 优化了 digiCamControl 运行时直接拍照的逻辑
- 在 socket.js 中添加了过滤,仅打印非 smart_shooter_enable_preview 消息
panqiuyao 5 月之前
父節點
當前提交
58efacce4c
共有 3 個文件被更改,包括 40 次插入33 次删除
  1. 0 2
      electron/api/camera.js
  2. 1 5
      electron/utils/socket.js
  3. 39 26
      frontend/src/views/Photography/check.vue

+ 0 - 2
electron/api/camera.js

@@ -146,8 +146,6 @@ module.exports = {
       }))
      return  new Promise(async (resolve, reject) => {
         pySocket.onSocketMessage('smart_shooter_getinfo',(message)=>{
-          console.log('m===================essage')
-          console.log(message)
           resolve(message)
         })
       })

+ 1 - 5
electron/utils/socket.js

@@ -82,6 +82,7 @@ const pySocket = function () {
 
           let this_data = JSON.parse(data.toString());
 
+          if(this_data.msg_type !== 'smart_shooter_enable_preview'){ console.log(this_data);}
           if(this_data.msg_type){
 
             let notAllMessage = false
@@ -166,11 +167,6 @@ const pySocket = function () {
       async function onSocketMessage(data){
           try {
             let this_data = JSON.parse(data.toString());
-
-            console.log('socket.on.message2222222222222222222222222');
-            console.log(this_data.msg_type);
-            console.log(message_type);
-            console.log(this_data);
             if(this_data.msg_type === message_type){
               app.socket.off('message', onSocketMessage);
               callback(this_data)

+ 39 - 26
frontend/src/views/Photography/check.vue

@@ -147,9 +147,6 @@ async function checkConfirm(init){
   }
   if(init){
     await  configInfoStore.getAppConfig()
-    console.log('configInfoStore.appConfig');
-    console.log(configInfoStore.appConfig);
-    console.log(configInfoStore.appConfig.controlType);
     if(configInfoStore.appConfig.controlType === "SmartShooter"){
         preview.value = configInfoStore.appConfig.userDataPath  + "\\preview\\liveview.png"
       }
@@ -180,7 +177,7 @@ function showVideo(){
         interval = setInterval(()=>{
           previewKey.value++;
         },200)
-      },2000)
+      },500)
 
     })
 
@@ -232,33 +229,49 @@ function takePictures() {
   }
 }
 
+// 获取主图
+function  createMainImage (file_path){
+
+  clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
+  clientStore.ipc.send(icpList.takePhoto.createMainImage,{
+    file_path:file_path
+  });
+  clientStore.ipc.on(icpList.takePhoto.createMainImage, async (event, result) => {
+    if(result.code === 0 && result.data?.main_out_path){
+      imageTplPath.value  = result.data?.main_out_path
+      hideVideo()
+      step.value = 2
+      loading.value = false;
+    }else if(result.msg){
+      loading.value = false;
+      showVideo()
+      if(result.code !== 0) ElMessage.error(result.msg)
+    }
+    clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
+
+
+  });
+}
+
+
+//拍照成功  SmartShooter
+clientStore.ipc.on(icpList.socket.message+'_smart_shooter_photo_take', async (event, result) => {
+
+  if(result.code === 1 && result.data?.photo_file_name){
+    createMainImage(result.data?.photo_file_name)
+  }
+
+})
+
+
+//运行的时候  直接拍照  digiCamControl
 clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, result) => {
-  console.log('_run_mcu_single_check')
+  console.log('_run_mcu_single_check_on')
   console.log(result)
 
   if(result.code === 0 && result.data?.file_path){
-    clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
-    clientStore.ipc.send(icpList.takePhoto.createMainImage,{
-      file_path:result.data.file_path
-    });
-    clientStore.ipc.on(icpList.takePhoto.createMainImage, async (event, result) => {
-      console.log('icpList.utils.createMainImage');
-      console.log(result);
-      if(result.code === 0 && result.data?.main_out_path){
-        imageTplPath.value  = result.data?.main_out_path
-        hideVideo()
-        step.value = 2
-        loading.value = false;
-      }else if(result.msg){
-        loading.value = false;
-        showVideo()
-        if(result.code !== 0) ElMessage.error(result.msg)
-      }
-      clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
-
-
-    });
 
+    createMainImage(result.data?.file_path)
 
   }else if(result.msg){
     if( result.msg.indexOf('处理失败,请重试') >= 0){