CameraConfig.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="selectBox">
  3. <div class="form-item" style="padding-bottom: 30px;">
  4. <div class="te-l fw-b fs-16">ISO参数(相机设置ISO auto时无效)</div>
  5. <div class="iso-inputs mar-top-20">
  6. <div class="iso-group">
  7. <span class="iso-label">用曝光灯时:</span>
  8. <div class="select-wrapper">
  9. <el-select
  10. v-model="iso_config.low"
  11. filterable
  12. default-first-option
  13. placeholder="请选择或输入ISO值"
  14. class="iso-input"
  15. >
  16. <el-option
  17. v-for="item in iso_options"
  18. :key="item"
  19. :label="item"
  20. :value="item"
  21. />
  22. </el-select>
  23. </div>
  24. </div>
  25. <div class="iso-group">
  26. <span class="iso-label">不用时:</span>
  27. <div class="select-wrapper">
  28. <el-select
  29. v-model="iso_config.high"
  30. filterable
  31. default-first-option
  32. placeholder="请选择或输入ISO值"
  33. class="iso-input"
  34. >
  35. <el-option
  36. v-for="item in iso_options"
  37. :key="item"
  38. :label="item"
  39. :value="item"
  40. />
  41. </el-select>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup>
  49. import { reactive,onMounted,ref } from 'vue'
  50. import { ElMessage } from 'element-plus'
  51. import client from "@/stores/modules/client";
  52. import icpList from '@/utils/ipc';
  53. import socket from "@/stores/modules/socket.js";
  54. const clientStore = client();
  55. const socketStore = socket(); // WebSocket状态管理实例
  56. const iso_config = reactive({
  57. low: 100,
  58. high: 6000,
  59. mode:"auto22"
  60. })
  61. const iso_options = ref(['auto',100,200,400,800,1600,3200,6400,12800])
  62. onMounted( () => {
  63. // 读取已保存的相机配置
  64. clientStore.ipc.removeAllListeners(icpList.setting.getSysConfig);
  65. clientStore.ipc.send(icpList.setting.getSysConfig,{key: 'camera_configs'});
  66. clientStore.ipc.on(icpList.setting.getSysConfig, (event, result) => {
  67. if(result.code == 0 && result.data){
  68. iso_config.low = result.data.iso_low ?? iso_config.low
  69. iso_config.high = result.data.iso_high ?? iso_config.high
  70. }
  71. clientStore.ipc.removeAllListeners(icpList.setting.getSysConfig);
  72. });
  73. // 读取设备当前可用的 ISO 档位
  74. clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_get_camera_property');
  75. socketStore.sendMessage({
  76. type: 'smart_shooter_get_camera_property'
  77. });
  78. clientStore.ipc.on(icpList.socket.message+'_smart_shooter_get_camera_property', async (event, result) => {
  79. if(result.code == 0 && result.data){
  80. const ISO = result.data.filter(item => item.CameraPropertyType == 'ISO')
  81. if(ISO.length > 0){
  82. iso_options.value = ISO[0].CameraPropertyRange
  83. }
  84. }
  85. clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_get_camera_property');
  86. })
  87. })
  88. // 暴露保存方法,给父组件调用
  89. const save = async () => {
  90. // 必填校验(允许填写数字或 'auto')
  91. const isEmpty = (v) => v === undefined || v === null || v === ''
  92. if (isEmpty(iso_config.low)) {
  93. ElMessage.error('请填写“用曝光灯时”的 ISO 值')
  94. return false
  95. }
  96. if (isEmpty(iso_config.high)) {
  97. ElMessage.error('请填写“不用时”的 ISO 值')
  98. return false
  99. }
  100. // 若均为数字,做简单范围校验(>0)
  101. const lowNum = Number(iso_config.low)
  102. const highNum = Number(iso_config.high)
  103. if (!Number.isNaN(lowNum) && lowNum <= 0) {
  104. ElMessage.error('“用曝光灯时”的 ISO 必须大于 0')
  105. return false
  106. }
  107. if (!Number.isNaN(highNum) && highNum <= 0) {
  108. ElMessage.error('“不用时”的 ISO 必须大于 0')
  109. return false
  110. }
  111. return await new Promise((resolve, reject) => {
  112. clientStore.ipc.removeAllListeners(icpList.setting.updateSysConfigs);
  113. clientStore.ipc.send(icpList.setting.updateSysConfigs,{
  114. key: 'camera_configs',
  115. value: JSON.stringify({
  116. iso_low: iso_config.low,
  117. iso_high: iso_config.high
  118. })
  119. });
  120. clientStore.ipc.on(icpList.setting.updateSysConfigs, async (event, result) => {
  121. clientStore.ipc.removeAllListeners(icpList.setting.updateSysConfigs);
  122. if(result.code === 0 && result.msg){
  123. resolve(true)
  124. } else {
  125. resolve(false)
  126. }
  127. });
  128. });
  129. }
  130. defineExpose({ save })
  131. </script>
  132. <style lang="scss" scoped>
  133. .iso-inputs {
  134. display: flex;
  135. flex-direction: column;
  136. gap: 16px;
  137. }
  138. .iso-group {
  139. display: flex;
  140. align-items: center;
  141. gap: 12px;
  142. }
  143. .iso-label {
  144. min-width: 80px;
  145. font-size: 14px;
  146. color: #1A1A1A;
  147. }
  148. .iso-input {
  149. width: 200px;
  150. }
  151. .select-wrapper {
  152. :deep(.el-input__inner) {
  153. border-radius: 6px;
  154. }
  155. }
  156. </style>