nvsencoders.js
8.22 KB
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
289
290
291
292
var layer = null;
var g_hasRenderEncodersTable = false;
///渲染查询结果表格
function reRenderEncodersTable(dataArray) {
var table = layui.table;
var configObject = {
elem: '#encodersTableData'
,skin: 'row ' //行边框风格
,size: 'bg' //小尺寸的表格
,data:dataArray
,title: '编码器设备表'
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar: ['filter', 'exports', 'print']
,id:"encodersTableDataId"
,text: {
none: '暂无相关数据' //默认:无数据。注:该属性为 layui 2.2.5 开始新增
}
,cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
,cols: [[
{type:'radio'}
,{field:'id', title:'ID',width:160,align:'center',sort: true}
,{field:'name', title:'名字',align:'left',sort: true}
,{field:'model', title:'型号',width:120,align:'center'}
,{field:'ip', title:'IP',width:120,align:'center'}
,{field:'port', title:'端口',width:80,align:'center'}
,{field:'username', title:'用户名',width:190,align:'center'}
,{field:'password', title:'密码',width:80,align:'center'}
,{field:'nums', title:'通道数',width:80,align:'center'}
,{field:'address', title:'别名ID',width:190,align:'center'}
,{field:'status', title:'状态',sort: true,width:80,align:'center'}
,{field:'desc2', title:'描述信息',width:190,align:'center'}
]]
,page: true
,done: function (res, curr, count) {
$('tr').css({'background-color': '#009688', 'color': '#fff'});//表头样式修改
var that = this.elem.next();
res.data.forEach(function (item, index) {
if (item.status === "离线") {
var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
tr.css({ 'color': 'red'});
}
});
}
};
if(g_hasRenderEncodersTable) {
table.reload('encodersTableDataId',{data:dataArray});
} else {
table.render(configObject);
g_hasRenderEncodersTable = true;
}
}
function handleEncoderArray(encoderList){
var dataArray = new Array();
for (var i = 0; i < encoderList.length; i++) {
var obj = encoderList[i];
var strstatus = "";
if(obj.status == "1") {
strstatus = "在线";
} else {
strstatus = "离线";
}
var item = {"id":obj.id,"name":obj.name,"model":obj.type,"ip":obj.ip,"port":obj.port,"username":obj.username,"password":obj.password,"nums":obj.channelnum,"address":obj.address,"status":strstatus,"desc2":obj.description};
dataArray.push(item);
}
reRenderEncodersTable(dataArray);
}
function getEncoderDeviceList(){
var xhr = $.ajax({
url: "/nvsthird/getencoderlist",
type: "post",
async: false,
dataType: "json",
contentType: "application/json",
data: JSON.stringify({
token: "",
fromindex:0,
toindex:-1
}),
timeout: 10000,
success: function(res) {
if (res.group != null){
var objToStr = JSON.stringify(res.group);
//console.log('tempData:'+objToStr);
setKeyValueToCache("getencoderlist", objToStr);
handleEncoderArray(res.group);
} else {
layer.msg('获取设备列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
layer.msg('获取设备列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
return false;
},
complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
if(status == 'timeout'){//超时,status还有success,error等值的情况
xhr.abort();
} else if(status == 'error') {
xhr.abort();
layer.msg('获取设备列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
}
}
});
}
function handleSetEncoderChannelNums(nvsurl){
var timeoutDefaultValue = 60 * 1000;
var xhr = $.ajax({
url: nvsurl,
type: "get",
async: true,
dataType: "json",
contentType: "application/json",
timeout: timeoutDefaultValue,
success: function(res) {
if(res.errormsg === "OK") {
layer.msg('设置成功',{icon: 1, title:'修改设备通道数',time: 2000,skin: 'layer-ext-moon' });
} else {
layer.msg('设置失败', {icon: 2, time: 2000,title:'修改设备通道数记',skin: 'layer-ext-moon' });
}
getEncoderDeviceList();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
layer.msg('设置超时:' + errorThrown, {icon: 2, title:'修改设备通道数',time: 2000,skin: 'layer-ext-moon' });
return false;
},
complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
if(status == 'timeout'){//超时,status还有success,error等值的情况
xhr.abort();
} else if(status == 'error') {
xhr.abort();
layer.msg('设置失败', {icon: 2, time: 2000,title:'修改设备通道数记',skin: 'layer-ext-moon' });
}
}
});
}
function doSetEncoderChannelNums(obj){
var data = obj.data;
if(isEmpty(data)) {
layer.msg('没有选择数据', {icon: 2, time: 2000,title:'修改设备通道数',skin: 'layer-ext-moon' });
return;
}
layer.prompt({
formType: 2
,title:"修改设备通道数"
,value: "" + data[0].nums
}, function(value, index){
if(value === data.nums){
layer.msg('没有修改通道数量', {icon: 2, time: 2000,title:'修改设备通道数',skin: 'layer-ext-moon' });
} else {
var urls = "/nvsthird/setEncoderChannels?id=" + data[0].id + "&nums=" + value;
handleSetEncoderChannelNums(urls);
}
layer.close(index);
});
}
function handleSyncCatalog(nvsurl){
var timeoutDefaultValue = 20 * 1000;
var xhr = $.ajax({
url: nvsurl,
type: "get",
async: true,
dataType: "json",
contentType: "application/json",
timeout: timeoutDefaultValue,
success: function(res) {
if(res.errormsg === "OK") {
layer.msg('同步成功',{icon: 1, title:'同步资源',time: 2000,skin: 'layer-ext-moon' });
} else {
layer.msg('同步失败', {icon: 2, time: 2000,title:'同步资源',skin: 'layer-ext-moon' });
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
layer.msg('同步超时:' + errorThrown, {icon: 2, title:'同步资源',time: 2000,skin: 'layer-ext-moon' });
return false;
},
complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
if(status == 'timeout'){//超时,status还有success,error等值的情况
xhr.abort();
} else if(status == 'error') {
xhr.abort();
layer.msg('同步失败', {icon: 2, time: 2000,title:'同步资源',skin: 'layer-ext-moon' });
}
}
});
}
function doSyncCatalogData(obj){
var data = obj.data;
if(isEmpty(data)) {
layer.msg('没有选择数据', {icon: 2, time: 2000,title:'同步资源',skin: 'layer-ext-moon' });
return;
}
layer.confirm('同步资源将要删除之前编码对应关系,确定要操作吗?', {
btn: ['确定','放弃']
,title:"提示"
}, function(){
var urls = "/nvsthird/SyncCatalog?id=" + data[0].id ;
handleSyncCatalog(urls);
}, function(){
}
);
}
$(function(){
///动态设置页面高度
var all_height = $(window).height();
var div_height = all_height - $("#headFrames").height() ;
$("#encoders_control").css("height",div_height+"px");
//console.log("div_height:" + div_height + " treebox_height:" +treebox_height + " all_height:"+all_height);
///弹窗初始化
layui.use('layer', function(){
layer = layui.layer;
});
///查询结果表格监听
layui.use('table', function(){
var table = layui.table;
reRenderEncodersTable([]);
//头工具栏事件
table.on('toolbar(encodersTableData)', function(obj){
var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
switch(obj.event){
case 'editChannels':
var data = checkStatus.data; //获取选中行数据
doSetEncoderChannelNums(checkStatus);
break;
case 'syncData':
var data = checkStatus.data; //获取选中行数据
doSyncCatalogData(checkStatus);
break;
};
});
});
///等待加载
setTimeout(function(){
getEncoderDeviceList();
},100);
});