|
|
|
@ -40,22 +40,22 @@
|
|
|
|
|
<div class="col-md-2">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">一键开</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allpoweron">一键开</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">一键关</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allpoweroff">一键关</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">开关开</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allswitchon">开关开</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">开关关</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allswitchoff">开关关</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">插座开</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allsocketon">插座开</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-1">
|
|
|
|
|
<button class="btn btn-block btn-primary">插座关</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax allsocketoff">插座关</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
@ -66,7 +66,7 @@
|
|
|
|
|
<div class="box-header">
|
|
|
|
|
<h3 class="box-title">{{node.Name}}</h3>
|
|
|
|
|
<div class="pull-right box-tools">
|
|
|
|
|
<label class="switch on"><input class="switch" type="checkbox" checked /></label>
|
|
|
|
|
<label class="switch on"><input :data-node-number="node.Number" class="switch" type="checkbox" checked /></label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="box-body">
|
|
|
|
@ -75,17 +75,17 @@
|
|
|
|
|
<div class="box-footer">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-md-6">
|
|
|
|
|
<button class="btn btn-block btn-primary">一键开</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax nodepoweron">一键开</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-6">
|
|
|
|
|
<button class="btn btn-block btn-primary">一键关</button>
|
|
|
|
|
<button class="btn btn-block btn-primary ajax nodepoweroff">一键关</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr />
|
|
|
|
|
<div class="row" v-if="node.Scenes.length">
|
|
|
|
|
<template v-for="scene in node.Scenes">
|
|
|
|
|
<div class="col-md-3" v-if="scene.Tag=='home'">
|
|
|
|
|
<button class="btn btn-block btn-info">{{scene.Name}}</button>
|
|
|
|
|
<button class="btn btn-block btn-info ajax" :data-node-number="node.Number" :data-scene-name="scene.Name">{{scene.Name}}</button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
@ -93,6 +93,33 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<script>
|
|
|
|
|
var connection;
|
|
|
|
|
var connectionId;
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
|
cache: false,
|
|
|
|
|
timeout: 5000
|
|
|
|
|
});
|
|
|
|
|
function connect() {
|
|
|
|
|
if (connection && connection.connection.connectionState === 1) {
|
|
|
|
|
console.log('has connected');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log('start connect to server:' + Date());
|
|
|
|
|
connection.start().then(function () {
|
|
|
|
|
console.log('signalR>start');
|
|
|
|
|
}).catch(function (err) {
|
|
|
|
|
console.error(err.toString());
|
|
|
|
|
setTimeout(connect, 10 * 1000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function onMessage() {
|
|
|
|
|
connection.on('Connected', function (id) {
|
|
|
|
|
connectionId = id;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
function UpdateChart(id, title, data, labels, colors, type) {
|
|
|
|
|
var ctx = document.getElementById(id).getContext('2d');
|
|
|
|
@ -131,6 +158,38 @@
|
|
|
|
|
var color = '#' + r.toString(16) + g.toString(16) + b.toString(16);
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
function ajax(url, data, type) {
|
|
|
|
|
console.log(url);
|
|
|
|
|
type = type || 'get';
|
|
|
|
|
$('.overlay').show();
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: type,
|
|
|
|
|
url: url,
|
|
|
|
|
data: data,
|
|
|
|
|
success: AjaxCallBack
|
|
|
|
|
}).fail(function (result) {
|
|
|
|
|
console.log('error');
|
|
|
|
|
console.log(result);
|
|
|
|
|
}).always(function () {
|
|
|
|
|
$('.overlay').hide();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function AjaxCallBack(response) {
|
|
|
|
|
var result = response;
|
|
|
|
|
if (result.code === 0) {
|
|
|
|
|
if (result.type === 0) {
|
|
|
|
|
if (result.format === 1) {
|
|
|
|
|
console.log('format/1/base64 jpeg image');
|
|
|
|
|
$('#callback .page-content').html('<img class="shot" src="' + result.data + '">');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log('format/0/json object');
|
|
|
|
|
$('#callback .page-content').html(result.data);
|
|
|
|
|
}
|
|
|
|
|
app.popup.open('#callback');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$('body').on('change', 'input.switch', function (e) {
|
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
|
$(this).parent('label').addClass('on');
|
|
|
|
@ -140,6 +199,16 @@
|
|
|
|
|
$(this).parent('label').removeClass('on');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('body').on('click', 'button.ajax', function (e) {
|
|
|
|
|
var data = $.map($('.switch:checked').toArray(), function (o) { return $(o).attr('data-node-number'); });
|
|
|
|
|
if ($(this).hasClass('allpoweron')) {
|
|
|
|
|
ajax('/App/AllPowerOn', { nodes: data }, 'post');
|
|
|
|
|
} else if ($(this).hasClass('allpoweroff')) {
|
|
|
|
|
ajax('/App/AllPowerOff', { nodes: data }, 'post');
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
var vm = new Vue({
|
|
|
|
@ -156,6 +225,10 @@
|
|
|
|
|
UpdateChart('DeviceChart', '设备', vm.ViewModel.DeviceChart.data, vm.ViewModel.DeviceChart.labels, null, 'doughnut');
|
|
|
|
|
UpdateChart('EnergyChart', '用电', vm.ViewModel.EnergyChart.data, vm.ViewModel.EnergyChart.labels, null, 'bar');
|
|
|
|
|
});
|
|
|
|
|
var wsUrl = '/hub?group=page';
|
|
|
|
|
connection = new signalR.HubConnectionBuilder().withUrl(wsUrl).build();
|
|
|
|
|
onMessage();
|
|
|
|
|
connect();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|