action_config.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <el-tabs v-model="topsTab" type="card" class="top_tabs">
  3. <el-tab-pane label="执行左脚程序" name="left">
  4. </el-tab-pane>
  5. <el-tab-pane label="执行右脚程序" name="right"></el-tab-pane>
  6. </el-tabs>
  7. <div class="two_tabs">
  8. <div class="item"
  9. :class="item.id === activeTab.id ? 'active' : ''"
  10. v-for="item in tabs" :key="item.id"
  11. @click="toggleTab(item)"
  12. >{{item.mode_name}}</div>
  13. </div>
  14. <div class="form-table">
  15. <div class="btnBox">
  16. <div class="primary-btn" @click="addRow">新增一行</div>
  17. <div class="primary-btn" @click="resetConfig">重新初始化</div>
  18. <div class="primary-btn" @click="reName">重命名配置</div>
  19. <el-radio-group style="margin-left: 10px" v-model="selectID" @click="changeSelectId(activeTab.id)">
  20. <el-radio :label="activeTab.id">切换成执行配置</el-radio>
  21. </el-radio-group>
  22. </div>
  23. <el-table max-height="700" :data="tableData" style="width: 100%" border>
  24. <!-- <el-table-column prop="id" label="id" />-->
  25. <el-table-column prop="action_name" label="步骤" >
  26. <template #default="scope">
  27. {{ scope.row.action_name }}
  28. <el-tag type="success" size="small" v-if="calibrationId === scope.row.id">校准位</el-tag>
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="take_picture" label="是否拍照" width="200px">
  32. <template #default="scope">
  33. <div v-if="!scope.row.is_system">
  34. {{ scope.row.take_picture ? '拍照' : '不拍照' }}
  35. </div>
  36. <span v-else></span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="value" label="操作" >
  40. <template #default="{row, $index}">
  41. <a class="mar-right-10 cursor-pointer" @click="editRow(row, $index)">编辑</a>
  42. <a class="cursor-pointer" v-if="!row.is_system" @click="deleteRow(row, $index)">删除</a>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </div>
  47. <EditDialog
  48. v-if="dialogVisible"
  49. v-model="dialogVisible"
  50. :id="editId"
  51. :addRowData="addRowData"
  52. @confirm="getList"
  53. />
  54. </template>
  55. <script setup lang="ts">
  56. import { ref, defineProps, defineEmits , watch,onMounted, reactive } from 'vue'
  57. import EditDialog from "./EditDialog.vue";
  58. import { ElMessage, ElMessageBox } from 'element-plus';import client from "@/stores/modules/client";
  59. import icpList from '@/utils/ipc';
  60. const clientStore = client();
  61. import socket from "@/stores/modules/socket";
  62. const socketStore = socket(); // WebSocket状态管理实例
  63. // 表格数据和对话框状态
  64. const tableData = ref([]); // 配置表格数据
  65. const dialogVisible = ref(false); // 编辑对话框可见状态
  66. const editTitle = ref(''); // 编辑对话框标题
  67. const addRowData = ref({}); // 新增行
  68. const topsTab = ref('left'); // 顶部tab
  69. const activeTab = ref({}); // 当前激活的标签页
  70. const tabs = ref([]); // 所有标签页
  71. const editId = ref(0); // 当前编辑行的索引
  72. const selectID = ref(0) //当前默认的ID
  73. onMounted(()=>{
  74. topsTab.value = 'left';
  75. getTopList()
  76. })
  77. /**
  78. * 监听topsTab变化,获取对应标签页的设备配置列表。
  79. */
  80. watch(() => topsTab.value, (newTab) => {
  81. getTopList();
  82. });
  83. const getTopList = ()=>{
  84. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceTabs);
  85. clientStore.ipc.send(icpList.setting.getDeviceTabs, {
  86. type: topsTab.value == 'left' ? 0 :1
  87. })
  88. clientStore.ipc.on(icpList.setting.getDeviceTabs, (event, result) => {
  89. console.log('getDeviceTabs')
  90. console.log(topsTab.value)
  91. console.log(result)
  92. if(result.code == 0 && result.data){
  93. tabs.value = result.data.tabs
  94. tabs.value.some(item=>{
  95. console.log('=======' )
  96. console.log(item.id )
  97. console.log(result.data.select_configs[topsTab.value] )
  98. if(item.id === result.data.select_configs[topsTab.value]){
  99. selectID.value = item.id
  100. activeTab.value = item
  101. return true;
  102. }
  103. })
  104. getList()
  105. }
  106. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceTabs);
  107. });
  108. }
  109. //切换tab
  110. const toggleTab = (item) => {
  111. activeTab.value = item
  112. getList()
  113. };
  114. const calibrationId = ref(null) //校准位
  115. /**
  116. * 获取设备配置列表。
  117. */
  118. const getList = () => {
  119. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceConfigList);
  120. let params = {
  121. tab_id: activeTab.value.id
  122. }
  123. clientStore.ipc.send(icpList.setting.getDeviceConfigList, params);
  124. clientStore.ipc.on(icpList.setting.getDeviceConfigList, (event, result) => {
  125. console.log('getDeviceConfigList')
  126. console.log(params)
  127. console.log(result)
  128. if (result.code == 0) {
  129. tableData.value = result.data.list;
  130. const calibration = result.data.list.filter(item=>(item.action_name === '侧视'))
  131. if(calibration.length >= 1){
  132. calibrationId.value = calibration[0].id
  133. }else{
  134. calibrationId.value = tableData.value[0].id
  135. }
  136. } else {
  137. ElMessage.error('获取列表失败');
  138. }
  139. clientStore.ipc.removeAllListeners(icpList.setting.getDeviceConfigList);
  140. });
  141. };
  142. const changeSelectId = (id)=>{
  143. if(id === selectID.value) return;
  144. clientStore.ipc.removeAllListeners(icpList.setting.updateLeftRightConfig);
  145. let params = {
  146. type: topsTab.value,
  147. id,
  148. }
  149. clientStore.ipc.send(icpList.setting.updateLeftRightConfig, params);
  150. clientStore.ipc.on(icpList.setting.updateLeftRightConfig, (event, result) => {
  151. console.log('updateLeftRightConfig')
  152. console.log(params)
  153. console.log(result)
  154. if (result.code == 0) {
  155. selectID.value = id;
  156. } else if(result.mssg){
  157. ElMessage.error(result.mssg);
  158. }else{
  159. ElMessage.error('切换失败');
  160. }
  161. clientStore.ipc.removeAllListeners(icpList.setting.updateLeftRightConfig);
  162. });
  163. }
  164. /**
  165. * 编辑指定行的配置。
  166. * @param {Object} row - 当前行的数据
  167. * @param {number} index - 当前行的索引
  168. */
  169. const editRow = (row, index) => {
  170. addRowData.value = {}
  171. dialogVisible.value = true;
  172. editId.value = row.id
  173. };
  174. /**
  175. * 删除指定行的配置。
  176. * @param {Object} row - 当前行的数据
  177. * @param {number} index - 当前行的索引
  178. */
  179. const deleteRow = (row, index) => {
  180. ElMessageBox.confirm('确定删除该步骤吗?', '提示', {
  181. confirmButtonText: '确定',
  182. cancelButtonText: '取消',
  183. type: 'warning'
  184. }).then(() => {
  185. clientStore.ipc.send(icpList.setting.removeDeviceConfig, {
  186. id: row.id
  187. });
  188. clientStore.ipc.on(icpList.setting.removeDeviceConfig, (event, result) => {
  189. if (result.code == 0) {
  190. getList();
  191. ElMessage.success('删除成功');
  192. } else if(result.mssg){
  193. ElMessage.error(result.mssg);
  194. }else {
  195. ElMessage.error('删除失败');
  196. }
  197. clientStore.ipc.removeAllListeners(icpList.setting.removeDeviceConfig);
  198. });
  199. });
  200. };
  201. /**
  202. * 重置设备配置。
  203. */
  204. const resetConfig = () => {
  205. console.log(activeTab.value);
  206. ElMessageBox.confirm(`确定初始化${activeTab.value.mode_name}吗?`, '提示', {
  207. confirmButtonText: '确定',
  208. cancelButtonText: '取消',
  209. type: 'warning'
  210. }).then(() => {
  211. clientStore.ipc.removeAllListeners(icpList.setting.resetDeviceConfig);
  212. clientStore.ipc.send(icpList.setting.resetDeviceConfig, {
  213. tab_id: activeTab.value.id
  214. });
  215. clientStore.ipc.on(icpList.setting.resetDeviceConfig, (event, result) => {
  216. if (result.code == 0) {
  217. getList();
  218. ElMessage.success('重置成功');
  219. } else if(result.mssg){
  220. ElMessage.error(result.mssg);
  221. } else {
  222. ElMessage.error('重置失败');
  223. }
  224. clientStore.ipc.removeAllListeners(icpList.setting.resetDeviceConfig);
  225. });
  226. });
  227. };
  228. const reName = ()=>{
  229. ElMessageBox.prompt('', '重命名配置', {
  230. confirmButtonText: '保存',
  231. cancelButtonText: '取消',
  232. inputValue: activeTab.value.mode_name,
  233. inputPlaceholder:'请输入配置名称',
  234. inputValidator: (value) => {
  235. if (value === '') {
  236. return '请输入配置名称';
  237. }
  238. return true;
  239. },
  240. })
  241. .then(({ value }) => {
  242. clientStore.ipc.removeAllListeners(icpList.setting.updateTabName);
  243. clientStore.ipc.send(icpList.setting.updateTabName, {
  244. id: activeTab.value.id,
  245. mode_name:value,
  246. });
  247. clientStore.ipc.on(icpList.setting.updateTabName, (event, result) => {
  248. if (result.code == 0) {
  249. activeTab.value.mode_name = value
  250. tabs.value.some(item=>{
  251. if(item.id === activeTab.value.id){
  252. item.mode_name = activeTab.value.mode_name
  253. }
  254. })
  255. ElMessage.success('重命名成功');
  256. } else if(result.mssg){
  257. ElMessage.error(result.mssg);
  258. }else {
  259. ElMessage.error('重命名失败');
  260. }
  261. clientStore.ipc.removeAllListeners(icpList.setting.updateTabName);
  262. });
  263. })
  264. }
  265. /**
  266. * 新增一行配置。
  267. */
  268. const addRow = () => {
  269. editId.value = -1
  270. let length = Number(tableData.value.length)+1
  271. addRowData.value = {
  272. mode_type: topsTab.value === 'left' ? '执行左脚程序' : '执行右脚程序',
  273. tab_id: activeTab.value.id,
  274. action_name: '新增步骤'+length,
  275. take_picture: false,
  276. camera_height: 0,
  277. camera_angle: 0,
  278. turntable_position: 0,
  279. turntable_angle: 0,
  280. shoe_upturn: false,
  281. led_switch: false,
  282. number_focus: 0,
  283. pre_delay: 0,
  284. after_delay: 0,
  285. }
  286. dialogVisible.value = true;
  287. editTitle.value = '新增步骤';
  288. };
  289. </script>
  290. <style lang="scss" scoped>
  291. .top_tabs {
  292. height: 30px;
  293. overflow: hidden;
  294. border: 1px solid #c8c8c8;
  295. border-bottom: none;
  296. }
  297. .two_tabs {
  298. width: 100%;
  299. height: 30px;
  300. background: #fff;
  301. border: 1px solid #c8c8c8;
  302. border-top: none;
  303. .item {
  304. float: left;
  305. padding: 0 15px;
  306. font-size: 14px;
  307. height: 30px;
  308. line-height: 30px;
  309. cursor: pointer;
  310. &.active {
  311. color: #2957FF;
  312. }
  313. }
  314. }
  315. .form-table{
  316. margin-top: 10px;
  317. .btnBox{
  318. display: flex;
  319. align-items: center;
  320. margin-bottom: 12px;
  321. }
  322. :deep(.el-table .el-table__header){
  323. padding: 0;
  324. height: 30px;
  325. .el-table__cell{
  326. background: #F1F4FF;
  327. }
  328. }
  329. :deep(.el-table .el-table__cell){
  330. padding: 0;
  331. text-align: center;
  332. }
  333. :deep(.el-table__row) {
  334. height: 30px;
  335. padding: 0;
  336. &:nth-child(even) {
  337. background: #F1F4FF;
  338. }
  339. &:nth-child(odd) {
  340. background: #FFFFFF;
  341. }
  342. }
  343. .primary-btn{
  344. width: 80px;
  345. height: 30px;
  346. background: linear-gradient( 135deg, #2FB0FF 0%, #B863FB 100%);
  347. border-radius: 4px;
  348. color: #fff;
  349. font-size: 14px;
  350. text-align: center;
  351. cursor: pointer;
  352. line-height: 30px;
  353. margin-right: 10px;
  354. }
  355. .normal-btn{
  356. width: 80px;
  357. height: 30px;
  358. background: #fff;
  359. border: 1px solid #CCCCCC;
  360. border-radius: 4px;
  361. font-size: 14px;
  362. text-align: center;
  363. line-height: 30px;
  364. cursor: pointer;
  365. }
  366. .cursor-pointer{
  367. cursor: pointer;
  368. }
  369. }
  370. .editDialog{
  371. .el-dialog__body{
  372. padding: 0 !important;
  373. }
  374. .btn-row{
  375. display: flex;
  376. align-items: center;
  377. justify-content: flex-end;
  378. gap: 10px;
  379. }
  380. .primary-btn{
  381. width: 100px;
  382. height: 30px;
  383. background: linear-gradient( 135deg, #2FB0FF 0%, #B863FB 100%);
  384. border-radius: 4px;
  385. color: #fff;
  386. font-size: 14px;
  387. text-align: center;
  388. line-height: 30px;
  389. cursor: pointer;
  390. }
  391. .normal-btn{
  392. width: 100px;
  393. height: 30px;
  394. background: #fff;
  395. border: 1px solid #CCCCCC;
  396. border-radius: 4px;
  397. font-size: 14px;
  398. text-align: center;
  399. line-height: 30px;
  400. cursor: pointer;
  401. }
  402. }
  403. </style>