diff --git a/projects/Infrastructure/Application/PagedList.cs b/projects/Infrastructure/Application/PagedList.cs index 4f66be67..537c502e 100644 --- a/projects/Infrastructure/Application/PagedList.cs +++ b/projects/Infrastructure/Application/PagedList.cs @@ -6,15 +6,15 @@ namespace Infrastructure.Application { public class PagedList : IPagedList, IValidatableObject { - [ScaffoldColumn(false)] - public int DefaultPageSize { get; set; } = 20; - public PagedList() { PageIndex = 1; PageSize = this.DefaultPageSize; } + [ScaffoldColumn(false)] + public int DefaultPageSize { get; set; } = 20; + [ScaffoldColumn(false)] public int PageIndex { get; set; } diff --git a/projects/Infrastructure/Application/PagedListModel.cs b/projects/Infrastructure/Application/PagedListModel.cs index cd9f4aed..0943eb1c 100644 --- a/projects/Infrastructure/Application/PagedListModel.cs +++ b/projects/Infrastructure/Application/PagedListModel.cs @@ -1,6 +1,18 @@ +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using System; + namespace Infrastructure.Application { public class PagedListModel : PagedList { + public PagedListModel() + { + this.Query = (T)Activator.CreateInstance(typeof(T)); + } + + public T Query { get; set; } + + public object Schema { get; set; } + public ViewDataDictionary ViewData { get; set; } } } \ No newline at end of file diff --git a/projects/Infrastructure/Web/Mvc/CrudController.cs b/projects/Infrastructure/Web/Mvc/CrudController.cs index 390d563e..046dd47c 100644 --- a/projects/Infrastructure/Web/Mvc/CrudController.cs +++ b/projects/Infrastructure/Web/Mvc/CrudController.cs @@ -56,7 +56,13 @@ namespace Infrastructure.Web.Mvc .ToList()); ViewData["EntityTypeExt"] = typeof(TEntity); ViewData["ModelTypeExt"] = typeof(TDisplayModel); - return this.Result(model); + if (this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase)) + { + model.ViewData = ViewData; + model.Schema = this.GetSchema(); + return Json(model, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + } + return View(model); } [HttpGet] @@ -287,17 +293,16 @@ namespace Infrastructure.Web.Mvc [ApiExplorerSettings(IgnoreApi = true)] private IActionResult Result(object model) { - return this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase) ? Json(model) as IActionResult : View(model); - } - - public IActionResult GetSearchSchema() - { - return Json(this.GetJsonSchema()); + if (this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase)) + { + return Json(model); + } + return View(model); } - public IActionResult GetEditSchema() + public object GetSchema() { - return Json(this.GetJsonSchema(), new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + return this.GetJsonSchema(); } } } \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/components/device/camera.html b/projects/WebMVC/wwwroot/components/iot/camera.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/camera.html rename to projects/WebMVC/wwwroot/components/iot/camera.html diff --git a/projects/WebMVC/wwwroot/components/device/color-light.html b/projects/WebMVC/wwwroot/components/iot/color-light.html similarity index 97% rename from projects/WebMVC/wwwroot/components/device/color-light.html rename to projects/WebMVC/wwwroot/components/iot/color-light.html index 25b555ff..a48cc9a3 100644 --- a/projects/WebMVC/wwwroot/components/device/color-light.html +++ b/projects/WebMVC/wwwroot/components/iot/color-light.html @@ -6,7 +6,7 @@
-
+
diff --git a/projects/WebMVC/wwwroot/components/device/curtain.html b/projects/WebMVC/wwwroot/components/iot/curtain.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/curtain.html rename to projects/WebMVC/wwwroot/components/iot/curtain.html diff --git a/projects/WebMVC/wwwroot/components/device/door.html b/projects/WebMVC/wwwroot/components/iot/door.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/door.html rename to projects/WebMVC/wwwroot/components/iot/door.html diff --git a/projects/WebMVC/wwwroot/components/device/gateway.html b/projects/WebMVC/wwwroot/components/iot/gateway.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/gateway.html rename to projects/WebMVC/wwwroot/components/iot/gateway.html diff --git a/projects/WebMVC/wwwroot/components/device/humiture.html b/projects/WebMVC/wwwroot/components/iot/humiture.html similarity index 94% rename from projects/WebMVC/wwwroot/components/device/humiture.html rename to projects/WebMVC/wwwroot/components/iot/humiture.html index 813f3a7d..f981fcda 100644 --- a/projects/WebMVC/wwwroot/components/device/humiture.html +++ b/projects/WebMVC/wwwroot/components/iot/humiture.html @@ -7,10 +7,10 @@
-
+
-
+
温度: diff --git a/projects/WebMVC/wwwroot/components/device/ir.html b/projects/WebMVC/wwwroot/components/iot/ir.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/ir.html rename to projects/WebMVC/wwwroot/components/iot/ir.html diff --git a/projects/WebMVC/wwwroot/components/device/light.html b/projects/WebMVC/wwwroot/components/iot/light.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/light.html rename to projects/WebMVC/wwwroot/components/iot/light.html diff --git a/projects/WebMVC/wwwroot/components/device/person.html b/projects/WebMVC/wwwroot/components/iot/person.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/person.html rename to projects/WebMVC/wwwroot/components/iot/person.html diff --git a/projects/WebMVC/wwwroot/components/device/serial-port.html b/projects/WebMVC/wwwroot/components/iot/serial-port.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/serial-port.html rename to projects/WebMVC/wwwroot/components/iot/serial-port.html diff --git a/projects/WebMVC/wwwroot/components/device/smoke.html b/projects/WebMVC/wwwroot/components/iot/smoke.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/smoke.html rename to projects/WebMVC/wwwroot/components/iot/smoke.html diff --git a/projects/WebMVC/wwwroot/components/device/socket.html b/projects/WebMVC/wwwroot/components/iot/socket.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/socket.html rename to projects/WebMVC/wwwroot/components/iot/socket.html diff --git a/projects/WebMVC/wwwroot/components/device/switch.html b/projects/WebMVC/wwwroot/components/iot/switch.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/switch.html rename to projects/WebMVC/wwwroot/components/iot/switch.html diff --git a/projects/WebMVC/wwwroot/components/device/switch3.html b/projects/WebMVC/wwwroot/components/iot/switch3.html similarity index 100% rename from projects/WebMVC/wwwroot/components/device/switch3.html rename to projects/WebMVC/wwwroot/components/iot/switch3.html diff --git a/projects/WebMVC/wwwroot/css/site.css b/projects/WebMVC/wwwroot/css/site.css index 692c19ae..b2049e90 100644 --- a/projects/WebMVC/wwwroot/css/site.css +++ b/projects/WebMVC/wwwroot/css/site.css @@ -1,17 +1,7 @@ -.loader { - position: relative; - height: 80px; - width: 80px; - top: 28%; - top: -webkit-calc(50% - 43px); - top: calc(50% - 43px); - left: 35%; - left: -webkit-calc(50% - 43px); - left: calc(50% - 43px); - border: 3px solid #fff; - border-radius: 80px; - -webkit-transform-origin: 50% 50%; - transform-origin: 50% 50%; - -webkit-animation: hourglass 2s ease-in-out infinite; - animation: hourglass 2s ease-in-out infinite; -} +.display-string { + width:8em; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + word-break: break-all; +} \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/index.html b/projects/WebMVC/wwwroot/index.html index 77ece646..5a33438d 100644 --- a/projects/WebMVC/wwwroot/index.html +++ b/projects/WebMVC/wwwroot/index.html @@ -54,6 +54,7 @@ + diff --git a/projects/WebMVC/wwwroot/js/axios.js b/projects/WebMVC/wwwroot/js/axios.js index f3969a08..36bb11c5 100644 --- a/projects/WebMVC/wwwroot/js/axios.js +++ b/projects/WebMVC/wwwroot/js/axios.js @@ -35,7 +35,7 @@ axios.interceptors.response.use(function (response) { .catch(function (error) { if (error.response.status === 401) { console.log('refreshToken 已过期'); - router.push('/pages/login'); + router.push('/router/login'); } }); } diff --git a/projects/WebMVC/wwwroot/js/common.js b/projects/WebMVC/wwwroot/js/common.js index 4f8f7b95..fcb95926 100644 --- a/projects/WebMVC/wwwroot/js/common.js +++ b/projects/WebMVC/wwwroot/js/common.js @@ -1,4 +1,11 @@ -function parseModel(response) { +function vueComponent(name,url) { + Vue.component(name, function (resolve, reject) { + axios.get(url).then(function (response) { + resolve(parseModel(response)); + }); + }); +} +function parseModel(response) { var html = new DOMParser().parseFromString(response.data, 'text/html'); var template = html.getElementsByTagName('template')[0].innerHTML; var script = html.getElementsByTagName('script')[0].innerHTML; diff --git a/projects/WebMVC/wwwroot/js/components.js b/projects/WebMVC/wwwroot/js/components.js index 6120a818..f5c28c8e 100644 --- a/projects/WebMVC/wwwroot/js/components.js +++ b/projects/WebMVC/wwwroot/js/components.js @@ -1,10 +1,10 @@ Vue.component('pagination', function (resolve, reject) { - axios.get("/pages/shared/pagination.html").then(function (response) { + axios.get("/router/shared/pagination.html").then(function (response) { resolve(parseModel(response)); }); }); Vue.component('layout', function (resolve, reject) { - axios.get("/pages/shared/layout.html").then(function (response) { + axios.get("/router/shared/layout.html").then(function (response) { resolve(parseModel(response)); }); }); \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/js/form.js b/projects/WebMVC/wwwroot/js/form.js new file mode 100644 index 00000000..b87aa609 --- /dev/null +++ b/projects/WebMVC/wwwroot/js/form.js @@ -0,0 +1,16 @@ +var formComponents = [ + 'display-string', + 'display-boolean', + 'display-imageurl', + 'display-integer', + 'display-selectlist', + 'display-multiselectlist', + 'edit-string', + 'edit-boolean', + 'edit-integer', +]; +for (var i = 0; i < formComponents.length; i++) { + var name = formComponents[i]; + var url = "/router/shared/" + name.replace('-', '/') + ".html"; + vueComponent(name, url); +} \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/js/iot.js b/projects/WebMVC/wwwroot/js/iot.js index fed24c95..0d3b3cef 100644 --- a/projects/WebMVC/wwwroot/js/iot.js +++ b/projects/WebMVC/wwwroot/js/iot.js @@ -1,11 +1,4 @@ -var time = '1d'; -if (window.WXInlinePlayer && WXInlinePlayer.isSupport()) { - WXInlinePlayer.init({ - asmUrl: '/lib/WXInlinePlayer/prod.all.asm.combine.js', - wasmUrl: '/lib/WXInlinePlayer/prod.all.wasm.combine.js' - }); -} -function getDeviceDataValue(device, name) { +function getDeviceDataValue(device, name) { var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault(); if (data) { return data['value']; @@ -37,73 +30,41 @@ function getData(device, name) { return Enumerable.from(device.data).where(o => o.name === name).firstOrDefault(); } //devices -Vue.component('iot-gateway', function (resolve, reject) { - axios.get("/components/device/gateway.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-light', function (resolve, reject) { - axios.get("/components/device/light.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-humiture', function (resolve, reject) { - axios.get("/components/device/humiture.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-smoke', function (resolve, reject) { - axios.get("/components/device/smoke.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-person', function (resolve, reject) { - axios.get("/components/device/person.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-curtain', function (resolve, reject) { - axios.get("/components/device/curtain.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-switch', function (resolve, reject) { - axios.get("/components/device/switch.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-switch3', function (resolve, reject) { - axios.get("/components/device/switch3.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-socket', function (resolve, reject) { - axios.get("/components/device/socket.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-ir', function (resolve, reject) { - axios.get("/components/device/ir.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-color-light', function (resolve, reject) { - axios.get("/components/device/color-light.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-door', function (resolve, reject) { - axios.get("/components/device/door.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-camera', function (resolve, reject) { - axios.get("/components/device/camera.html").then(function (response) { - resolve(parseModel(response)); - }); -}); -Vue.component('iot-serial-port', function (resolve, reject) { - axios.get("/components/device/serial-port.html").then(function (response) { - resolve(parseModel(response)); - }); -}); \ No newline at end of file +var iotComponents = [ + 'gateway', + 'light', + 'humiture', + 'smoke', + 'person', + 'curtain', + 'switch', + 'switch3', + 'socket', + 'ir', + 'color-light', + 'door', + 'camera', + 'serial-port', +]; +for (var i = 0; i < iotComponents.length; i++) { + var name = 'iot-'+iotComponents[i]; + var url = "/components/iot/" + iotComponents[i] + ".html"; + vueComponent(name, url); +} +var deviceInfo = []; +deviceInfo['网关'] = 'iot-gateway'; +deviceInfo['光强检测器'] = 'iot-light'; +deviceInfo['温湿度传感器'] = 'iot-humiture'; +deviceInfo['烟雾报警器'] = 'iot-smoke'; +deviceInfo['人体感应器'] = 'iot-person'; +deviceInfo['窗帘电机'] = 'iot-curtain'; +deviceInfo['一路开关'] = 'iot-switch'; +deviceInfo['三路开关'] = 'iot-switch3'; +deviceInfo['插座'] = 'iot-socket'; +deviceInfo['智能插座'] = 'iot-socket'; +deviceInfo['红外转发器'] = 'iot-ir'; +deviceInfo['调色灯'] = 'iot-color-light'; +deviceInfo['门锁'] = 'iot-door'; +deviceInfo['摄像头'] = 'iot-camera'; +deviceInfo['摄像头'] = 'gateway'; +deviceInfo['串口控制器'] = 'iot-serial-port'; \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/js/route.js b/projects/WebMVC/wwwroot/js/route.js index 3455c90b..1d591269 100644 --- a/projects/WebMVC/wwwroot/js/route.js +++ b/projects/WebMVC/wwwroot/js/route.js @@ -1,18 +1,18 @@ var routes = []; const router = new VueRouter(); router.beforeEach((to, from, next) => { - if (to.path !== '/pages/login.html') { + if (to.path !== '/router/login.html') { var isAuthenticated = false; if (store.state.token.accessToken) { var jwt = jwt_decode(store.state.token.accessToken); isAuthenticated = jwt.exp * 1000 >= new Date().getTime(); } if (!isAuthenticated) { - router.push('/pages/login.html'); + router.push('/router/login.html'); return; } } - var url = to.path === '/' ? '/pages/home.html' : to.path; + var url = to.path === '/' ? '/router/home.html' : to.path; var name = url.replace(/\//g, "-").replace(/\./g, "-").substring(1); var route = routes[name]; if (!route) { diff --git a/projects/WebMVC/wwwroot/pages/admin/list.html b/projects/WebMVC/wwwroot/pages/admin/list.html deleted file mode 100644 index 0a26162c..00000000 --- a/projects/WebMVC/wwwroot/pages/admin/list.html +++ /dev/null @@ -1,97 +0,0 @@ - - \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/pages/admin/home.html b/projects/WebMVC/wwwroot/router/admin/home.html similarity index 100% rename from projects/WebMVC/wwwroot/pages/admin/home.html rename to projects/WebMVC/wwwroot/router/admin/home.html diff --git a/projects/WebMVC/wwwroot/router/admin/list.html b/projects/WebMVC/wwwroot/router/admin/list.html new file mode 100644 index 00000000..dbf63d43 --- /dev/null +++ b/projects/WebMVC/wwwroot/router/admin/list.html @@ -0,0 +1,134 @@ + + \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/pages/device.html b/projects/WebMVC/wwwroot/router/device.html similarity index 78% rename from projects/WebMVC/wwwroot/pages/device.html rename to projects/WebMVC/wwwroot/router/device.html index 90464323..95ed652b 100644 --- a/projects/WebMVC/wwwroot/pages/device.html +++ b/projects/WebMVC/wwwroot/router/device.html @@ -3,21 +3,7 @@
- - - - - - - - - - - - - - - +
@@ -70,6 +56,12 @@ }); }); }, + getComponent: function () { + return deviceInfo[this.device.name]; + }, + showEdit: function () { + return this.device.name === '红外转发器' || this.device.name === '串口控制器'; + }, updateChart: function () { var dataList = Enumerable.from(this.device.data).where(function (o) { return o.type === 10 || o.type === 20; diff --git a/projects/WebMVC/wwwroot/pages/home.html b/projects/WebMVC/wwwroot/router/home.html similarity index 94% rename from projects/WebMVC/wwwroot/pages/home.html rename to projects/WebMVC/wwwroot/router/home.html index 35a06478..d6f37a95 100644 --- a/projects/WebMVC/wwwroot/pages/home.html +++ b/projects/WebMVC/wwwroot/router/home.html @@ -7,7 +7,7 @@

{{item.name}}

{{item.count}}
- +
diff --git a/projects/WebMVC/wwwroot/pages/login.html b/projects/WebMVC/wwwroot/router/login.html similarity index 100% rename from projects/WebMVC/wwwroot/pages/login.html rename to projects/WebMVC/wwwroot/router/login.html diff --git a/projects/WebMVC/wwwroot/pages/node.html b/projects/WebMVC/wwwroot/router/node.html similarity index 99% rename from projects/WebMVC/wwwroot/pages/node.html rename to projects/WebMVC/wwwroot/router/node.html index 0c5984be..07469286 100644 --- a/projects/WebMVC/wwwroot/pages/node.html +++ b/projects/WebMVC/wwwroot/router/node.html @@ -158,7 +158,7 @@ if (vm.node.id === item.id) { if (method.indexOf('Deleted') >= 0) { console.log('node has deleted'); - router.push('/pages/nodes.html'); + router.push('/router/nodes.html'); } else { vm.load(); diff --git a/projects/WebMVC/wwwroot/pages/nodes.html b/projects/WebMVC/wwwroot/router/nodes.html similarity index 95% rename from projects/WebMVC/wwwroot/pages/nodes.html rename to projects/WebMVC/wwwroot/router/nodes.html index 46655a20..87e8b817 100644 --- a/projects/WebMVC/wwwroot/pages/nodes.html +++ b/projects/WebMVC/wwwroot/router/nodes.html @@ -26,7 +26,7 @@
{{item.count}}
- + diff --git a/projects/WebMVC/wwwroot/pages/product.html b/projects/WebMVC/wwwroot/router/product.html similarity index 97% rename from projects/WebMVC/wwwroot/pages/product.html rename to projects/WebMVC/wwwroot/router/product.html index 3dd2f63a..143f03fe 100644 --- a/projects/WebMVC/wwwroot/pages/product.html +++ b/projects/WebMVC/wwwroot/router/product.html @@ -40,7 +40,7 @@
- +