editRow.vue 10 KB

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