Former-commit-id: 94bc6f28aa58a9d300b2fb4daa474437ec97976e
TangShanKaiPing
wanggang 6 years ago
parent ca9e059cf2
commit 0c88afb051

@ -9,9 +9,7 @@ using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace UserCenter.Controllers
@ -63,7 +61,7 @@ namespace UserCenter.Controllers
}
[HttpPost]
public ActionResult Exec([FromBody]ApiRequestModel model)
public ActionResult ExecApi([FromBody]ApiRequestModel model)
{
try
{
@ -77,6 +75,25 @@ namespace UserCenter.Controllers
}
}
[HttpPost]
public ActionResult ExecScene(Guid id)
{
try
{
var scene = this._sceneRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == id);
if (scene != null)
{
this._hub.ServerToClient(Methods.ExecSceneRequest, id, scene.Node.Number, null);
}
return Ok();
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
private void CallApi(string connectionId, string number, string method, string query)
{
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Number == number);

@ -68,7 +68,7 @@ router.beforeEach((to, from, next) => {
}
var route;
for (var i = 0; i < routeList.length; i++) {
if (routeList[i].path == to.path) {
if (routeList[i].path === to.path) {
route = routeList[i];
}
}
@ -80,7 +80,7 @@ router.beforeEach((to, from, next) => {
$.getScript(url, function () {
var route = {
path: to.path,
component: eval(method),
component: eval(method)
};
router.addRoutes([route]);
routeList.push(route);
@ -95,8 +95,8 @@ router.beforeEach((to, from, next) => {
router.afterEach((route, redirect) => {
Vue.nextTick(() => {
$('#loading').fadeOut(100);
})
})
});
});
///
const app = new Vue({
store: store,
@ -107,5 +107,5 @@ const app = new Vue({
console.log('mounted:app');
},
methods: {
},
}
}).$mount('#app');

@ -6,13 +6,16 @@ const store = new Vuex.Store({
user: null,
products: [],
nodes: [],
scenes: [],
timers: [],
tiggers: [],
product: null,
node: null,
device:null
device: null
},
actions: {
update(context,model) {
context.commit(model.event,model);
update(context, model) {
context.commit(model.event, model);
}
},
mutations: {
@ -60,19 +63,19 @@ const store = new Vuex.Store({
dataEntityUpdated(state, data) {
var model = data.model;
if (state.node) {
var device = Enumerable.from(state.node.devices).where(function (o) { return o.id === model.deviceId; }).firstOrDefault();
let device = Enumerable.from(state.node.devices).where(function (o) { return o.id === model.deviceId; }).firstOrDefault();
if (device) {
updateByKey(device.data, model);
}
}
if (state.product) {
var device = Enumerable.from(state.product.devices).where(function (o) { return o.id === model.deviceId; }).firstOrDefault();
let device = Enumerable.from(state.product.devices).where(function (o) { return o.id === model.deviceId; }).firstOrDefault();
if (device) {
updateByKey(device.data, model);
}
}
if (state.device) {
var device =state.device.number === model.number;
let device = state.device.number === model.number;
if (device) {
updateByKey(device.data, model);
}
@ -112,5 +115,5 @@ const store = new Vuex.Store({
// product.count -= 1;
// }
//}
},
})
}
});

@ -29,7 +29,7 @@ function update(list, item, key) {
function remove(list, item,key) {
var result = false;
for (var i = 0; i < list.length; i++) {
if (list[i][key] == item[key]) {
if (list[i][key] === item[key]) {
list.splice(i, 1);
result = true;
break;
@ -48,9 +48,9 @@ function copy(from, to) {
}
}
function callApi(number, method, query) {
function execApi(number, method, query) {
var loading = weui.loading('提交中...');
axios.post('/IoTCenter/api/v1/api/exec', { connectionId,number,method, query })
axios.post('/IoTCenter/api/v1/api/execApi', { connectionId,number,method, query })
.then(function (response) {
console.log(response);
})
@ -60,4 +60,19 @@ function callApi(number, method, query) {
.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();
});
}

@ -10,7 +10,7 @@
<div class="card">
<div class="card-header">场景</div>
<div class="card-body">
<button class="btn btn-success mr-4" v-for="scene in scenes" v-on:click="CallScene(scene.Id)">{{scene.name}}</button>
<button class="btn btn-success mr-4" v-for="scene in scenes" v-on:click="execScene(scene.id)">{{scene.name}}</button>
</div>
</div>
</div>
@ -171,9 +171,9 @@
</div>
<div class="col col-md-8 col-sm-8 align-self-center">
<div class="row" style="line-height:28px;">
<img style="height:32px;" v-on:click="callApi(device.number,'/Curtain/On')" src="/IoTCenter/images/left.png" />
<img style="height:32px;" v-on:click="callApi(device.number,'/Curtain/Stop')" src="/IoTCenter/images/stop.png" />
<img style="height:32px;" v-on:click="callApi(device.number,'/Curtain/Off')" src="/IoTCenter/images/right.png" />
<img style="height:32px;" v-on:click="exceApi(device.number,'/Curtain/On')" src="/IoTCenter/images/left.png" />
<img style="height:32px;" v-on:click="exceApi(device.number,'/Curtain/Stop')" src="/IoTCenter/images/stop.png" />
<img style="height:32px;" v-on:click="exceApi(device.number,'/Curtain/Off')" src="/IoTCenter/images/right.png" />
</div>
</div>
</div>
@ -195,12 +195,12 @@
</div>
<div class="col col-md-8 col-sm-8 align-self-center">
<div class="row" style="line-height:28px;">
<img v-if="getDataValue(device.number,'L1状态')=='开'" v-on:click="callApi(device.number,'/Switch3/L1Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L1状态')=='关'" v-on:click="callApi(device.number,'/Switch3/L1On')" src="/IoTCenter/images/off.png" />
<img v-if="getDataValue(device.number,'L2状态')=='开'" v-on:click="callApi(device.number,'/Switch3/L2Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L2状态')=='关'" v-on:click="callApi(device.number,'/Switch3/L2On')" src="/IoTCenter/images/off.png" />
<img v-if="getDataValue(device.number,'L3状态')=='开'" v-on:click="callApi(device.number,'/Switch3/L3Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L3状态')=='关'" v-on:click="callApi(device.number,'/Switch3/L3On')" src="/IoTCenter/images/off.png" />
<img v-if="getDataValue(device.number,'L1状态')=='开'" v-on:click="exceApi(device.number,'/Switch3/L1Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L1状态')=='关'" v-on:click="exceApi(device.number,'/Switch3/L1On')" src="/IoTCenter/images/off.png" />
<img v-if="getDataValue(device.number,'L2状态')=='开'" v-on:click="exceApi(device.number,'/Switch3/L2Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L2状态')=='关'" v-on:click="exceApi(device.number,'/Switch3/L2On')" src="/IoTCenter/images/off.png" />
<img v-if="getDataValue(device.number,'L3状态')=='开'" v-on:click="exceApi(device.number,'/Switch3/L3Off')" src="/IoTCenter/images/on.png" />
<img v-if="getDataValue(device.number,'L3状态')=='关'" v-on:click="exceApi(device.number,'/Switch3/L3On')" src="/IoTCenter/images/off.png" />
</div>
</div>
</div>
@ -222,8 +222,8 @@
</div>
<div class="col col-md-8 col-sm-8 align-self-center">
<div class="row" style="line-height:28px;">
<img v-if="getDataValue(device.number,'状态')==='开'" v-on:click="callApi(device.number,'/Socket/Off')" src="/IoTCenter/images/on.png" :data-status="getDataValue(device.number,'状态')" />
<img v-if="getDataValue(device.number,'状态')==='关'" v-on:click="callApi(device.number,'/Socket/On')" src="/IoTCenter/images/off.png" :data-status="getDataValue(device.number,'状态')" />
<img v-if="getDataValue(device.number,'状态')==='开'" v-on:click="exceApi(device.number,'/Socket/Off')" src="/IoTCenter/images/on.png" :data-status="getDataValue(device.number,'状态')" />
<img v-if="getDataValue(device.number,'状态')==='关'" v-on:click="exceApi(device.number,'/Socket/On')" src="/IoTCenter/images/off.png" :data-status="getDataValue(device.number,'状态')" />
</div>
</div>
</div>

@ -29,14 +29,14 @@
getDeviceDataAttr: function (number, name, attr) {
var device = Enumerable.from(this.node.devices).where(function (o) { return o.number === number; }).firstOrDefault();
var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
if (data != null) {
if (data !== null) {
return data[attr];
}
return null;
},
getDataValue: function (number, name) {
return this.getDeviceDataAttr(number, name, 'value');
},
}
},
computed: {
node: function () {
@ -45,9 +45,8 @@
scenes: function () {
return Enumerable.from(this.node.scenes).orderBy('o=>o.displayOrder');
}
},
})
}
});
});
});
}

@ -29,8 +29,8 @@
nodes: function () {
return store.state.nodes;
}
},
})
}
});
});
});
}

@ -29,8 +29,8 @@
products: function () {
return store.state.products;
}
},
})
}
});
});
});
}

@ -55,7 +55,7 @@
}, this.regexp);
}
}
})
});
});
});
}
Loading…
Cancel
Save