-
Notifications
You must be signed in to change notification settings - Fork 9
/
node_mg.html
188 lines (177 loc) · 6.16 KB
/
node_mg.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>node_mg</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">
</head>
<body>
<div class="mui-content" id="ViewModel" data-bind="foreach: { data: nodes, as: 'node' }">
<!-- ko -->
<div class="mui-card">
<div class="mui-card-header" data-bind="text:node.Title"></div>
<div class="mui-card-content">
<div class="mui-card-content-inner">
<ul class="mui-table-view">
<li class="mui-table-view-cell">
<a>枢纽ID<span class="mui-pull-right" data-bind="text:node.HubId"></span></a>
</li>
<li class="mui-table-view-cell">
<a>节点ID<span class="mui-pull-right" data-bind="text:node.Id"></span></a>
</li>
<li class="mui-table-view-cell">
<a>标签<span class="mui-pull-right" data-bind="text:node.Tags"></span></a>
</li>
<li class="mui-table-view-cell">
<a>描述<span class="mui-pull-right" data-bind="text:node.About"></span></a>
</li>
<!-- ko if: node.Type === 1 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">控制器-开关</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 2 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">控制器-自定义型</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 3 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">控制器-约束型</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 4 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">传感器-数值型</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 5 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">传感器-GPS</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 6 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">传感器-自定义型</span></a>
</li>
<!-- /ko -->
<!-- ko if: node.Type === 7 -->
<li class="mui-table-view-cell">
<a>节点类型<span class="mui-pull-right">传感器-图片</span></a>
</li>
<!-- /ko -->
</ul>
<div class="mui-button-row">
<button type="button" class="mui-btn mui-btn-primary" onclick="return false;" data-bind="click: $root.nodeedit">修改</button>
<button type="button" class="mui-btn mui-btn-danger" onclick="return false;" data-bind="click: $root.nodedel">删除</button>
</div>
</div>
</div>
<div class="mui-card-footer">
<!--<a class="mui-card-link" href="#" data-bind="text:node.HubId"></a>-->
<a class="mui-card-link" href="#" data-bind="click: $root.hub_mg">取消</a>
</div>
</div>
<!-- /ko -->
</div>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script src="js/knockout-3.3.0.js"></script>
<script type="text/javascript">
mui.init();
mui.plusReady(function() {
var hubid;
window.addEventListener('sethubid', function(event) {
var obj = JSON.parse(event.detail.hub);
hubid = obj.Id;
dvvm.load();
});
window.addEventListener('reload', function(event) {
dvvm.load();
});
// window.addEventListener('show', function(event) {
// //注册返回事件
// mui.oldBack = mui.back;
// mui.back = function(event) {
// var hubmg = plus.webview.getWebviewById('hub_mg.html');
// plus.webview.show(hubmg, "fade-in", 300);
// mui.back = mui.oldBack;
// };
// })
function vm() {
var self = this;
self.hub_mg = function() {
var hubmg = plus.webview.getWebviewById('hub_mg.html');
plus.webview.show(hubmg, "fade-in", 300);
}
self.nodeedit = function(obj) {
var nodeedit = plus.webview.getWebviewById('node_edit.html');
mui.fire(nodeedit, 'sethubid', {
'nodeobj': JSON.stringify(obj)
})
plus.webview.show(nodeedit, "fade-in", 300);
}
self.nodedel = function(obj) {
var btnArray = ['否', '是'];
mui.confirm('删除节点,确认?', '酷痞物联', btnArray, function(e) {
if(e.index == 1) {
var state = app.getState();
mui.ajax(localStorage.getItem('$svc') + '/api/hub/' + hubid + '/node/' + obj.Id, {
dataType: 'json',
type: 'delete',
headers: {
'Content-Type': 'application/json',
"Authorization": state.token
},
success: function(data) {
if(data.ok == 1) {
self.load();
} else {
plus.nativeUI.toast(data.err);
var hubmg = plus.webview.getWebviewById('hub_mg.html');
plus.webview.show(hubmg, "fade-in", 300);
}
},
error: function(xhr, type, errorThrown) {
plus.nativeUI.toast(Error(xhr.responseText));
}
});
}
})
}
self.nodes = ko.observableArray();
self.load = function() {
var state = app.getState();
mui.ajax(localStorage.getItem('$svc') + '/api/hub/' + hubid + '/nodes', {
dataType: 'json',
type: 'get',
headers: {
'Content-Type': 'application/json',
"Authorization": state.token
},
success: function(data) {
if(data.ok == 1) {
self.nodes.removeAll()
self.nodes(data.data)
} else {
var hubmg = plus.webview.getWebviewById('hub_mg.html');
plus.webview.show(hubmg, "fade-in", 300);
plus.nativeUI.toast("此枢纽没发现节点")
}
},
error: function(xhr, type, errorThrown) {
plus.nativeUI.toast(Error(xhr.responseText));
}
});
}
}
var dvvm = new vm();
ko.applyBindings(dvvm, document.getElementById("ViewModel"));
})
</script>
</body>
</html>