zhaochongyi
2024-08-26 e0301d12be2ba6c04613f23c24734c48a30caad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<script setup>
  import {ipc} from '@/utils/ipcRenderer'
  import {ref} from "vue";
  // 连接模式
  const mode = ref(2);
  // 设备编号
  const deviceId = ref(1);
  // 串口地址
  const com = ref();
  // 波特率
  const serialBaud = ref(115200);
  const serialBaudList = ref([
      9600,19200,38400,57600,115200
  ])
  const data = ref( [
  ]);
  //com列表
  const comList = ref([]);
  const isLJ = ref(false)
 
 
  const initListPort = () =>{
    ipc.invoke('controller.port.initPort',1).then(res=>{
      console.log(res)
      comList.value = res;
 
      if (comList.value.length > 0){
        com.value = 0;
      }
    })
  }
  /**
   * 连接设备
   */
  const setLocalICRF = () => {
    ipc.invoke('controller.icrf.hc_init',{port:com.value,baud:serialBaud.value}).then(res=>{
      console.log(res)
    });
  }
  /**
   * 断开设备
   */
  const disconnectLocalICRF =()=>{
 
  }
 
 
  initListPort();
</script>
 
<template>
  <div class="app-container">
    <a-card >
      <div class="card-box">
        <div class="flex-1 " style="margin-right: 10px">
          <Section title="连接模式">
            <a-radio-group v-model:value="mode">
              <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="请输入" />
          </Section>
 
          <Section title="串口号">
            <a-select :disabled="mode !== 2"
                ref="select"
                v-model:value="com"
                style="width: 100%;"
            >
              <a-select-option :value="index" v-for="(item,index) in comList">{{ item.path }}</a-select-option>
            </a-select>
          </Section>
 
          <Section title="波特率">
            <a-select :disabled="mode !== 2"
                ref="select"
                v-model:value="serialBaud"
                style="width: 100%;"
            >
              <a-select-option :value="item" v-for="(item,index) in serialBaudList" :key="index">{{ item }}</a-select-option>
            </a-select>
          </Section>
          <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>
          </div>
        </div>
        <div class="flex-1 box-right">
          <div class="box-right-body">
            <a-list bordered :data-source="data" :locale="{emptyText: ' '}" class="aList">
              <template #renderItem="{ item }">
                <a-list-item>{{ item }}</a-list-item>
              </template>
            </a-list>
          </div>
        </div>
      </div>
 
 
    </a-card>
  </div>
</template>
 
<style scoped lang="less">
.card-box{
  display: flex;
  justify-content: space-between;
}
.flex-1{
  flex:1
}
.box-right{
  border-left: 1px dashed #e9e9e9;
 
  .box-right-body{
    margin-left: 10px;
    border-radius: 10px;
    background: #fafafa;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 10px;
    font-size: 14px;
    .aList{
      overflow: auto;
      height: 330px;
    }
  }
}
</style>