|
|
|
@ -21,6 +21,8 @@ var volume = 0.5;
|
|
|
|
|
if (isApp) {
|
|
|
|
|
Framework7.use(Framework7Vue);
|
|
|
|
|
}
|
|
|
|
|
toastr.options.timeOut = 500;
|
|
|
|
|
toastr.options.positionClass = "toast-top-center";
|
|
|
|
|
/*fun*/
|
|
|
|
|
function alert(message,title) {
|
|
|
|
|
if (isApp) {
|
|
|
|
@ -31,13 +33,9 @@ function alert(message,title) {
|
|
|
|
|
alert(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function hideLoading() {
|
|
|
|
|
if (isApp) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$('.overlay').hide();
|
|
|
|
|
}
|
|
|
|
|
function hideLoading(message) {
|
|
|
|
|
toastr.success(message||'请求成功');
|
|
|
|
|
$('.overlay').hide();
|
|
|
|
|
}
|
|
|
|
|
function loadData() {
|
|
|
|
|
var formData = new FormData();
|
|
|
|
@ -57,7 +55,7 @@ function loadData() {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
alert(error)
|
|
|
|
|
toastr.error('数据加载失败!');
|
|
|
|
|
})
|
|
|
|
|
.then(hideLoading);
|
|
|
|
|
}
|
|
|
|
@ -183,7 +181,7 @@ function ajax(url, data, type) {
|
|
|
|
|
data: data,
|
|
|
|
|
success: AjaxCallBack
|
|
|
|
|
}).fail(function (result) {
|
|
|
|
|
console.log('error');
|
|
|
|
|
toastr.error('请求发送失败!');
|
|
|
|
|
console.log(result);
|
|
|
|
|
}).always(function () {
|
|
|
|
|
$('.overlay').hide();
|
|
|
|
@ -255,19 +253,17 @@ function connect() {
|
|
|
|
|
}
|
|
|
|
|
if (connection.state === signalR.HubConnectionState.Disconnected) {
|
|
|
|
|
connection.start().then(function () {
|
|
|
|
|
|
|
|
|
|
toastr.success('客户端与服务器连接成功!');
|
|
|
|
|
}).catch(function (err) {
|
|
|
|
|
console.error(err.toString());
|
|
|
|
|
toastr.error('客户端与服务器连接失败!');
|
|
|
|
|
setTimeout(connect, 15 * 1000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
connection.on('Connected', function (id) {
|
|
|
|
|
connectionId = id;
|
|
|
|
|
console.log(connectionId);
|
|
|
|
|
});
|
|
|
|
|
connection.onclose(function (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
setTimeout(connect, 15 * 1000);
|
|
|
|
|
});
|
|
|
|
|
connection.on("ServerToClient", function (method, json, to,from) {
|
|
|
|
@ -276,23 +272,32 @@ connection.on("ServerToClient", function (method, json, to,from) {
|
|
|
|
|
});
|
|
|
|
|
function onMessage(method, json,to, from) {
|
|
|
|
|
var item = JSON.parse(json);
|
|
|
|
|
if (method === 'ApiCallback') {
|
|
|
|
|
if (method === 'ExecApiRsponse') {
|
|
|
|
|
console.log(json);
|
|
|
|
|
toastr.success('操作调用成功');
|
|
|
|
|
}
|
|
|
|
|
else if
|
|
|
|
|
(method == 'DataEntityInserted' || method == 'DataEntityUpdated') {
|
|
|
|
|
var device = Enumerable.from(vm.model.Devices).firstOrDefault(function (o) { return o.Id === item.DeviceId; })
|
|
|
|
|
if (device) {
|
|
|
|
|
updateItem(device.Data, item);
|
|
|
|
|
}
|
|
|
|
|
else if (method === 'ExecSceneRsponse') {
|
|
|
|
|
console.log(json);
|
|
|
|
|
toastr.success('场景调用成功');
|
|
|
|
|
}
|
|
|
|
|
else if (method == 'SceneEntityInserted' ||method == 'SceneEntityUpdated') {
|
|
|
|
|
updateItem(vm.model.Scenes, item);
|
|
|
|
|
else {
|
|
|
|
|
if(method == 'DataEntityInserted' || method == 'DataEntityUpdated') {
|
|
|
|
|
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+'更新');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (method == 'SceneEntityInserted' || method == 'SceneEntityUpdated') {
|
|
|
|
|
updateItem(vm.model.Scenes, item);
|
|
|
|
|
toastr.info(item.Name+'更新');
|
|
|
|
|
}
|
|
|
|
|
else if (method == 'SceneEntityDeleted') {
|
|
|
|
|
deleteItem(vm.model.Scenes, item);
|
|
|
|
|
toastr.info(item.Name+'删除');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (method == 'SceneEntityDeleted') {
|
|
|
|
|
deleteItem(vm.model.Scenes, item);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*vue*/
|
|
|
|
|
function init() {
|
|
|
|
@ -373,6 +378,9 @@ function init() {
|
|
|
|
|
CallApi(number, method, query) {
|
|
|
|
|
ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: number, method: method, query: query }, 'post');
|
|
|
|
|
},
|
|
|
|
|
GetScenes() {
|
|
|
|
|
return Enumerable.from(this.model.Scenes).orderBy('o=>o.DisplayOrder').toArray();
|
|
|
|
|
},
|
|
|
|
|
CallScene(id) {
|
|
|
|
|
ajax('/App/ExecScene', { token: token, connectionId: connectionId, id: id }, 'post');
|
|
|
|
|
},
|
|
|
|
|