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.
78 lines
1.8 KiB
78 lines
1.8 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;
|
|
}
|
|
console.log(result?'insert':'update'+' data by '+key);
|
|
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+'"')
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
})
|
|
.finally(function () {
|
|
loading.hide();
|
|
});
|
|
|
|
} |