DockControlPanel.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="dock-control-panel">
  3. <!-- title -->
  4. <div class="dock-control-panel-header fz16 pl5 pr5 flex-align-center flex-row flex-justify-between">
  5. <span>
  6. <span>
  7. 设备控制
  8. </span>
  9. <span class="fz12 pl15">
  10. {{ props.sn }}
  11. </span>
  12. </span>
  13. <span style="cursor: pointer;" @click="closeControlPanel">
  14. <CloseOutlined />
  15. </span>
  16. </div>
  17. <!-- setting -->
  18. <DeviceSettingBox :sn="props.sn" :deviceInfo="props.deviceInfo"></DeviceSettingBox>
  19. <!-- cmd -->
  20. <div class="control-cmd-wrapper">
  21. <div class="control-cmd-header">
  22. 设备远程调试
  23. <a-switch class="debug-btn" checked-children="开" un-checked-children="关" v-model:checked="debugStatus"
  24. @change="onDeviceStatusChange" />
  25. </div>
  26. <div class="control-cmd-box">
  27. <div v-for="(cmdItem, index) in cmdList" :key="cmdItem.cmdKey" class="control-cmd-item">
  28. <div class="control-cmd-item-left">
  29. <div class="item-label">{{ cmdItem.label }}</div>
  30. <div class="item-status">{{ cmdItem.status }}</div>
  31. </div>
  32. <div class="control-cmd-item-right">
  33. <a-button :disabled="!debugStatus || cmdItem.disabled" :loading="cmdItem.loading" size="small"
  34. type="primary" @click="sendControlCmd(cmdItem, index)">
  35. {{ cmdItem.operateText }}
  36. </a-button>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script setup lang="ts">
  44. import { defineProps, defineEmits, ref, watch } from 'vue'
  45. import { CloseOutlined } from '@ant-design/icons-vue'
  46. import { useDockControl } from './use-dock-control'
  47. import { DeviceInfoType, EDockModeCode } from '/@/types/device'
  48. import { cmdList as baseCmdList, DeviceCmdItem } from '/@/types/device-cmd'
  49. import { useMyStore } from '/@/store'
  50. import { updateDeviceCmdInfoByOsd, updateDeviceCmdInfoByExecuteInfo } from '/@/utils/device-cmd'
  51. import DeviceSettingBox from './DeviceSettingBox.vue'
  52. const props = defineProps<{
  53. sn: string,
  54. deviceInfo: DeviceInfoType,
  55. }>()
  56. const store = useMyStore()
  57. const initCmdList = baseCmdList.map(cmdItem => Object.assign({}, cmdItem))
  58. const cmdList = ref(initCmdList)
  59. // 根据机场指令执行状态更新信息
  60. watch(() => store.state.devicesCmdExecuteInfo, (devicesCmdExecuteInfo) => {
  61. if (props.sn && devicesCmdExecuteInfo[props.sn]) {
  62. updateDeviceCmdInfoByExecuteInfo(cmdList.value, devicesCmdExecuteInfo[props.sn])
  63. }
  64. }, {
  65. immediate: true,
  66. deep: true,
  67. })
  68. // 根据设备osd信息更新信息
  69. watch(() => props.deviceInfo, (value) => {
  70. updateDeviceCmdInfoByOsd(cmdList.value, value)
  71. // console.log('deviceInfo', value)
  72. }, {
  73. immediate: true,
  74. deep: true
  75. })
  76. // dock 控制指令
  77. const debugStatus = ref(props.deviceInfo.dock?.basic_osd?.mode_code === EDockModeCode.Remote_Debugging)
  78. const emit = defineEmits(['close-control-panel'])
  79. function closeControlPanel() {
  80. emit('close-control-panel', props.sn, debugStatus.value)
  81. }
  82. async function onDeviceStatusChange(status: boolean) {
  83. let result = false
  84. if (status) {
  85. result = await dockDebugOnOff(props.sn, true)
  86. } else {
  87. result = await dockDebugOnOff(props.sn, false)
  88. }
  89. if (!result) {
  90. if (status) {
  91. debugStatus.value = false
  92. } else {
  93. debugStatus.value = true
  94. }
  95. }
  96. }
  97. const {
  98. sendDockControlCmd,
  99. dockDebugOnOff
  100. } = useDockControl()
  101. async function sendControlCmd(cmdItem: DeviceCmdItem, index: number) {
  102. const success = await sendDockControlCmd({
  103. sn: props.sn,
  104. cmd: cmdItem.cmdKey,
  105. action: cmdItem.action
  106. }, true)
  107. if (success) {
  108. // updateDeviceSingleCmdInfo(cmdList.value[index])
  109. }
  110. }
  111. </script>
  112. <style lang='scss' scoped>
  113. .dock-control-panel {
  114. position: absolute;
  115. left: calc(100% + 10px);
  116. top: 0px;
  117. width: 480px;
  118. padding: 0 !important;
  119. background: #000;
  120. color: #fff;
  121. border-radius: 2px;
  122. .dock-control-panel-header {
  123. padding: 10px;
  124. border-bottom: 1px solid #515151;
  125. }
  126. .control-cmd-wrapper {
  127. .control-cmd-header {
  128. font-size: 14px;
  129. font-weight: 600;
  130. padding: 10px 10px 0px;
  131. .debug-btn {
  132. margin-left: 10px;
  133. border: 1px solid #585858;
  134. }
  135. }
  136. .control-cmd-box {
  137. display: flex;
  138. flex-wrap: wrap;
  139. justify-content: space-between;
  140. padding: 4px 10px;
  141. .control-cmd-item {
  142. width: 220px;
  143. height: 58px;
  144. display: flex;
  145. align-items: center;
  146. justify-content: space-between;
  147. border: 1px solid #666;
  148. margin: 4px 0;
  149. padding: 0 8px;
  150. .control-cmd-item-left {
  151. display: flex;
  152. flex-direction: column;
  153. .item-label {
  154. font-weight: 700;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. </style>