From 256693287464e26e7b679a76792ef16b73353e98 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sun, 19 Jan 2020 18:04:39 +0800 Subject: [PATCH] update Former-commit-id: c73593544a54e8219fb851c490f02bdfa40c80de --- projects/WebApp/wwwroot/css/app.css | 21 +++++ projects/WebApp/wwwroot/index.html | 2 +- projects/WebApp/wwwroot/js/message.js | 49 +++++++---- projects/WebApp/wwwroot/js/store.js | 71 +++++++++------ projects/WebApp/wwwroot/js/util.js | 4 +- projects/WebApp/wwwroot/pages/iot/node.html | 93 +++++++++----------- projects/WebApp/wwwroot/pages/iot/nodes.html | 2 +- 7 files changed, 147 insertions(+), 95 deletions(-) diff --git a/projects/WebApp/wwwroot/css/app.css b/projects/WebApp/wwwroot/css/app.css index 97f0fb52..2af41935 100644 --- a/projects/WebApp/wwwroot/css/app.css +++ b/projects/WebApp/wwwroot/css/app.css @@ -720,6 +720,15 @@ ul { border-radius: unset; } /*bootstrap4+weui*/ +.row{ + margin-left:auto; + margin-right:auto; +} + +.col{ + padding-left:initial; + padding-right:initial; +} [class^="weui"]{ box-sizing:initial; } @@ -731,4 +740,16 @@ a:hover{ } label,h1{ margin-bottom:initial; +} +img{ + margin:auto; +} +.img.icon { + width: 48px; + height: 48px; +} +.img.button{ + width:48px; + height:48px; + cursor:pointer; } \ No newline at end of file diff --git a/projects/WebApp/wwwroot/index.html b/projects/WebApp/wwwroot/index.html index 44fb230c..cb267745 100644 --- a/projects/WebApp/wwwroot/index.html +++ b/projects/WebApp/wwwroot/index.html @@ -12,7 +12,7 @@ 首屏 -
+
diff --git a/projects/WebApp/wwwroot/js/message.js b/projects/WebApp/wwwroot/js/message.js index 57bbdf4a..a5bbdc18 100644 --- a/projects/WebApp/wwwroot/js/message.js +++ b/projects/WebApp/wwwroot/js/message.js @@ -14,22 +14,35 @@ connection.on('Connected', function (id) { connectionId = id; console.log('signalR 连接Id:' + connectionId); }); -connection.on("ServerToClient", function (method, json, to, from) { - console.log(method+' from:'+from+' to:'+to); - console.log(json); - var model = JSON.parse(json); - if (method === 'NodeEntityUpdated') { - store.commit('updateNode', model); - } - //else if (method === 'NodeEntityInserted') {} - //else if (method === 'NodeEntityDeleted') {} - else if (method === 'DeviceEntityInserted') { - store.commit('insertDevice', model); - } - else if (method === 'DeviceEntityUpdated') { - store.commit('updateDevice', model); - } - else if (method === 'DeviceEntityDeleted') { - store.commit('deleteDevice', model); - } +connection.on("ServerToClient", function (method, message, to, from) { + console.log(method); + console.log(message); + var event = method.substr(0, 1).toLowerCase() + method.substr(1); + var model = JSON.parse(message); + store.dispatch('update', {event,model,to,from}); + //store.commit('update', method,message,to,from); + //store.commit('update',method,message,to,from) + //if (method === 'NodeEntityUpdated') { + // store.commit('updateNode', model); + //} + ////else if (method === 'NodeEntityInserted') {} + ////else if (method === 'NodeEntityDeleted') {} + //else if (method === 'DeviceEntityInserted') { + // store.commit('insertDevice', model); + //} + //else if (method === 'DeviceEntityUpdated') { + // store.commit('updateDevice', model); + //} + //else if (method === 'DeviceEntityDeleted') { + // store.commit('deleteDevice', model); + //} + //else if (method === 'DataEntityInserted') { + // store.commit('insertData', model); + //} + //else if (method === 'DataEntityUpdated') { + // store.commit('updateData', model); + //} + //else if (method === 'DataEntityDeleted') { + // store.commit('deleteData', model); + //} }); \ No newline at end of file diff --git a/projects/WebApp/wwwroot/js/store.js b/projects/WebApp/wwwroot/js/store.js index 60ec2d07..267891b0 100644 --- a/projects/WebApp/wwwroot/js/store.js +++ b/projects/WebApp/wwwroot/js/store.js @@ -10,6 +10,11 @@ const store = new Vuex.Store({ node: null, device:null }, + actions: { + update(context,model) { + context.commit(model.event,model); + } + }, mutations: { setToken(state, data) { state.accessToken = data.accessToken; @@ -41,33 +46,49 @@ const store = new Vuex.Store({ setNode(state, model) { state.node = model; }, - updateNode(state, model) { - updateByNumber(state.nodes, model); - }, - insertDevice(state, model) { - updateByNumber(state.devices, model); - var node = Enumerable.from(state.nodes).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); - if (node) { - node.count += 1; + nodeEntityUpdated(state, data) { + var model = data.model; + if (state.nodes) { + updateByNumber(state.nodes, model); } - var product = Enumerable.from(state.products).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); - if (product) { - product.count += 1; + if (state.node) { + copy(data.model, state.node); } }, - updateDevice(state, model) { - updateByNumber(state.devices, model); - }, - deleteDevice(state, model) { - deleteByNumber(state.devices, model); - var node = Enumerable.from(state.nodes).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); - if (node) { - node.count -= 1; - } - var product = Enumerable.from(state.products).where(function (o) { return o.id === model.productId; }).firstOrDefault(); - if (product) { - product.count -= 1; - } - } + + //update(state,method,message,to,from) { + // alert(1); + //}, + //updateNode(state, model) { + // updateByNumber(state.nodes, model); + //}, + //insertDevice(state, model) { + // updateByNumber(state.devices, model); + // var node = Enumerable.from(state.nodes).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); + // if (node) { + // node.count += 1; + // } + // var product = Enumerable.from(state.products).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); + // if (product) { + // product.count += 1; + // } + //}, + //updateDevice(state, model) { + // updateByNumber(state.devices, model); + // if (device) { + // //update device + // } + //}, + //deleteDevice(state, model) { + // deleteByNumber(state.devices, model); + // var node = Enumerable.from(state.nodes).where(function (o) { return o.id === model.nodeId; }).firstOrDefault(); + // if (node) { + // node.count -= 1; + // } + // var product = Enumerable.from(state.products).where(function (o) { return o.id === model.productId; }).firstOrDefault(); + // if (product) { + // product.count -= 1; + // } + //} }, }) \ No newline at end of file diff --git a/projects/WebApp/wwwroot/js/util.js b/projects/WebApp/wwwroot/js/util.js index c9237b4c..82b3b084 100644 --- a/projects/WebApp/wwwroot/js/util.js +++ b/projects/WebApp/wwwroot/js/util.js @@ -1,7 +1,9 @@ function copy(from, to) { for (var attr in to) { if (from.hasOwnProperty(attr)) { - to[attr] = from[attr]; + if (!(from[attr] instanceof Array)) { + to[attr] = from[attr]; + } } } } diff --git a/projects/WebApp/wwwroot/pages/iot/node.html b/projects/WebApp/wwwroot/pages/iot/node.html index 0c0d9f38..6696c56e 100644 --- a/projects/WebApp/wwwroot/pages/iot/node.html +++ b/projects/WebApp/wwwroot/pages/iot/node.html @@ -6,7 +6,7 @@
-
+
场景
@@ -16,22 +16,22 @@
-
环境
+
环境
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
光照度: @@ -50,19 +50,19 @@
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
温度: @@ -93,19 +93,19 @@
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
状态: @@ -123,19 +123,19 @@
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
状态: @@ -154,22 +154,22 @@
-
用电
+
用电
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
@@ -181,19 +181,19 @@
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
@@ -208,19 +208,19 @@
-
-
+
+
{{device.displayName}}
-
-
+
+
-
+
@@ -231,19 +231,14 @@
-
-
-
- +
+
+
+ +
+

{{device.displayName}}

\ No newline at end of file diff --git a/projects/WebApp/wwwroot/pages/iot/nodes.html b/projects/WebApp/wwwroot/pages/iot/nodes.html index a73ef357..7a0f467e 100644 --- a/projects/WebApp/wwwroot/pages/iot/nodes.html +++ b/projects/WebApp/wwwroot/pages/iot/nodes.html @@ -6,7 +6,7 @@
- +