editRow.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="editrow_wrap" v-if="initStatus">
  3. <div class="config-type">参数值编辑:<el-checkbox v-model="isDefault">开启运动调试</el-checkbox></div>
  4. <el-form class="editForm" :model="editRowData" label-width="100px">
  5. <el-form-item label="动作名称">
  6. <el-input v-model="editRowData.action_name" style="width: 170px;"/>
  7. </el-form-item>
  8. <el-form-item label="是否拍照">
  9. <el-radio-group v-model="editRowData.take_picture">
  10. <el-radio :label="true">拍照</el-radio>
  11. <el-radio :label="false">不拍照</el-radio>
  12. </el-radio-group>
  13. </el-form-item>
  14. <el-form-item label="相机高度(mm)">
  15. <el-input v-model="editRowData.camera_height" @change="changeNum('camera_high_motor',0, 400)" :min="0" :max="400" :step="1" style="width: 170px;" type="number">
  16. </el-input>
  17. <div class="error-msg">最小0,最大400</div>
  18. </el-form-item>
  19. <el-form-item label="相机倾角">
  20. <el-input v-model="editRowData.camera_angle" :min="-40" :max="40" :step=".1" @change="changeNum('camera_steering',-40, 40)" style="width: 170px;" type="number">
  21. </el-input>
  22. <div class="error-msg">最小-40,最大40</div>
  23. </el-form-item>
  24. <el-form-item label="转盘前后位置">
  25. <el-input v-model="editRowData.turntable_position" @change="changeNum('turntable_position_motor',0, 800)" :min="0" :max="800" :step="1" style="width: 170px;" type="number">
  26. </el-input>
  27. <div class="error-msg">最小0,最大800</div>
  28. </el-form-item>
  29. <el-form-item label="转盘角度">
  30. <el-input v-model="editRowData.turntable_angle" @change="changeNum('turntable_steering',-720, 720)" :min="-720" :max="720" :step="1" style="width: 170px;" type="number">
  31. </el-input>
  32. <div class="error-msg">最小-720,最大720</div>
  33. </el-form-item>
  34. <el-form-item label="鞋子翻转">
  35. <div class="flex-row">
  36. <el-radio-group v-model="editRowData.shoe_upturn">
  37. <el-radio :label="true">翻转</el-radio>
  38. <el-radio :label="false">不翻转</el-radio>
  39. </el-radio-group>
  40. <a class="cursor-pointer" @click="changeNum('overturn_steering')">测试翻转</a>
  41. </div>
  42. </el-form-item>
  43. <el-form-item label="LED灯光开光" @change="changeNum('laser_position')">
  44. <el-radio-group v-model="editRowData.led_switch">
  45. <el-radio :label="false">关闭</el-radio>
  46. <el-radio :label="true">开启</el-radio>
  47. </el-radio-group>
  48. </el-form-item>
  49. <el-form-item label="对焦次数">
  50. <el-input v-model="editRowData.number_focus" @change="changeNum('take_picture',0, 1)" :min="0" :max="1" :step="1" style="width: 170px;" type="number">
  51. </el-input>
  52. <div class="error-msg">最小0,最大1</div>
  53. </el-form-item>
  54. <el-form-item label="拍照前延时(秒)">
  55. <el-input v-model="editRowData.pre_delay" :min="0" :max="99" :step="1" @change="changeNum('pre_delay',0, 99)" style="width: 170px;" type="number">
  56. </el-input>
  57. <div class="error-msg">最小0,最大99</div>
  58. </el-form-item>
  59. <el-form-item label="拍照后延时(秒)">
  60. <el-input v-model="editRowData.after_delay" :min="0" :max="99" :step="1" @change="changeNum('after_delay',0, 99)" style="width: 170px;" type="number">
  61. </el-input>
  62. <div class="error-msg">最小0,最大99</div>
  63. </el-form-item>
  64. </el-form>
  65. <div class="btn-row mar-top-20">
  66. <div class="normal-btn" @click="close" v-if="id">取消</div>
  67. <div class="primary-btn" @click="saveRow" v-if="id">{{ id ? '保存并关闭' : '保存' }}</div>
  68. </div>
  69. </div>
  70. </template>
  71. <script setup lang="ts">
  72. import { ref, defineProps, defineEmits , watch, onMounted } from 'vue'
  73. import icpList from '@/utils/ipc';
  74. import { digiCamControlWEB } from '@/utils/appconfig'
  75. import {ElMessage} from "element-plus";
  76. import client from "@/stores/modules/client";
  77. const clientStore = client();
  78. import socket from "@/stores/modules/socket";
  79. const socketStore = socket(); // WebSocket状态管理实例
  80. // 定义 props
  81. const props = defineProps({
  82. id:{
  83. type: Number||String,
  84. default: 0
  85. },
  86. addRowData:{
  87. type: Object,
  88. default: () => {
  89. return { }
  90. }
  91. }
  92. })
  93. const initStatus = ref(false)
  94. const isDefault = ref(true); // 是否为默认配置
  95. const editRowData = ref({}); // 当前编辑行的数据
  96. onMounted(()=>{
  97. if(props.addRowData.mode_type){
  98. console.log(props.addRowData);
  99. initStatus.value = true
  100. editRowData.value = props.addRowData;
  101. return
  102. }
  103. let params = {
  104. id: props.id
  105. }
  106. if(!props.id) params = {
  107. mode_type:"执行左脚程序",
  108. action_name:"侧视图",
  109. }
  110. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceConfigDetail);
  111. clientStore.ipc.send(icpList.setting.getDeviceConfigDetail, params);
  112. clientStore.ipc.on(icpList.setting.getDeviceConfigDetail, (event, result) => {
  113. editRowData.value = result.data;
  114. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceConfigDetail);
  115. initStatus.value = true;
  116. });
  117. })
  118. /**
  119. * 修改设备配置数值。
  120. * @param {string} type - 配置类型
  121. */
  122. async function changeNum(type, min, max) {
  123. let socketValue = {
  124. 'camera_high_motor': 'camera_height',
  125. 'turntable_steering': 'turntable_angle',
  126. 'turntable_position_motor': 'turntable_position',
  127. 'camera_steering': 'camera_angle',
  128. 'overturn_steering': 'shoe_upturn',
  129. 'laser_position': 'led_switch',
  130. 'take_picture': 'number_focus',
  131. };
  132. if(min || max){
  133. if(editRowData.value[socketValue[type]] < min || editRowData.value[socketValue[type]] > max){
  134. if(editRowData.value[socketValue[type]] < min){
  135. editRowData.value[socketValue[type]] = min;
  136. }else{
  137. editRowData.value[socketValue[type]] = max;
  138. }
  139. ElMessage.error(`${type}值应在${min}到${max}之间`);
  140. return;
  141. }
  142. }
  143. if(type=='pre_delay' || type=='after_delay'){
  144. return
  145. }
  146. if (isDefault.value) {
  147. socketStore.sendMessage({
  148. type: 'control_mcu',
  149. data: {
  150. device_name: type,
  151. value: type == 'laser_position' ? (editRowData.value.led_switch ? "1" : "0") : editRowData.value[socketValue[type]]
  152. }
  153. });
  154. }
  155. }
  156. /*测试拍照*/
  157. const captureLoading = ref(false)
  158. const imageUrl = ref(digiCamControlWEB+'preview.jpg')
  159. const imageUrlkey = ref(0)
  160. function testShoesFlip(){
  161. if (clientStore.isClient) {
  162. socketStore.sendMessage({
  163. type: 'run_mcu_single',
  164. data: {
  165. camera_height: Number(editRowData.value.camera_height),
  166. camera_angle: Number(editRowData.value.camera_angle),
  167. led_switch:editRowData.value.led_switch,
  168. id:0,
  169. mode_type:'执行'+ activeTab.value === 'left' ? '左脚' : '右脚'+'程序',
  170. turntable_position:Number(editRowData.value.turntable_position),
  171. action_name:editRowData.value.action_name || '测试',
  172. turntable_angle: Number(editRowData.value.turntable_angle),
  173. shoe_upturn: Number(editRowData.value.shoe_upturn),
  174. action_index:1,
  175. number_focus:0,
  176. take_picture:false,
  177. pre_delay:0,
  178. after_delay:0,
  179. }
  180. });
  181. captureLoading.value = true;
  182. clientStore.ipc.on(icpList.socket.message+'_run_mcu_single_finish', async (event, result) => {
  183. console.log('_run_mcu_single_finish')
  184. setTimeout(()=>{
  185. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  186. clientStore.ipc.send(icpList.camera.takePictures,false);
  187. clientStore.ipc.on(icpList.camera.takePictures, async (event, result) => {
  188. setTimeout(()=>{
  189. imageUrlkey.value++;
  190. console.log('preview')
  191. preview(imageUrl.value+'?key='+imageUrlkey.value)
  192. captureLoading.value = false;
  193. },8000)
  194. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  195. })
  196. },1000)
  197. })
  198. }
  199. }
  200. const emit = defineEmits([ 'confirm','onClose']);
  201. const close = ()=>{
  202. console.log('onClose')
  203. emit('onClose')
  204. }
  205. /**
  206. * 保存当前编辑的配置。
  207. */
  208. const saveRow = () => {
  209. clientStore.ipc.send(icpList.setting.saveDeviceConfig, {
  210. ...editRowData.value
  211. });
  212. clientStore.ipc.on(icpList.setting.saveDeviceConfig, (event, result) => {
  213. if (result.code == 0) {
  214. emit('confirm')
  215. ElMessage.success('保存成功');
  216. clientStore.ipc.removeAllListeners(icpList.setting.saveDeviceConfig);
  217. } else {
  218. ElMessage.error('保存失败');
  219. }
  220. });
  221. };
  222. </script>
  223. <style>
  224. </style>
  225. <style lang="scss" scoped>
  226. .editrow_wrap {
  227. }
  228. .config-type{
  229. font-size: 16px;
  230. color: #333333;
  231. display: flex;
  232. align-items: center;
  233. justify-content: flex-start;
  234. padding: 10px;
  235. border-bottom: 1px solid #CCCCCC;
  236. .el-checkbox{
  237. margin-left: 10px;
  238. }
  239. }
  240. .editForm{
  241. padding: 10px;
  242. display: grid;
  243. grid-template-columns: repeat(1, 1fr);
  244. gap: 0;
  245. .flex-row{
  246. display: flex;
  247. align-items: center;
  248. :deep(.el-radio){
  249. margin-right: 6px !important;
  250. }
  251. :deep(.el-radio__label){
  252. padding-left: 4px;
  253. }
  254. }
  255. :deep(.el-form-item) {
  256. margin-bottom: 0;
  257. .el-form-item__label {
  258. width: 120px !important;
  259. padding-right: 0 !important;
  260. background: #FBFCFF;
  261. border: 1px solid #EEEEEE;
  262. height: 41px;
  263. line-height: 41px;
  264. padding-left: 5px;
  265. text-align: left;
  266. }
  267. .el-form-item__content {
  268. width: 190px;
  269. position: relative;
  270. height: 41px;
  271. background: #FFFFFF;
  272. padding-left: 7px;
  273. border: 1px solid #EEEEEE;
  274. .el-input__wrapper {
  275. box-shadow: none;
  276. }
  277. .error-msg{
  278. display: none;
  279. position: absolute;
  280. top: 41px;
  281. top: 28px;
  282. left: 8px;
  283. z-index: 22;
  284. color: #dc2626;
  285. font-size: 12px;
  286. }
  287. &:hover{
  288. .error-msg{
  289. display: block;
  290. }
  291. }
  292. // 确保number类型输入框的上下箭头始终显示
  293. input[type="number"]::-webkit-inner-spin-button,
  294. input[type="number"]::-webkit-outer-spin-button {
  295. opacity: 1;
  296. height: 28px;
  297. position: absolute;
  298. top: 2px;
  299. right: 2px;
  300. cursor: pointer;
  301. }
  302. input[type="number"] {
  303. -moz-appearance: number-input; /* Firefox */
  304. }
  305. }
  306. }
  307. }
  308. .btn-row{
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. gap: 10px;
  313. }
  314. .primary-btn{
  315. width: 100px;
  316. height: 30px;
  317. background: linear-gradient( 135deg, #2FB0FF 0%, #B863FB 100%);
  318. border-radius: 4px;
  319. color: #fff;
  320. font-size: 14px;
  321. text-align: center;
  322. line-height: 30px;
  323. cursor: pointer;
  324. }
  325. .normal-btn{
  326. width: 100px;
  327. height: 30px;
  328. background: #fff;
  329. border: 1px solid #CCCCCC;
  330. border-radius: 4px;
  331. font-size: 14px;
  332. text-align: center;
  333. line-height: 30px;
  334. cursor: pointer;
  335. }
  336. </style>