Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit a70b268

Browse files
committed
串口前端改进
1 parent 02a722c commit a70b268

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

WebPage/assets/js/serial.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
1-
var appSerialList = new Vue({
2-
el: '#serialport',
1+
var appSerial = new Vue({
2+
el: '#serial',
33
data :{
44
selected: '',
55
serialLists:[]
6-
}
7-
})
8-
axios.get('/serial')
9-
.then(function (response) {
10-
appSerialList.selected=response.data.Name
11-
})
12-
.catch(function (error) {
13-
console.log(error);
14-
})
15-
axios.get('/serial/list')
16-
.then(function (response) {
17-
appSerialList.serialLists=response.data.Ports
18-
})
19-
.catch(function (error) {
20-
console.log(error);
21-
})
22-
23-
var appSerialBtn = new Vue({
24-
el: '#serialbtn',
6+
},
257
methods: {
268
openserial: function(event){
279
axios.get('/serial/open', {
2810
params: {
29-
port: appSerialList.selected
11+
port: appSerial.selected
3012
}
3113
})
3214
.then(function (response) {
@@ -59,11 +41,26 @@ var appSerialBtn = new Vue({
5941
refreshserial: function(event){
6042
axios.get('/serial/list')
6143
.then(function (response) {
62-
appSerialList.serialLists=response.data.Ports
44+
appSerial.serialLists=response.data.Ports
6345
})
6446
.catch(function (error) {
6547
console.log(error);
6648
})
6749
}
6850
}
6951
})
52+
53+
axios.get('/serial')
54+
.then(function (response) {
55+
appSerial.selected=response.data.Name
56+
})
57+
.catch(function (error) {
58+
console.log(error);
59+
})
60+
axios.get('/serial/list')
61+
.then(function (response) {
62+
appSerial.serialLists=response.data.Ports
63+
})
64+
.catch(function (error) {
65+
console.log(error);
66+
})

WebPage/index.html

+11-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@
4242

4343
<div class="tab-content" id="nav-tabContent">
4444
<div class="tab-pane fade show active" id="nav-serialport" role="tabpanel" aria-labelledby="nav-home-tab">
45-
<p><div class="input-group mb-3">
46-
<div class="input-group-prepend">
47-
<label class="input-group-text">串口:</label>
48-
</div>
49-
<select id="serialport" class="custom-select" v-model="selected">
50-
<option v-for="serialList in serialLists" v-bind:value="serialList">{{serialList}}</option>
51-
</select>
52-
</div></p>
53-
<div id="serialbtn">
54-
<p><button class="btn btn-primary" v-on:click="refreshserial">刷新串口</button></p>
55-
<p><button class="btn btn-primary" v-on:click="openserial">打开串口</button></p>
56-
<p><button class="btn btn-danger" v-on:click="closeserial">关闭串口</button></p>
45+
<div id="serial">
46+
<p><div class="input-group mb-3">
47+
<div class="input-group-prepend">
48+
<label class="input-group-text" v-on:click="refreshserial">串口:</label>
49+
</div>
50+
<select id="serialport" class="custom-select" v-model="selected">
51+
<option v-for="serialList in serialLists" v-bind:value="serialList">{{serialList}}</option>
52+
</select>
53+
</div></p>
54+
<p><button class="btn btn-primary" v-on:click="openserial">打开串口</button>
55+
<button class="btn btn-danger" v-on:click="closeserial">关闭串口</button></p>
5756
</div>
5857
<div class="input-group" id="fileupload">
5958
<div class="input-group-prepend">

0 commit comments

Comments
 (0)