From 7f164af532f66aff71419682c5b3f531b606983a Mon Sep 17 00:00:00 2001
From: zhaochongyi <11111>
Date: 星期五, 30 八月 2024 18:56:13 +0800
Subject: [PATCH] 修改初始化

---
 frontend/src/views/communication/index.vue |   73 +++++++++++++++++++++++++++++-------
 1 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/frontend/src/views/communication/index.vue b/frontend/src/views/communication/index.vue
index 1652a8c..63f99c8 100644
--- a/frontend/src/views/communication/index.vue
+++ b/frontend/src/views/communication/index.vue
@@ -1,14 +1,16 @@
 <script setup>
   import {ipc} from '@/utils/ipcRenderer'
-  import {ref} from "vue";
+  import {onBeforeUnmount, ref} from "vue";
+  import {useStore} from "@/stores/icrfStore";
+  const store = useStore();
   // 杩炴帴妯″紡
-  const mode = ref(2);
+  const mode = ref(store.mode);
   // 璁惧缂栧彿
-  const deviceId = ref(1);
+  const deviceId = ref(store.deviceId);
   // 涓插彛鍦板潃
-  const com = ref();
+  const com = ref(store.com);
   // 娉㈢壒鐜�
-  const serialBaud = ref(115200);
+  const serialBaud = ref(store.serialBaud);
   const serialBaudList = ref([
       9600,19200,38400,57600,115200
   ])
@@ -16,8 +18,8 @@
   ]);
   //com鍒楄〃
   const comList = ref([]);
-  const isLJ = ref(false)
-
+  const isLJ = ref(store.isLJ)
+  const icdev = ref();
 
   const initListPort = () =>{
     ipc.invoke('controller.port.initPort',1).then(res=>{
@@ -33,16 +35,56 @@
    * 杩炴帴璁惧
    */
   const setLocalICRF = () => {
-    ipc.invoke('controller.icrf.hc_init',{port:com.value,baud:serialBaud.value}).then(res=>{
-      console.log(res)
-    });
+    if(mode.value === 1){
+      ipc.invoke('controller.icrf.connectUsb',{number:deviceId.value});
+    }else{
+      let port = comList.value[com.value];
+      let portNum = port.path.slice(3);
+      ipc.invoke('controller.icrf.connectSerialPort',{port:(Number(portNum) -1),baud:serialBaud.value});
+    }
+
   }
   /**
    * 鏂紑璁惧
    */
   const disconnectLocalICRF =()=>{
+    ipc.invoke('controller.icrf.connectExit').then(res=>{
+      if (res.code === 0){
+        isLJ.value = false;
+        store.$reset();
+      }
+      data.value.unshift(res.msg);
+    });
 
   }
+
+  const resetLocal = ()=>{
+    ipc.invoke('controller.icrf.connectExit').then(res=>{
+      isLJ.value = false;
+      store.$reset();
+      data.value.unshift("閲嶇疆杩炴帴鎴愬姛");
+    });
+
+  }
+
+  ipc.on('controller.icrf.communication',(event,ret)=>{
+      if (Number(ret.handle) > 0){
+        icdev.value = Number(ret.handle)
+        isLJ.value = true;
+        store.$patch({
+          mode: mode.value,
+          deviceId: deviceId.value,
+          com: com.value,
+          serialBaud: serialBaud.value,
+          icdev: icdev.value,
+          isLJ: true,
+        })
+      }
+     data.value.unshift(ret.msg);
+  })
+  onBeforeUnmount(()=>{
+    ipc.removeAllListeners('controller.icrf.communication')
+  })
 
 
   initListPort();
@@ -54,18 +96,18 @@
       <div class="card-box">
         <div class="flex-1 " style="margin-right: 10px">
           <Section title="杩炴帴妯″紡">
-            <a-radio-group v-model:value="mode">
+            <a-radio-group v-model:value="mode" :disabled="isLJ">
               <a-radio :value="1">USB</a-radio>
               <a-radio :value="2">Serial Port</a-radio>
             </a-radio-group>
           </Section>
 
           <Section title="璁惧缂栧彿">
-            <a-input :disabled="mode !== 1"  v-model:value="deviceId" placeholder="璇疯緭鍏�" />
+            <a-input :disabled="mode !== 1 || isLJ"  v-model:value="deviceId" placeholder="璇疯緭鍏�" />
           </Section>
 
           <Section title="涓插彛鍙�">
-            <a-select :disabled="mode !== 2"
+            <a-select :disabled="mode !== 2 || isLJ"
                 ref="select"
                 v-model:value="com"
                 style="width: 100%;"
@@ -75,7 +117,7 @@
           </Section>
 
           <Section title="娉㈢壒鐜�">
-            <a-select :disabled="mode !== 2"
+            <a-select :disabled="mode !== 2 || isLJ"
                 ref="select"
                 v-model:value="serialBaud"
                 style="width: 100%;"
@@ -86,6 +128,7 @@
           <div style="margin-top: 20px;text-align: right;">
             <a-button style="margin-right: 20px;width: 150px" :disabled="isLJ" @click="setLocalICRF">杩炴帴璁惧</a-button>
             <a-button style="width: 150px" :disabled="!isLJ" @click="disconnectLocalICRF">鏂紑杩炴帴</a-button>
+            <a-button style="margin-left: 20px;width: 150px;margin-top: 10px" @click="resetLocal">閲嶇疆</a-button>
           </div>
         </div>
         <div class="flex-1 box-right">
@@ -127,6 +170,8 @@
     .aList{
       overflow: auto;
       height: 330px;
+      max-height: 100%;
+      min-height: 100%;
     }
   }
 }

--
Gitblit v1.8.0