|
|
@@ -3,6 +3,7 @@
|
|
|
v-model="visible"
|
|
|
:title="title"
|
|
|
:close-on-click-modal="false"
|
|
|
+ :show-close="false"
|
|
|
width="500px"
|
|
|
class="hardware-check-dialog"
|
|
|
>
|
|
|
@@ -21,8 +22,8 @@
|
|
|
<template v-else-if="checkSuccess">硬件检测完成</template>
|
|
|
<template v-else>初始化检测硬件失败</template>
|
|
|
</div>
|
|
|
- <el-progress
|
|
|
- :percentage="progress"
|
|
|
+ <el-progress
|
|
|
+ :percentage="progress"
|
|
|
:colors="['#2FB0FF', '#B863FB']"
|
|
|
:stroke-width="8"
|
|
|
v-if="checkLoading"
|
|
|
@@ -30,7 +31,7 @@
|
|
|
<div class="check-error-result" v-else-if="!checkSuccess">失败的原因,比如请检查硬件链接</div>
|
|
|
</div>
|
|
|
</el-timeline-item>
|
|
|
-
|
|
|
+
|
|
|
<!-- Step 2 -->
|
|
|
<el-timeline-item
|
|
|
:type="'primary'"
|
|
|
@@ -60,8 +61,19 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, computed, watch, onBeforeUnmount, nextTick } from 'vue';
|
|
|
-
|
|
|
+import { ref, computed, watch, onBeforeUnmount, nextTick, watchEffect } from 'vue';
|
|
|
+import icpList from '@/utils/ipc'
|
|
|
+import client from "@/stores/modules/client";
|
|
|
+import useUserInfo from "@/stores/modules/user";
|
|
|
+import socket from "@/stores/modules/socket";
|
|
|
+import checkInfo from "@/stores/modules/check";
|
|
|
+
|
|
|
+/**
|
|
|
+ * 定义组件的 props。
|
|
|
+ * @param {Object} props
|
|
|
+ * @param {Boolean} props.modelValue - 控制对话框显示状态的双向绑定值,默认为 false。
|
|
|
+ * @param {String} props.title - 对话框标题,默认为 '检测硬件'。
|
|
|
+ */
|
|
|
const props = defineProps({
|
|
|
modelValue: {
|
|
|
type: Boolean,
|
|
|
@@ -72,60 +84,105 @@ const props = defineProps({
|
|
|
default: '检测硬件'
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+const checkInfoStore = checkInfo()
|
|
|
+
|
|
|
+// 检测是否成功的状态
|
|
|
const checkSuccess = ref(false);
|
|
|
-const checkLoading = ref(false)
|
|
|
+
|
|
|
+// 检测加载状态
|
|
|
+const checkLoading = ref(false);
|
|
|
+
|
|
|
+// 定义事件发射器,用于更新父组件的 modelValue 和触发 confirm 事件
|
|
|
const emit = defineEmits(['update:modelValue', 'confirm']);
|
|
|
|
|
|
-const progress = ref(80);
|
|
|
+// 检测次数计数器
|
|
|
+const checkCount = ref(0);
|
|
|
+
|
|
|
+// 进度条的当前进度值
|
|
|
+const progress = checkInfoStore.getProgress
|
|
|
+
|
|
|
+// 定时器变量,用于控制进度条的递增
|
|
|
let timer = null;
|
|
|
|
|
|
-const visible = computed({
|
|
|
- get() {
|
|
|
- return props.modelValue;
|
|
|
- },
|
|
|
- set(val) {
|
|
|
- emit('update:modelValue', val);
|
|
|
- }
|
|
|
-});
|
|
|
+// 控制组件可见性的状态
|
|
|
+const visible = ref(false);
|
|
|
|
|
|
+/**
|
|
|
+ * 开始进度条的递增逻辑。
|
|
|
+ * 该函数会重置进度条并启动定时器,逐步增加进度值直到达到 80。
|
|
|
+ */
|
|
|
function startProgress() {
|
|
|
progress.value = 0;
|
|
|
checkLoading.value = true;
|
|
|
- timer = setInterval(() => {
|
|
|
- if (progress.value < 80) {
|
|
|
- progress.value += 1;
|
|
|
- } else {
|
|
|
- checkSuccess.value = false;
|
|
|
- clearInterval(timer);
|
|
|
- }
|
|
|
- }, 50);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 重新执行检测逻辑。
|
|
|
+ * 调用 startProgress 函数以重新开始进度条。
|
|
|
+ */
|
|
|
function reCheck() {
|
|
|
- startProgress();
|
|
|
+ startProgress()
|
|
|
+ listenerMessage()
|
|
|
}
|
|
|
|
|
|
+// 初始化客户端状态管理
|
|
|
+const clientStore = client();
|
|
|
|
|
|
-function handleConfirm() {
|
|
|
- emit('confirm');
|
|
|
- visible.value = false;
|
|
|
-}
|
|
|
+// 初始化用户信息状态管理
|
|
|
+const useUserInfoStore = useUserInfo()
|
|
|
+
|
|
|
+// 初始化 WebSocket 状态管理
|
|
|
+const socketStore = socket()
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 监听用户信息和检测次数的变化,自动触发相关逻辑。
|
|
|
+ * 当用户信息存在且检测次数为 0 时,设置组件可见性为 true,
|
|
|
+ * 并尝试连接 WebSocket 和发送消息。
|
|
|
+ */
|
|
|
+watchEffect(async ()=>{
|
|
|
+ if( useUserInfoStore.userInfo.id && checkCount.value === 0){
|
|
|
+ // console.log('aaa')
|
|
|
+ await socketStore.disconnectSocket()
|
|
|
+ console.log('watchEffect');
|
|
|
+ checkCount.value++;
|
|
|
+ await socketStore.connectSocket()
|
|
|
+ visible.value = true
|
|
|
+ startProgress()
|
|
|
+ listenerMessage()
|
|
|
|
|
|
-watch(visible, (val) => {
|
|
|
- if (val) {
|
|
|
- nextTick(() => {
|
|
|
- startProgress();
|
|
|
- });
|
|
|
- } else {
|
|
|
- clearInterval(timer);
|
|
|
}
|
|
|
-});
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+async function listenerMessage(){
|
|
|
+
|
|
|
+/* //发送设备连接检测请求
|
|
|
+ await socketStore.sendMessage({
|
|
|
+ type: 'connect_mcu',
|
|
|
+ })
|
|
|
+*/
|
|
|
+ //发送遥控器请求
|
|
|
+/* await socketStore.sendMessage({
|
|
|
+ type: 'connect_bluetooth',
|
|
|
+ })*/
|
|
|
+ if(clientStore.isClient){
|
|
|
+ clientStore.ipc.removeAllListeners(icpList.socket.message);
|
|
|
+ clientStore.ipc.on(icpList.socket.message, async (event, result) => {
|
|
|
+ console.log(result);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- clearInterval(timer);
|
|
|
-});
|
|
|
</script>
|
|
|
|
|
|
+
|
|
|
<style lang="scss" scoped>
|
|
|
.hardware-check-container {
|
|
|
padding: 20px 0;
|
|
|
@@ -145,7 +202,7 @@ color: #000000;
|
|
|
}
|
|
|
|
|
|
.progress-text {
|
|
|
- text-align: right;
|
|
|
+ text-align: right;
|
|
|
margin-top: 5px;
|
|
|
color: #606266;
|
|
|
}
|
|
|
@@ -183,4 +240,4 @@ color: #000000;
|
|
|
text-align: left;
|
|
|
color: #FF4C00;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|