-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.qml
260 lines (255 loc) · 8.73 KB
/
Server.qml
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import QtQuick 2.0
import QtQuick.Controls 2.12
import "com"
import "com/com.js" as Com
Popup {
id: root
property var delegate: null
width: 600
height: 400
x:(parent.width-width)/2
y:(parent.height-height)/2
modal: true
focus: true
background: Rectangle {color: "white"}
clip: true
ListModel {
id: model
}
Rectangle {
anchors.fill: parent
color: "transparent"
Column {
id: col
anchors.top: parent.top
anchors.left:parent.left
anchors.right: parent.right
spacing: dp(10)
Text {
text: $a.tr("Server")
width: parent.width
font.pointSize: sp(20)
font.weight: Font.Black
horizontalAlignment: Text.AlignHCenter
}
Rectangle {
width: parent.width
height: dp(10)
}
Row {
width: parent.width
spacing: dp(10)
MyRadioBtn {
id: btn_enserv
width: dp(150)
text: st ? $a.tr("Disable Server") : $a.tr("Enable Server")
anchors.verticalCenter: parent.verticalCenter
function click() {
if(st) {
$a.disableServer();
st = 0;
} else {
$a.enableServer();
st = 1;
}
}
function fkEntered() {
e_st.text = "开启本地服务器,连手机后可相互发送数据。";
}
function fkExited() {
e_st.text = "";
}
}
Btn {
text_size: sp(10)
text: "生成证书"
border.width: dp(1)
border.color: "#afafaf"
color: "transparent"
radius: height/2
text_color: "#595959"
width: dp(100)
height: btn_enserv.height
anchors.verticalCenter: parent.verticalCenter
function click() {
$a.genCert(1, 1);
}
function fkEntered() {
e_st.text = "若自动生成的丢失,可点此生成新的SSL证书。";
}
function fkExited() {
e_st.text = "";
}
}
Btn {
visible: btn_enserv.st === 1
text_size: sp(10)
text: $a.tr("Gen QR Code")
border.width: dp(1)
border.color: "#afafaf"
color: "transparent"
radius: height/2
text_color: "#595959"
width: dp(150)
height: btn_enserv.height
anchors.verticalCenter: parent.verticalCenter
function click() {
$a.genQRCode(Com.putFunc(function(r) {
qrimg.value = r;
}));
}
function fkEntered() {
e_st.text = "用手机扫码连接电脑";
}
function fkExited() {
e_st.text = "";
}
}
QRCode {
id: qrimg
visible: btn_enserv.st === 1 && qrimg.value !== ""
width: dp(50)
height: width
anchors.verticalCenter: parent.verticalCenter
value: ""
}
}
Rectangle {
width: parent.width
height: dp(30)
Column {
width: parent.width
height: parent.height
spacing: dp(2)
Rectangle {
width: parent.width
height: dp(1)
color: "#191919"
}
Row {
width: parent.width
height: parent.height - dp(2)
Text {
text: $a.tr("Device")
font.bold: true
font.pointSize: sp(14)
width: parent.width/10 * 5
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: $a.tr("Time")
font.bold: true
font.pointSize: sp(14)
width: parent.width/10 * 3
anchors.verticalCenter: parent.verticalCenter
}
Text {
width: parent.width/10 * 2
}
}
Rectangle {
width: parent.width
height: dp(1)
color: "#191919"
}
}
}
}
MyList {
id: list
model: model
Component {
id: delegate
Column {
width: list.width
height: dp(40)
spacing: dp(1)
Row {
width: parent.width
height: parent.height - dp(1)
Text {
id: devname
text: dev
color: "#595959"
font.pointSize: sp(10)
width: parent.width/10 * 5
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: Com.getTimeStr(Number(ct)/1000)
color: "#595959"
font.pointSize: sp(10)
width: parent.width/10 * 3
anchors.verticalCenter: parent.verticalCenter
}
Row {
width: parent.width/10 * 2
anchors.verticalCenter: parent.verticalCenter
Btn {
text_size: sp(10)
text: $a.tr("Del")
border.width: dp(1)
border.color: "#afafaf"
color: "transparent"
radius: height/2
text_color: "#595959"
width: dp(40)
height: dp(25)
function click() {
delDev(devname.text, index);
}
}
}
}
Rectangle {
width: parent.width
height: dp(1)
color: "#efefef"
}
}
}
delegate: delegate
anchors.top: col.bottom
anchors.topMargin: dp(10)
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
}
Text {
id: e_st
font.pointSize: sp(10)
color: "#595959"
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: dp(20)
text: ""
horizontalAlignment: Text.AlignHCenter
}
}
function op() {
open();
$a.getCurQRCode(Com.putFunc(function(r){
qrimg.value = r;
}));
model.clear();
$a.devices(Com.putFunc(function(r) {
if(r && r.length > 0) {
JSON.stringify(r);
model.append(r);
}
}));
}
function onPush(ty, d) {
if(d && d.length>1) {
model.append({dev:d[0], ct:d[1]});
}
}
function delDev(dev, i) {
$a.delDev(dev, Com.putFunc(function(r) {
if(r === 0) {
model.remove(i);
}
}));
}
}