You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.4 KiB
131 lines
3.4 KiB
//update
|
|
function updateById(list, item) {
|
|
return update(list, item, 'id');
|
|
}
|
|
|
|
function updateByNumber(list, item) {
|
|
return update(list, item, 'number');
|
|
}
|
|
|
|
function updateByKey(list, item) {
|
|
return update(list, item, 'key');
|
|
}
|
|
|
|
function update(list, item, key) {
|
|
key = key || 'number';
|
|
var result = false;
|
|
var to = Enumerable.from(list).where(function (o) { return o[key] === item[key]; }).firstOrDefault();
|
|
if (to) {
|
|
copy(item, to);
|
|
}
|
|
else {
|
|
list.push(item);
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
//delete
|
|
function remove(list, item,key) {
|
|
var result = false;
|
|
for (var i = 0; i < list.length; i++) {
|
|
if (list[i][key] === item[key]) {
|
|
list.splice(i, 1);
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
//util
|
|
function copy(from, to) {
|
|
for (var attr in to) {
|
|
if (from.hasOwnProperty(attr)) {
|
|
if (!(from[attr] instanceof Array)) {
|
|
to[attr] = from[attr];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function execApi(number, method, query) {
|
|
var loading = weui.loading('提交中...');
|
|
axios.post('/IoTCenter/api/v1/api/execApi', { connectionId,number,method, query })
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
})
|
|
.finally(function () {
|
|
loading.hide();
|
|
});
|
|
}
|
|
|
|
function execScene(id) {
|
|
var loading = weui.loading('提交中...');
|
|
axios.post('/IoTCenter/api/v1/api/execScene', '"' + id + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
})
|
|
.finally(function () {
|
|
loading.hide();
|
|
});
|
|
}
|
|
|
|
function nodePower(number, command) {
|
|
var loading = weui.loading('提交中...');
|
|
axios.post('/IoTCenter/api/v1/node/power'+command, '"' + number + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
})
|
|
.finally(function () {
|
|
loading.hide();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 格式化时间
|
|
* @param {*} value
|
|
*/
|
|
function formatDate(value){
|
|
var date = new Date(value);
|
|
var year = date.getFullYear();
|
|
var month = ("0" + (date.getMonth() + 1)).slice(-2);
|
|
var day = ("0" + date.getDate()).slice(-2);
|
|
var hours = ("0" + date.getHours()).slice(-2);
|
|
var minutes = ("0" + date.getMinutes()).slice(-2);
|
|
var seconds = ("0" + date.getSeconds()).slice(-2);
|
|
return year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds;
|
|
}
|
|
|
|
/**
|
|
* 消息图标
|
|
* @param {*} value
|
|
*/
|
|
function iconMessage(key,val){
|
|
var icon = 'info';
|
|
if(key == 'State'){
|
|
if(val == '开') icon = 'on';
|
|
if(val == '关' || val == '停') icon = 'off';
|
|
}else if(key == 'Warning'){
|
|
if(val == '正常') icon = 'infrared';
|
|
if(val == '警报') icon = 'warn';
|
|
}else{
|
|
icon = key;
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
/**
|
|
* 获取url参数
|
|
* @param {*} value
|
|
*/
|
|
function getUrlKey(name){
|
|
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
|
|
} |