Selaa lähdekoodia

refactor(photography): 重构相机参数配置与拍照流程

- 新增相机参数开关控制,关闭时隐藏配置项且不发送参数
- 移除测试照片等待超时机制及相关状态变量
- 将 buildSingleShotData 内联至 takePictures,简化拍照逻辑
- 移除 isSetting 条件分支,统一拍照数据构建方式
- 相机参数范围加载时自动填充当前值或首选项作为默认值
- 保存时校验已开启相机参数但未读取数据的情况
- 移除 _run_mcu 事件监听及对应的清理逻辑
panqiuyao 1 viikko sitten
vanhempi
commit
c7c207624f

+ 21 - 81
frontend/src/views/Photography/check.vue

@@ -372,43 +372,7 @@ function handleAutoFocus() {
 const loading = ref(true)
 const editData = ref(null);
 const imageTplPath = ref(null)
-const expectTestPhoto = ref(false)
-let testPhotoToken = 0
-let shootAfterMove = false
-function buildSingleShotData() {
-  const row = editData.value?.editRowData || {}
-  const data: Record<string, any> = {
-    camera_height: Number(row.camera_height),
-    camera_angle: Number(row.camera_angle),
-    led_switch: row.led_switch,
-    id: 0,
-    mode_type: row.mode_type,
-    turntable_position: Number(row.turntable_position),
-    action_name: row.action_name || '测试',
-    turntable_angle: Number(row.turntable_angle),
-    shoe_upturn: Number(row.shoe_upturn),
-    camera_focal_distance: Number(row.camera_focal_distance || 0),
-    action_index: 1,
-    number_focus: isSetting.value ? Number(row.number_focus || 0) : 0,
-    take_picture: true,
-    pre_delay: 0,
-    after_delay: 0,
-    point_name: row.point_name || currentPointName.value || 'A',
-    is_move_device: row.is_move_device,
-  }
-  if (isSetting.value) {
-    const cameraConfigs = editData.value?.getCameraConfigs?.()
-    if (cameraConfigs) {
-      data.camera_configs = cameraConfigs
-    }
-  }
-  return data
-}
-
 function backToPreview() {
-  testPhotoToken += 1
-  expectTestPhoto.value = false
-  shootAfterMove = false
   step.value = 1
   imageTplPath.value = null
   loading.value = false
@@ -422,25 +386,28 @@ function takePictures() {
 
   if (clientStore.isClient) {
     loading.value = true;
-    if (isSetting.value) {
-      const token = ++testPhotoToken
-      expectTestPhoto.value = true
-      shootAfterMove = true
-      setTimeout(() => {
-        if (token !== testPhotoToken || !expectTestPhoto.value || step.value !== 1) return
-        expectTestPhoto.value = false
-        shootAfterMove = false
-        loading.value = false
-        showVideo(currentPointName.value)
-        ElMessage.warning('未收到测试照片,已返回预览')
-      }, 30000)
-    }
-    const shotData = buildSingleShotData()
-    if (isSetting.value) {
-      shotData.take_picture = false
-      shotData.number_focus = 0
-      delete shotData.camera_configs
+    const row = editData.value?.editRowData || {}
+    const shotData: Record<string, any> = {
+      camera_height: Number(row.camera_height),
+      camera_angle: Number(row.camera_angle),
+      led_switch: row.led_switch,
+      id: 0,
+      mode_type: row.mode_type,
+      turntable_position: Number(row.turntable_position),
+      action_name: row.action_name || '测试',
+      turntable_angle: Number(row.turntable_angle),
+      shoe_upturn: Number(row.shoe_upturn),
+      camera_focal_distance: Number(row.camera_focal_distance),
+      action_index: 1,
+      number_focus: 0,
+      take_picture: true,
+      pre_delay: 0,
+      after_delay: 0,
+      point_name: row.point_name || currentPointName.value || 'A',
+      is_move_device: row.is_move_device,
     }
+    const cameraConfigs = editData.value?.getCameraConfigs?.()
+    if (cameraConfigs) shotData.camera_configs = cameraConfigs
     console.log('takePictures');
     console.log(shotData)
     hideVideo(currentPointName.value).then(() => {
@@ -479,22 +446,10 @@ function  createMainImage (file_path){
 }
 
 
-clientStore.ipc.on(icpList.socket.message+'_run_mcu', async (event, result) => {
-  if (!expectTestPhoto.value) return
-  if (result?.code === 0) return
-  testPhotoToken += 1
-  expectTestPhoto.value = false
-  loading.value = false
-  showVideo(currentPointName.value)
-  if (result?.msg) ElMessage.error(result.msg)
-})
-
 //拍照成功  SmartShooter
 clientStore.ipc.on(icpList.socket.message+'_smart_shooter_photo_take', async (event, result) => {
   console.log('_smart_shooter_photo_take');
   console.log(result);
-  testPhotoToken += 1
-  expectTestPhoto.value = false
   if(result.code === 0 && result.data?.photo_file_name){
     imageTplPath.value  = result.data?.photo_file_name
     step.value = 2
@@ -531,20 +486,6 @@ clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, resul
   }else {
     loading.value = false;
     console.log('_run_mcu_single');
-    if (shootAfterMove && result.code === 0) {
-      shootAfterMove = false
-      loading.value = true
-      socketStore.sendMessage({
-        type: 'smart_shooter_photo_take',
-        data: {
-          point_name: currentPointName.value || 'A',
-          goods_art_no: '',
-          id: 0,
-        }
-      })
-      return
-    }
-    expectTestPhoto.value = false
     showVideo(currentPointName.value)
     if(result.code !== 0 && result.msg) ElMessage.error(result.msg)
   }
@@ -586,7 +527,6 @@ onBeforeUnmount(() => {
   clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
   clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
   clientStore.ipc.removeAllListeners(icpList.socket.message+'_run_mcu_single');
-  clientStore.ipc.removeAllListeners(icpList.socket.message+'_run_mcu');
   clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_photo_take');
 })
 </script>

+ 37 - 10
frontend/src/views/Photography/components/editRow.vue

@@ -18,17 +18,23 @@
         <el-button size="small" plain style="margin-left: 8px;" @click="onRefreshPointList" v-log="{ describe: { action: '点击刷新点位列表' } }">刷新</el-button>
       </el-form-item>
 
-      <template v-if="!disablePointConfig">
+      <el-form-item label="相机参数" v-if="!disablePointConfig">
+        <el-switch
+          v-model="cameraParamEnabled"
+          active-text="设置"
+          inactive-text="不设置"
+          @change="onCameraParamSwitch"
+        />
+      </el-form-item>
+      <template v-if="!disablePointConfig && cameraParamEnabled">
         <el-form-item v-for="item in cameraPropDefs" :key="item.key" :label="item.label">
           <el-select
             v-model="cameraForm[item.key]"
             filterable
-            clearable
-            placeholder="不修改"
+            placeholder="请选择"
             style="width: 108px;"
             :loading="cameraPropLoading"
           >
-            <el-option label="不修改" value="" />
             <el-option v-for="opt in optionsFor(item.key)" :key="opt" :label="opt" :value="opt" />
           </el-select>
           <el-button
@@ -185,6 +191,7 @@ const cameraRanges = reactive({
   Exposure: [] as string[],
 })
 const cameraPropLoading = ref(false)
+const cameraParamEnabled = ref(false)
 let cameraPropRequest = 0
 
 function isWritable(item) {
@@ -219,10 +226,12 @@ function applyCameraConfigs(raw) {
   cameraPropDefs.forEach(({ key }) => {
     cameraForm[key] = saved[key] != null && saved[key] !== '' ? String(saved[key]) : ''
   })
+  cameraParamEnabled.value = cameraPropDefs.some(({ key }) => cameraForm[key] !== '')
   return Object.keys(saved).length > 0
 }
 
 function getCameraConfigs() {
+  if (!cameraParamEnabled.value) return undefined
   const payload = {}
   cameraPropDefs.forEach(({ key }) => {
     if (cameraForm[key] !== '' && cameraForm[key] != null) {
@@ -232,6 +241,14 @@ function getCameraConfigs() {
   return Object.keys(payload).length ? payload : undefined
 }
 
+function onCameraParamSwitch(enabled) {
+  if (!enabled) return
+  cameraPropDefs.forEach(({ key }) => {
+    cameraForm[key] = ''
+  })
+  fetchCameraProperties()
+}
+
 function applySavedCamera(row, fallbackId) {
   const nested = parseCameraConfigs(row?.camera_configs)
   if (Object.keys(nested).length) {
@@ -256,7 +273,7 @@ function applySavedCamera(row, fallbackId) {
 }
 
 function fetchCameraProperties() {
-  if (!clientStore.isClient || props.disablePointConfig) return
+  if (!clientStore.isClient || props.disablePointConfig || !cameraParamEnabled.value) return
   const requestId = ++cameraPropRequest
   const point = editRowData.value.point_name || 'A'
   cameraPropLoading.value = true
@@ -280,17 +297,22 @@ function fetchCameraProperties() {
     const dropped = []
     cameraPropDefs.forEach(({ key, label }) => {
       const item = result.data.find((prop) => prop?.CameraPropertyType === key)
-      const range = item && isWritable(item) && Array.isArray(item.CameraPropertyRange)
+      const currentValue = item?.CameraPropertyValue != null && String(item.CameraPropertyValue) !== ''
+        ? String(item.CameraPropertyValue)
+        : ''
+      let range = item && isWritable(item) && Array.isArray(item.CameraPropertyRange)
         ? item.CameraPropertyRange.map((opt) => String(opt))
         : []
+      if (currentValue && !range.includes(currentValue)) range = [currentValue, ...range]
       cameraRanges[key] = range
-      if (cameraForm[key] && range.length && !range.includes(String(cameraForm[key]))) {
-        cameraForm[key] = ''
-        dropped.push(label)
+      const selected = cameraForm[key] ? String(cameraForm[key]) : ''
+      if (!selected || (range.length && !range.includes(selected))) {
+        if (selected) dropped.push(label)
+        cameraForm[key] = currentValue || range[0] || ''
       }
     })
     if (dropped.length) {
-      ElMessage.warning(`${dropped.join('、')}不在当前点位相机范围内,已清空`)
+      ElMessage.warning(`${dropped.join('、')}不在当前点位相机范围内,已改为相机当前值`)
     }
   })
   socketStore.sendMessage({
@@ -667,6 +689,11 @@ const saveRow = async () => {
     return;
   }
 
+  if (!props.disablePointConfig && cameraParamEnabled.value && !getCameraConfigs()) {
+    ElMessage.warning('未读取到相机参数,请先读取后再保存')
+    return
+  }
+
   // 多相机模式校验
   if (isMultiCameraMode.value) {
     if (!editRowData.value.point_name) {