editRow.vue 11 KB

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