Browse Source

feat(photography): 添加相机配置和预览功能

- 新增获取应用配置功能,用于获取相机控制类型等信息
- 实现预览图片路径的动态配置,支持 SmartShooter 模式- 添加 onRunMcuSingle事件处理,用于响应单次运行 MCU 指令
-优化预览图片的加载和更新机制
- 调整部分代码结构,提高可维护性
panqiuyao 5 months ago
parent
commit
eee8758128

+ 6 - 2
electron/controller/utils.js

@@ -159,8 +159,12 @@ class UtilsController extends Controller {
 
   }
 
-  getUserDir(){
-    return app.getPath('userData');
+  getAppConfig(){
+    const config  =  readConfigFile()
+    return  {
+      ...config,
+      userDataPath: app.getPath('userData')
+    }
   }
   async readFileImageForPath(filePath,maxWidth=1500){
 

+ 2 - 3
electron/utils/socket.js

@@ -38,13 +38,12 @@ function livePreview(data){
 
     fs.writeFile(tempFilePath, data.data.smart_shooter_preview, 'base64', (err) => {
       if (err) {
-        console.error('写入临时文件失败:', err);
+        Log.error('写入临时文件失败:', err);
       } else {
         fs.rename(tempFilePath, previewPath, (renameErr) => {
           if (renameErr) {
-            console.error('重命名文件失败:', renameErr);
+            Log.error('重命名文件失败:', renameErr);
           } else {
-            console.log(`文件已成功写入到 preview.png`);
           }
         });
       }

+ 17 - 5
frontend/src/stores/modules/config.ts

@@ -12,15 +12,26 @@ export const configInfo = defineStore('config',()=>{
     digiCamControlPath.value = data
   }
 
-  const userDataPath = ref("")
+  const appConfig = ref({})
 
 
-  clientStore.ipc.send(icpList.utils.getUserDir);
-  clientStore.ipc.on(icpList.utils.getUserDir, async (event, result) => {
-    userDataPath.value = result;
+  const getAppConfig = async ()=>{
+    return new Promise((resolve, reject) => {
+      clientStore.ipc.send(icpList.utils.getAppConfig);
+      clientStore.ipc.on(icpList.utils.getAppConfig, async (event, result) => {
+        appConfig.value = result;
+        resolve(appConfig.value)
+      })
+    })
+  }
+
 
+  clientStore.ipc.send(icpList.utils.getAppConfig);
+  clientStore.ipc.on(icpList.utils.getAppConfig, async (event, result) => {
+    appConfig.value = result;
   })
 
+
   //  1 为拍照并处理图像 2 为仅处理图像
   const appModel = ref(1)
   const updateAppModel = (data:number)=>{
@@ -31,7 +42,8 @@ export const configInfo = defineStore('config',()=>{
     updateDigiCamControlPath,
     appModel,
     updateAppModel,
-    userDataPath,
+    appConfig,
+    getAppConfig,
   }
 },{
   persist:true,

+ 1 - 1
frontend/src/utils/ipc.ts

@@ -19,7 +19,7 @@ const icpList = {
         shellFun: 'controller.utils.shellFun',
         openDirectory:"controller.utils.openDirectory",
         openImage:"controller.utils.openImage",
-        getUserDir:"controller.utils.getUserDir",
+        getAppConfig:"controller.utils.getAppConfig",
         openFile:"controller.utils.openFile"
     },
     setting:{

+ 23 - 5
frontend/src/views/Photography/check.vue

@@ -64,6 +64,7 @@
       @confirm="confirm"
       ref="editData"
       @onClose="onClose"
+      @onRunMcuSingle="onRunMcuSingle"
       :addRowData="addRowData"
     />
 
@@ -86,6 +87,10 @@ const socketStore = socket(); // WebSocket状态管理实例
 
 const emit = defineEmits([ 'confirm','onClose']);
 
+
+import  configInfo  from '@/stores/modules/config';
+const configInfoStore = configInfo();
+
 const confirm = ()=>{
   hideVideo()
   emit('confirm')
@@ -120,16 +125,17 @@ import { digiCamControlWEB } from  '@/utils/appconfig'
 import { getFilePath } from '@/utils/appfun'
 import {ElMessage} from "element-plus";
 const previewKey = ref(0)
-//const preview = ref(digiCamControlWEB+'liveview.jpg')
 
-const preview = ref('C:\\Users\\Administrator\\AppData\\Roaming\\ZhiHuiYin\\preview\\liveview.png')
+const preview = ref(digiCamControlWEB+'liveview.jpg')
+
+
 
 const previewSrc = computed(()=>{
   let time = new Date().getTime()
   return preview.value+'?key='+previewKey.value+'&time='+time
 })
 const step = ref(1)
-function checkConfirm(init){
+async function checkConfirm(init){
   step.value =1
   if(menu.length === 0){
     menu.push({
@@ -139,12 +145,24 @@ function checkConfirm(init){
       type:'toggleModel'
     })
   }
+  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"
+      }
+  }
   if(!init) previewKey.value++;
 
   showVideo()
   showrEditRow.value = true
 }
 
+function onRunMcuSingle (){
+  loading.value = true
+}
 const showrEditRow = ref(false)
 
 
@@ -162,7 +180,7 @@ function showVideo(){
         interval = setInterval(()=>{
           previewKey.value++;
         },1000)
-      },2000)
+      },500)
 
     })
 
@@ -178,7 +196,7 @@ function hideVideo(){
 
 }
 
-const loading = ref(false)
+const loading = ref(true)
 const editData = ref(null);
 const imageTplPath = ref(null)
 function takePictures() {

+ 3 - 2
frontend/src/views/Photography/components/editRow.vue

@@ -204,15 +204,16 @@ function testShoesFlip(){
 
 
     clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, result) => {
-      console.log('_run_mcu_single_row')
 
       captureLoading.value = false;
 
+      emit('onRunMcuSingle')
+
     })
   }
 }
 
-const emit = defineEmits([ 'confirm','onClose']);
+const emit = defineEmits([ 'confirm','onClose','onRunMcuSingle']);
 const close = ()=>{
   console.log('onClose')
   emit('onClose')