whychdw
2019-09-16 dfdab1aa564b1e9339a34a14fd7f882c68debc23
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
'use strict';
 
var CORS = 'http://192.168.7.120:8080/Device_Manage/'; // 开启跨域请求(调试时开启)
//const CORS='';           // 关闭跨域请求(发布时开启)
 
//定义计时器
function Interval() {
    this.timer = null;
    this.time = '';
    this.callback = '';
}
// 开启计时器并添加
Interval.prototype.start = function (callback, time) {
    // 先关闭计时器
    this.stop();
    // 配置执行函数
    if (typeof callback == 'function' && typeof time == 'number') {
        this.callback = callback;
        this.time = time;
        callback();
        this.timer = setInterval(callback, time);
    } else {
        console.warn('未完整配置参数!');
    }
};
// 开启计时器
Interval.prototype.open = function () {
    var callback = this.callback;
    var time = this.time;
    this.start(callback, time);
};
 
// 关闭计时器
Interval.prototype.stop = function () {
    clearInterval(this.timer);
};
 
// 延时计时器
function Timeout() {
    this.timer = null;
    this.time = '';
    this.callback = '';
}
// 开启计时器并添加
Timeout.prototype.start = function (callback, time, exe) {
    // 先关闭计时器
    this.stop();
    // 配置执行函数
    if (typeof callback == 'function' && typeof time == 'number') {
        this.callback = callback;
        this.time = time;
        if (exe != 'exe') {
            callback();
        }
        this.timer = setTimeout(callback, time);
    } else {
        console.warn('未完整配置参数!');
    }
};
// 开启计时器
Timeout.prototype.open = function () {
    var callback = this.callback;
    var time = this.time;
    this.start(callback, time, 'exe');
};
 
// 关闭计时器
Timeout.prototype.stop = function () {
    clearTimeout(this.timer);
};
 
/*从多维数组中获取最大值*/
function getMaxFromArr(arr) {
    var newArray = arr.join(",").split(",");
    return Math.max.apply({}, newArray);
}
 
/*从多维数组中获取最小值*/
function getMinFromArr(arr) {
    var newArray = arr.join(",").split(",");
    return Math.min.apply({}, newArray);
}
/*从多维数组中获取和*/
function getSumFromArr(arr) {
    var newArray = arr.join(",").split(",");
    var sum = 0;
    for (var i = 0; i < newArray.length; i++) {
        var _newArray = newArray[i];
        sum += Number(_newArray);
    }
    return sum;
}
/*从多维数组中获取平均值*/
function getAvgFromArr(arr) {
    var avg = 0;
    if (arr.length != 0) {
        var sum = getSumFromArr(arr);
        avg = sum / arr.length;
    }
    return avg;
}
 
function ajax(option) {
    // bui.ajax({
    //     method: 'POST',
    //     async: true,
    //     url: CORS+option.url,
    //     data: option.data,
    //     dataType: 'json',
    //     needNative: true,
    // }).then(function(res) {
    //     if(typeof(option.success) == 'function') {
    //         option.success(res);
    //     }
    //     if(typeof(option.complete) == 'function') {
    //         option.complete();
    //     }
    // },
    // function() {
    //     if(typeof(option.complete) == 'function') {
    //         option.complete();
    //     }
    // });
    $.ajax({
        type: 'post',
        async: true,
        url: CORS + option.url,
        data: option.data,
        dataType: 'json',
        success: option.success,
        error: option.error,
        complete: option.complete
    });
}
 
//将秒转化成时:分:秒
function formatSeconds(value) {
    if (value > 0) {} else {
        value = 0;
    }
    var theTime = parseInt(value); // 秒
    var theTime1 = 0; // 分
    var theTime2 = 0; // 小时
    // alert(theTime);
    if (theTime >= 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        //alert(theTime1+"-"+theTime);
        if (theTime1 >= 60) {
            theTime2 = parseInt(theTime1 / 60);
            theTime1 = parseInt(theTime1 % 60);
        }
    }
    var result = (theTime < 10 ? "0" : "") + parseInt(theTime);
    if (theTime1 >= 0) {
        result = (theTime1 < 10 ? "0" : "") + parseInt(theTime1) + ":" + result;
    }
    if (theTime2 >= 0) {
        result = (theTime2 < 10 ? "0" : "") + parseInt(theTime2) + ":" + result;
    }
    //console.info(result);
    return result;
}
 
// 设置后备时间(续航时间)
function sethoubeiTime(value) {
    value = Math.abs(value);
    var str = "";
    if (value > 0) {
        var hour = parseInt(value);
        var min = parseInt((parseFloat(value) - hour) * 60);
        if (hour < 10) {
            str = "0";
        }
        str += hour + "H";
        if (min < 10) {
            str += "0";
        }
        str += min + "M";
    } else {
        str = "00H00M";
    }
    return str;
}
 
// 格式化时间
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    };
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    }return format;
};
 
function Title() {
    this.min = 0; //最小值
    this.max = 0; //最大值
    this.avg = 0; //平均值
    this.sum = 0; //总和
    this.ahight = 0; //高告警阀值
    this.alow = 0; //低告警阀值
    this.clow = 0; //次低更换阀值
    this.lc = 0; //低告警单体数
    this.lp = 0; //低告警百分比
}
 
function createTitle() {
    var obj = new Object();
    obj.min = 0;
    obj.max = 0;
    obj.avg = 0;
    obj.sum = 0;
    obj.ahight = 0;
    obj.alow = 0;
    obj.clow = 0;
    obj.lc = 0;
    obj.lp = 0;
    return obj;
}
 
Title.prototype.setMin = function (min) {
    this.min = min;
};
 
Title.prototype.getMin = function () {
    return this.min;
};
 
Title.prototype.setMax = function (max) {
    this.max = max;
};
 
Title.prototype.getMax = function () {
    return this.max;
};
 
Title.prototype.setAvg = function (avg) {
    this.avg = avg;
};
 
Title.prototype.getAvg = function () {
    return this.avg;
};
 
Title.prototype.setSum = function (sum) {
    this.sum = sum;
};
 
Title.prototype.getSum = function () {
    return this.sum;
};
 
Title.prototype.setAhight = function (ahight) {
    this.ahight = ahight;
};
 
Title.prototype.getAhight = function () {
    return this.ahight;
};
 
Title.prototype.setAlow = function (alow) {
    this.alow = alow;
};
 
Title.prototype.getAlow = function () {
    return this.alow;
};
 
Title.prototype.setClow = function (clow) {
    this.clow = clow;
};
 
Title.prototype.getClow = function () {
    return this.clow;
};
 
Title.prototype.setLc = function (lc) {
    this.lc = lc;
};
 
Title.prototype.getLc = function () {
    return this.lc;
};
 
Title.prototype.setLp = function (lp) {
    this.lp = lp;
};
 
Title.prototype.getLp = function () {
    return lp;
};
 
Title.prototype.getAllTile = function (lname) {
    //alert(this.avg);
    var title = "";
    var maxText = '最大值'; //最大值
    var minText = '最小值'; //最小值
    var avgText = '平均值'; //平均值
    var lowText = '落后值'; //落后值
    var lcText = '落后数量'; //落后数量
    var lpText = '落后数量比'; //落后数量比
    if ("Voltage" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "V;" + minText + "=" + parseFloat(this.min).toFixed(3) + "V;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "V;累加和=" + parseFloat(this.sum).toFixed(3) + "V";
    } else if ("Resistance" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"mΩ;"+minText+"="+(parseFloat(this.min).toFixed(3))+"mΩ;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"mΩ;"+lowText+"="+this.alow+"mΩ;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "mΩ;" + minText + "=" + parseFloat(this.min).toFixed(3) + "mΩ;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "mΩ";
    } else if ("Temperature" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(1))+"℃;"+minText+"="+(parseFloat(this.min).toFixed(1))+"℃;"+avgText+"="+(parseFloat(this.avg).toFixed(1))+"℃;"+lowText+"="+this.alow+"℃;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(1) + "℃;" + minText + "=" + parseFloat(this.min).toFixed(1) + "℃;" + avgText + "=" + parseFloat(this.avg).toFixed(1) + "℃";
    } else if ("Conductance" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(0))+";"+minText+"="+(parseFloat(this.min).toFixed(0))+";"+avgText+"="+(parseFloat(this.avg).toFixed(0))+";"+lowText+"="+this.alow+";"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(0) + ";" + minText + "=" + parseFloat(this.min).toFixed(0) + ";" + avgText + "=" + parseFloat(this.avg).toFixed(0);
    } else if ("MonJHCurr" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "mA;" + minText + "=" + parseFloat(this.min).toFixed(3) + "mA;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "mA";
    } else if ("Serpercent" == lname || "Percent_total_capacity" == lname) {
        //title=maxText+"="+this.max+"%;"+minText+"="+this.min+"%;"+avgText+"="+this.avg+"%;"+lowText+"="+this.alow+"%;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + this.max + "%;" + minText + "=" + this.min + "%;" + avgText + "=" + this.avg + "%";
    } else if ("Actual_capacity" == lname || "Residual_capacity" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(0))+"AH;"+minText+"="+(parseFloat(this.min).toFixed(0))+"AH;"+avgText+"="+(parseFloat(this.avg).toFixed(0))+"AH;"+lowText+"="+this.alow+"AH;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(0) + "AH;" + minText + "=" + parseFloat(this.min).toFixed(0) + "AH;" + avgText + "=" + parseFloat(this.avg).toFixed(0) + "AH";
    }
    return title;
};
 
// 根据设备的id获取设备的基本信息
function getDevBaseInfo(dev_id) {
    var result = {
        name: '未知',
        key: '未知',
        reg: '',
        workstates: [],
        stopreasons: [],
        alarmstates: []
    };
    // 遍历DEVICEINFO
    for (var i = 0; i < DEVICEINFO.length; i++) {
        var data = DEVICEINFO[i];
        if (regEquipType(dev_id, data.reg)) {
            result = data;
        }
    }
    return result;
}
 
// 验证设备类型
function regEquipType(eId, pattern) {
    if (pattern.test(eId)) {
        return true;
    }
    return false;
}
 
function getBattstate(state) {
    var str = "";
    switch (state) {
        case 1:
            str = battstate[1];break;
        case 2:
            str = battstate[2];break;
        case 3:
            str = battstate[3];break;
        case 4:
            str = battstate[4];break;
        default:
            str = battstate[0];
    }
    return str;
}