|
|
@@ -60,43 +60,32 @@
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
|
|
|
- <!-- 设备状态对话框 -->
|
|
|
- <el-dialog
|
|
|
- v-model="showStatusDialog"
|
|
|
- title="设备运行状态"
|
|
|
- width="600px"
|
|
|
- :close-on-click-modal="false"
|
|
|
- >
|
|
|
- <div class="status-content">
|
|
|
- <div class="status-item" v-for="(status, key) in deviceStatus" :key="key">
|
|
|
- <span class="status-label">{{ getStatusLabel(key) }}:</span>
|
|
|
- <span class="status-value" :class="getStatusClass(status)">{{ getStatusText(status) }}</span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <template #footer>
|
|
|
- <span class="dialog-footer">
|
|
|
- <el-button @click="showStatusDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" :loading="statusLoading" @click="getDeviceStatus">刷新</el-button>
|
|
|
- </span>
|
|
|
- </template>
|
|
|
- </el-dialog>
|
|
|
+ <!-- 使用统一的设备状态对话框组件 -->
|
|
|
+ <DeviceStatusDialog />
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, computed, watch, onBeforeUnmount, nextTick, watchEffect } from 'vue';
|
|
|
-import { ElMessage, ElDialog, ElButton } from 'element-plus';
|
|
|
+import { ref, watchEffect } from 'vue';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
import useUserInfo from "@/stores/modules/user";
|
|
|
import checkInfo from "@/stores/modules/check";
|
|
|
import client from "@/stores/modules/client";
|
|
|
-import socket from "@/stores/modules/socket";
|
|
|
-import icpList from '@/utils/ipc';
|
|
|
-const clientStore = client();
|
|
|
+import DeviceStatusDialog from '@/components/device-status-dialog/index.vue';
|
|
|
+import useDeviceStatusStore from '@/stores/modules/deviceStatus';
|
|
|
+
|
|
|
+const useUserInfoStore = useUserInfo()
|
|
|
+const checkInfoStore = checkInfo()
|
|
|
+const clientStore = client()
|
|
|
+const deviceStatusStore = useDeviceStatusStore()
|
|
|
+
|
|
|
+// 检测是否成功的状态
|
|
|
+const checkSuccess = ref(false);
|
|
|
+
|
|
|
+// 检测加载状态
|
|
|
+const checkLoading = ref(true);
|
|
|
|
|
|
/**
|
|
|
* 定义组件的 props。
|
|
|
- * @param {Object} props
|
|
|
- * @param {Boolean} props.modelValue - 控制对话框显示状态的双向绑定值,默认为 false。
|
|
|
- * @param {String} props.title - 对话框标题,默认为 '检测硬件'。
|
|
|
*/
|
|
|
const props = defineProps({
|
|
|
isInitCheck: {
|
|
|
@@ -109,31 +98,7 @@ const props = defineProps({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-// 初始化用户信息状态管理
|
|
|
-const useUserInfoStore = useUserInfo()
|
|
|
-const checkInfoStore = checkInfo()
|
|
|
-const socketStore = socket()
|
|
|
-
|
|
|
-// 检测是否成功的状态
|
|
|
-const checkSuccess = ref(false);
|
|
|
-
|
|
|
-// 检测加载状态
|
|
|
-const checkLoading = ref(true);
|
|
|
-
|
|
|
-// 设备状态相关
|
|
|
-const showStatusDialog = ref(false);
|
|
|
-const statusLoading = ref(false);
|
|
|
-const deviceStatus = ref({
|
|
|
- state_camera_motor: 0,
|
|
|
- state_camera_steering: 0,
|
|
|
- state_turntable_steering: 0,
|
|
|
- state_move_turntable_steering: 0,
|
|
|
- state_overturn_steering: 0
|
|
|
-});
|
|
|
-
|
|
|
-// 定义事件发射器,用于更新父组件的 modelValue 和触发 confirm 事件
|
|
|
-const emit = defineEmits([ 'confirm']);
|
|
|
+const emit = defineEmits(['confirm']);
|
|
|
|
|
|
// 检测次数计数器
|
|
|
const checkCount = ref(props.isInitCheck ? 0 : 1);
|
|
|
@@ -231,98 +196,10 @@ function confirm(){
|
|
|
emit('confirm')
|
|
|
}
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.message + '_get_mcu_info')
|
|
|
-})
|
|
|
-
|
|
|
-// 状态文本映射
|
|
|
-const stateTextMap = {
|
|
|
- 0: "未初始化",
|
|
|
- 1: "运动中",
|
|
|
- 2: "已停止",
|
|
|
- 3: "未在线",
|
|
|
- 4: "堵转"
|
|
|
-}
|
|
|
-
|
|
|
-// 获取状态标签
|
|
|
-function getStatusLabel(key) {
|
|
|
- const labelMap = {
|
|
|
- state_camera_motor: '相机高度状态',
|
|
|
- state_camera_steering: '相机角度状态',
|
|
|
- state_turntable_steering: '转盘状态',
|
|
|
- state_move_turntable_steering: '转盘前后移动状态',
|
|
|
- state_overturn_steering: '翻板状态'
|
|
|
- }
|
|
|
- return labelMap[key] || key
|
|
|
-}
|
|
|
-
|
|
|
-// 获取状态文本
|
|
|
-function getStatusText(status) {
|
|
|
- return stateTextMap[status] || '未知状态'
|
|
|
-}
|
|
|
-
|
|
|
-// 获取状态样式类
|
|
|
-function getStatusClass(status) {
|
|
|
- const classMap = {
|
|
|
- 0: 'status-uninit',
|
|
|
- 1: 'status-moving',
|
|
|
- 2: 'status-stopped',
|
|
|
- 3: 'status-offline',
|
|
|
- 4: 'status-blocked'
|
|
|
- }
|
|
|
- return classMap[status] || 'status-unknown'
|
|
|
-}
|
|
|
-
|
|
|
-// 打开状态对话框
|
|
|
+// 打开设备状态对话框
|
|
|
function openStatusDialog() {
|
|
|
- showStatusDialog.value = true
|
|
|
- getDeviceStatus()
|
|
|
+ deviceStatusStore.openDialog();
|
|
|
}
|
|
|
-
|
|
|
-// 获取设备状态
|
|
|
-function getDeviceStatus() {
|
|
|
- statusLoading.value = true
|
|
|
-
|
|
|
- // 移除之前的监听器
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.message + '_get_mcu_info')
|
|
|
-
|
|
|
- // 发送获取MCU信息的消息
|
|
|
- socketStore.sendMessage({
|
|
|
- type: 'get_mcu_info',
|
|
|
- data: null
|
|
|
- })
|
|
|
-
|
|
|
- // 监听MCU信息响应
|
|
|
- clientStore.ipc.on(icpList.socket.message + '_get_mcu_info', (event, result) => {
|
|
|
- console.log('_get_mcu_info')
|
|
|
- console.log(result)
|
|
|
- statusLoading.value = false
|
|
|
-
|
|
|
- if (result.code === 0 && result.data.data_state) {
|
|
|
- deviceStatus.value = {
|
|
|
- state_camera_motor: result.data.data_state.state_camera_motor || 0,
|
|
|
- state_camera_steering: result.data.data_state.state_camera_steering || 0,
|
|
|
- state_turntable_steering: result.data.data_state.state_turntable_steering || 0,
|
|
|
- state_move_turntable_steering: result.data.data_state.state_move_turntable_steering || 0,
|
|
|
- state_overturn_steering: result.data.data_state.state_overturn_steering || 0
|
|
|
- }
|
|
|
- } else {
|
|
|
- ElMessage.error(result.msg || '获取设备状态失败')
|
|
|
- }
|
|
|
-
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.message + '_get_mcu_info')
|
|
|
- })
|
|
|
-
|
|
|
- // 设置超时
|
|
|
- setTimeout(() => {
|
|
|
- if (statusLoading.value) {
|
|
|
- statusLoading.value = false
|
|
|
- ElMessage.error('获取设备状态超时')
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.message + '_get_mcu_info')
|
|
|
- }
|
|
|
- }, 10000)
|
|
|
-}
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
|