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.

93 lines
3.1 KiB

isDebug = true;
useSignalR = true;
dataUrl = iotCenter + '/App/GetProduct?number=' + new URI().search(true).number;
data = function data() {
return {
f7params: f7params,
server: localStorage.getItem('server'),
token: localStorage.getItem('token'),
model: null
};
}
methods = {
HasBatchCommand() {
return this.model.Name === '调色灯'
|| this.model.Name.indexOf('窗帘电机') >= 0
|| this.model.Name.indexOf('开关') >= 0
|| this.model.Name.indexOf('插座') >= 0;
},
GetDevices() {
return Enumerable.from(this.model.Devices).orderBy('o=>o.DisplayOrder').orderBy('o=>o.Name').toArray();
},
GetDataValue(number, name) {
var device = Enumerable.from(this.model.Devices)
.where(function (o) { return o.Number === number; })
.firstOrDefault();
if (device != null) {
var data = Enumerable.from(device.Data)
.where(function (o) { return o.Name == name })
.firstOrDefault();
if (data != null) {
return data.Value;
}
}
return null;
},
SelectDevice(e) {
var checkbox = $(e.target);
if (checkbox.hasClass('checkall')) {
if (e.target.checked) {
$('input.item').not(':checked').prop("checked", true);
}
else {
$('input.item').filter(':checked').prop("checked", false);
}
}
else if (checkbox.hasClass('uncheck')) {
$('input.item').each(function () {
$(this).prop("checked", !$(this).prop("checked")).change();
});
}
var parent = $('input.checkall');
if ($('input.item').not(':checked').length === 0) {
parent.prop("indeterminate", false);
parent.prop("checked", true);
}
else if ($('input.item').filter(':checked').length === 0) {
parent.prop("indeterminate", false);
parent.prop("checked", false);
}
else {
parent.prop("indeterminate", true);
}
},
CallApiAll(method) {
var numbers = [];
$('.item:checked').each(function () {
numbers.push($(this).val());
});
ajax('/App/ExecApiAll', { token: token, connectionId: connectionId, method: vm.model.Path + method, numbers: numbers }, 'post');
}
};
function onMessage(method, json, to, from) {
debug(method + ':' + json);
var item = JSON.parse(json);
console.log(method + ':' + json);
var item = JSON.parse(json);
if (method == 'DeviceEntityInserted' ||
method == 'DeviceEntityUpdated' ||
method == 'DeviceEntityDeleted') {
loadData();
}
else if (method == 'DataEntityInserted' ||
method == 'DataEntityUpdated' ||
method == 'DataEntityDeleted') {
var device = Enumerable.from(vm.model.Devices).firstOrDefault(function (o) { return o.Id === item.DeviceId; })
if (device) {
updateItem(device.Data, item);
toastr.info(device.DisplayName + '更新');
}
}
}
start();