-
Notifications
You must be signed in to change notification settings - Fork 9
/
view_ctrls.html
288 lines (268 loc) · 8.96 KB
/
view_ctrls.html
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vew_ctrls</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!--标准mui.css-->
<link rel="stylesheet" href="css/mui.min.css">
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
<style>
h5 {
margin: 5px 7px;
}
</style>
</head>
<body>
<!--<header class="mui-bar mui-bar-nav">
<h1 class="mui-title">控制器</h1>
</header>-->
<div class="mui-content" id="hublist"></div>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script>
mui.init({
swipeBack: false //启用右滑关闭功能
});
mui.plusReady(function() {
window.addEventListener('reload', function(event) {
reload();
});
})
function reload() {
var hublist = document.getElementById("hublist");
hublist.innerHTML = "";
app.ldhGetOrDel('/api/hubs/all', 'get', function(result) {
if(result.ok == 1) {
mui.each(result.data, function(index, hub) {
var nodes = "";
mui.each(hub.RNodes, function(index, nd) {
if(nd.Type == 1) {
nodes += createsw(nd, hub.Id);
} else if(nd.Type == 2) {
nodes += creategen(nd, hub.Id);
} else if(nd.Type == 3) {
nodes += createran(nd, hub.Id);
} else if(nd.Type == 4) {
nodes += createval(nd, hub.Id);
} else if(nd.Type == 5) {
nodes += creategps(nd, hub.Id);
} else if(nd.Type == 6) {
nodes += creategenvalue(nd, hub.Id);
} else if(nd.Type == 7) {
nodes += createimg(nd, hub.Id);
}
})
hublist.innerHTML += createcard(hub, nodes);
})
mui('.mui-input-row input').input();
mui(".mui-switch").switch();
mui.each(mui(".mui-switch"), function(i, ele) {
ele.removeEventListener('toggle', swput);
ele.addEventListener('toggle', swput);
})
} else {
plus.nativeUI.toast(result.err);
}
})
}
function goto_imgs(event) {
var alink;
if(event.target.tagName == "A") {
alink = event.target;
} else if(event.target.tagName == "P") {
alink = event.target.parentElement.parentElement;
} else {
alink = event.target.parentElement;
}
var page = plus.webview.getWebviewById('sub/imgs.html');
mui.fire(page, 'sethubid', {
'parentid': alink.id
})
plus.webview.show(page, "fade-in", 300);
plus.webview.currentWebview().hide()
}
function goto_vals(event) {
var hubnode = event.target.id;
var page = plus.webview.getWebviewById('sub/vals.html');
mui.fire(page, 'sethubid', {
'parentid': hubnode
})
plus.webview.show(page, "fade-in", 300);
plus.webview.currentWebview().hide()
}
function goto_gpss(event) {
var alink;
if(event.target.tagName == "A") {
alink = event.target;
} else if(event.target.tagName == "P") {
alink = event.target.parentElement.parentElement;
} else {
alink = event.target.parentElement;
}
var page = plus.webview.getWebviewById('sub/gpss.html');
mui.fire(page, 'sethubid', {
'parentid': alink.id
})
plus.webview.show(page, "fade-in", 300);
plus.webview.currentWebview().hide()
}
function goto_gens(event) {
var alink;
if(event.target.tagName == "A") {
alink = event.target;
} else if(event.target.tagName == "P") {
alink = event.target.parentElement.parentElement;
} else {
alink = event.target.parentElement;
}
var page = plus.webview.getWebviewById('sub/gens.html');
mui.fire(page, 'sethubid', {
'parentid': alink.id
})
plus.webview.show(page, "fade-in", 300);
plus.webview.currentWebview().hide()
}
function swput(event) {
var hubnode = event.target.id.split("_");
var Svalue;
if(event.detail.isActive) {
Svalue = JSON.stringify({
"Svalue": 1
});
} else {
Svalue = JSON.stringify({
"Svalue": 2
});
}
app.ldhPostOrPutForDps('/api/hub/' + hubnode[1] + '/node/' + hubnode[2] + '/datapoint', 'put', Svalue, function(result) {
if(result.ok != 1) {
plus.nativeUI.toast(result.err);
}
})
}
function genput(event) {
if(event.keyCode == 13) {
var hubnode = event.target.id.split("_");
var Gvalue = JSON.stringify({
"Gvalue": event.target.value
});
app.ldhPostOrPutForDps('/api/hub/' + hubnode[1] + '/node/' + hubnode[2] + '/datapoint', 'put', Gvalue, function(result) {
if(result.ok == 1) {
plus.nativeUI.toast("发送成功!");
} else {
plus.nativeUI.toast(result.err);
}
})
}
}
function ranput(event) {
var hubnode = event.target.id.split("_");
var Rvalue = JSON.stringify({
"Rvalue": parseInt(event.target.value, 10)
});
app.ldhPostOrPutForDps('/api/hub/' + hubnode[1] + '/node/' + hubnode[2] + '/datapoint', 'put', Rvalue, function(result) {
if(result.ok != 1) {
plus.nativeUI.toast(result.err);
}
})
}
function createcard(hub, nodehtml) {
var card = '<div class="mui-card">' +
'<div class="mui-card-header">' + hub.Title + '</div>' +
'<ul class="mui-table-view">' + nodehtml +
'</ul>' +
'<div class="mui-card-footer">' + hub.About + '</div>' +
'</div>';
return card;
}
function createval(node, hubid) {
var val = '<li class="mui-table-view-cell mui-media">' +
'<div class="mui-slider-left mui-disabled">' +
'<a class="mui-btn mui-btn-red mui-icon mui-icon-image"></a>' +
'<a class="mui-btn mui-btn-yellow mui-icon mui-icon-list" id="valval_' + hubid + '_' + node.Id + '" onclick="goto_vals(event)"></a>' +
'</div>' +
'<div class="mui-slider-handle">' +
'<a href="javascript:;" class="mui-navigate-right">' +
'<img class="mui-media-object mui-pull-left" src="images/val.png">' +
'<div class="mui-media-body">' + node.Title +
'<p class="mui-ellipsis">' + node.About + '</p>' +
'</div>' +
'</a>' +
'</div>' +
'</li>';
return val;
}
function creategps(node, hubid) {
var val = '<li class="mui-table-view-cell mui-media">' +
'<a href="javascript:;" id="gpsval_' + hubid + '_' + node.Id + '" onclick="goto_gpss(event)" class="mui-navigate-right">' +
'<img class="mui-media-object mui-pull-left" src="images/gps.png">' +
'<div class="mui-media-body">' + node.Title +
'<p class="mui-ellipsis">' + node.About + '</p>' +
'</div>' +
'</a>' +
'</li>';
return val;
}
function creategenvalue(node, hubid) {
var val = '<li class="mui-table-view-cell mui-media">' +
'<a href="javascript:;" id="genval_' + hubid + '_' + node.Id + '" onclick="goto_gens(event)" class="mui-navigate-right">' +
'<img class="mui-media-object mui-pull-left" src="images/gen.png">' +
'<div class="mui-media-body">' + node.Title +
'<p class="mui-ellipsis">' + node.About + '</p>' +
'</div>' +
'</a>' +
'</li>';
return val;
}
function createimg(node, hubid) {
var val = '<li class="mui-table-view-cell mui-media">' +
'<a href="javascript:;" id="imgval_' + hubid + '_' + node.Id + '" onclick="goto_imgs(event)" class="mui-navigate-right">' +
'<img class="mui-media-object mui-pull-left" src="images/img.png">' +
'<div class="mui-media-body">' + node.Title +
'<p class="mui-ellipsis">' + node.About + '</p>' +
'</div>' +
'</a>' +
'</li>';
return val;
}
function createsw(node, hubid) {
var sw = '<li class="mui-table-view-cell">' + '<span>' + node.Title + '</span>';
if(node.CtrlerVal == "1") {
sw += '<div id="sw_' + hubid + '_' + node.Id + '" class="mui-switch mui-active">';
} else {
sw += '<div id="sw_' + hubid + '_' + node.Id + '" class="mui-switch">';
}
sw += '<div class="mui-switch-handle"></div>' +
'</div>' +
'</li>';
return sw;
}
function creategen(node, hubid) {
var gen = '<li class="mui-table-view-cell">' +
'<div class="mui-input-row">' +
'<div>' + node.Title + '</div>' +
'<input id="geninput_' + hubid + '_' + node.Id + '" type="text" value="' + node.CtrlerVal +
'" onkeypress="genput(event)">' +
'</div>' +
'</li>';
return gen;
}
function createran(node, hubid) {
var vals = node.CtrlerVal.split(",");
var ran = '<li class="mui-table-view-cell">' +
'<div class="mui-input-row">' + node.Title + '</div>' +
'<div class="mui-input-row">' + node.About + '</div>' +
'<div class="mui-input-row">' + node.Tags + '</div>' +
'<div class="mui-input-row mui-button-row mui-input-range">' +
'<input id="raninput_' + hubid + '_' + node.Id + '" type="range" value="' + vals[0] + '" min="' + vals[1] + '" max="' + vals[2] + '" step="' + vals[3] +
'" onchange="ranput(event)">' +
'</div>' +
'</li>';
return ran;
}
</script>
</body>
</html>