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.

75 lines
2.5 KiB

isDebug = true;
useSignalR = true;
dataUrl = iotCenter + '/App/GetDevice?number=' + new URI().search(true).number;
data = function data() {
return {
f7params: f7params,
server: localStorage.getItem('server'),
token: localStorage.getItem('token'),
model: null
};
}
loadDataSuccess = function () {
Vue.nextTick(function () {
UpdateCamera();
UpdateChart();
});
}
methods = {
HasChart() {
var o = this.model;
return o.Name === '温湿度传感器' || o.Name === 'PM2.5感应器' || o.Name === '光强检测器' || o.Name === '智能插座';
},
GetDatas() {
return Enumerable.from(this.model.Data).orderBy('o=>o.Key').toArray();
},
GetDevice(nameOrNumber) {
return this.model;
},
GetDataValueByKey(key) {
var data = Enumerable.from(this.model.Data)
.where(function (o) { return o.Key.toLowerCase() === key; })
.firstOrDefault();
if (data != null) {
return data.Value;
}
return null;
},
GetSimpleApis() {
return Enumerable.from(this.model.Product.Apis).where(function (o) { return o.Parameters.length === 1; }).orderBy(function (o) { return o.Name;}).toArray();
},
GetParameter(api,name) {
return Enumerable.from(api.Parameters).where(function (o) { return o.Name == name;}).firstOrDefault();
},
CallCommand(id) {
ajax('/App/ExecCommand', { token: token, connectionId: connectionId, id: id }, 'post');
},
CallApi(number, method, query) {
ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: number, method: method, query: query }, '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 = vm.model.Id == item.DeviceId ? vm.model : null;
if (device) {
updateItem(device.Data, item);
toastr.info(device.DisplayName + '更新');
if ($('canvas#' + device.Number).length) {
UpdateChart(device.Number);
}
}
}
}
start();