diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 29a0c3a6..e604a1b8 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -252,7 +252,7 @@ namespace Infrastructure.Web { context.Token = context.Request.Query["access_token"]; } - if (context.Request.Cookies.Keys.Contains("jwt")) + if (!context.Request.Headers.ContainsKey("Authorization") && context.Request.Cookies.Keys.Contains("jwt")) { context.Token = context.Request.Cookies["jwt"]; } diff --git a/projects/IoT.Shared/Application/Domain/Entities/Product.cs b/projects/IoT.Shared/Application/Domain/Entities/Product.cs index 642eb814..4e417f83 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Product.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Product.cs @@ -24,6 +24,9 @@ namespace Application.Domain.Entities [Display(Name = "ApiJson")] public string ApiJson { get; set; } + [Display(Name = "序号")] + public int DisplayOrder { get; set; } + [Display(Name = "产品分类")] public Guid CategoryId { get; set; } diff --git a/projects/IoT.Shared/Application/Models/EditProductModel.cs b/projects/IoT.Shared/Application/Models/EditProductModel.cs index 77293ecf..9ff6230f 100644 --- a/projects/IoT.Shared/Application/Models/EditProductModel.cs +++ b/projects/IoT.Shared/Application/Models/EditProductModel.cs @@ -24,6 +24,9 @@ namespace Application.Models [Display(Name = "路径")] public string Path { get; set; } + [Display(Name = "序号")] + public int DisplayOrder { get; set; } + [Display(Name = "ApiJson")] [DataType(DataType.MultilineText)] public string ApiJson { get; set; } diff --git a/projects/IoTCenter/Api/DeviceController.cs b/projects/IoTCenter/Api/DeviceController.cs new file mode 100644 index 00000000..ee8e2470 --- /dev/null +++ b/projects/IoTCenter/Api/DeviceController.cs @@ -0,0 +1,53 @@ +using Application.Domain.Entities; +using Infrastructure.Data; +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using System; +using System.Linq; + +namespace UserCenter.Controllers +{ + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]/[action]")] + [ApiController] + public class DeviceController : ControllerBase + { + private readonly IConfiguration _cfg; + private readonly IRepository _productRepo; + private readonly IRepository _categoryRepo; + + public DeviceController(IConfiguration cfg, + IRepository productRepo, + IRepository categoryRepo) + { + this._cfg = cfg; + this._productRepo = productRepo; + this._categoryRepo = categoryRepo; + } + + [HttpPost] + public ActionResult GetProducts() + { + try + { + var model = this._productRepo.ReadOnlyTable() + .OrderBy(o => o.DisplayOrder) + .Select(o => new + { + o.Name, + o.Number, + o.Image, + o.DisplayOrder, + Count = o.Devices.Count() + }); + return Ok(model); + } + catch (Exception ex) + { + ex.PrintStack(); + return Problem(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/projects/IoTCenter/Api/NodeController.cs b/projects/IoTCenter/Api/NodeController.cs index 5a351ddc..15882af1 100644 --- a/projects/IoTCenter/Api/NodeController.cs +++ b/projects/IoTCenter/Api/NodeController.cs @@ -32,15 +32,24 @@ namespace UserCenter.Controllers { try { - var model = this._nodeCategoryRepo.ReadOnlyTable() - .Include(o => o.CategoryNodes) - .ThenInclude(o => o.Node) - .OrderBy(o => o.DisplayOrder) + //var model = this._nodeCategoryRepo.ReadOnlyTable() + // .Include(o => o.CategoryNodes) + // .ThenInclude(o => o.Node) + // .OrderBy(o => o.DisplayOrder) + // .Select(o => new + // { + // o.Name, + // o.DisplayOrder, + // Nodes = o.CategoryNodes.Select(o => o.Node) + // }); + var model = this._nodeRepo.ReadOnlyTable() .Select(o => new { o.Name, + o.Number, + o.Image, o.DisplayOrder, - Nodes = o.CategoryNodes.Select(o => o.Node) + Count = o.Devices.Count() }); return Ok(model); } diff --git a/projects/IoTCenter/Api/ProductController.cs b/projects/IoTCenter/Api/ProductController.cs new file mode 100644 index 00000000..66d621a0 --- /dev/null +++ b/projects/IoTCenter/Api/ProductController.cs @@ -0,0 +1,80 @@ +using Application.Domain.Entities; +using Infrastructure.Data; +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using System; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace UserCenter.Controllers +{ + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]/[action]")] + [ApiController] + public class ProductController : ControllerBase + { + private readonly IConfiguration _cfg; + private readonly IRepository _productRepo; + private readonly IRepository _deviceRepo; + + public ProductController(IConfiguration cfg, + IRepository productRepo, + IRepository deviceRepo) + { + this._cfg = cfg; + this._productRepo = productRepo; + this._deviceRepo = deviceRepo; + } + + [HttpPost] + public ActionResult GetProducts() + { + try + { + var model = this._productRepo.ReadOnlyTable() + .OrderBy(o => o.DisplayOrder) + .Select(o => new + { + o.Name, + o.Number, + o.Image, + o.DisplayOrder, + Count = o.Devices.Count() + }); + return Ok(model); + } + catch (Exception ex) + { + ex.PrintStack(); + return Problem(ex.Message); + } + } + + [HttpPost] + public ActionResult GetDevices([Required]string number) + { + try + { + var model = this._deviceRepo.ReadOnlyTable() + .Where(o => o.Product.Number == number) + .OrderBy(o => o.DisplayOrder) + .Select(o => new + { + o.Name, + o.Number, + o.DisplayName, + Image = o.Product.Image, + o.DisplayOrder, + o.Data + }); + return Ok(model); + } + catch (Exception ex) + { + ex.PrintStack(); + return Problem(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/nodes.html b/projects/IoTCenter/wwwroot/nodes.html new file mode 100644 index 00000000..38fabfde --- /dev/null +++ b/projects/IoTCenter/wwwroot/nodes.html @@ -0,0 +1,19 @@ +
+ + + back + + +
+
+ +
+
+
\ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/nodes.js b/projects/IoTCenter/wwwroot/nodes.js new file mode 100644 index 00000000..59c8ff40 --- /dev/null +++ b/projects/IoTCenter/wwwroot/nodes.js @@ -0,0 +1,29 @@ +function IoTCenter_nodes() { + return Vue.component('IoTCenter_nodes', function (resolve, reject) { + axios.get("/IoTCenter/nodes.html").then(function (response) { + resolve({ + template: response.data, + data() { + return { + model: null + }; + }, + mounted: function () { + var url = '/IoTCenter/api/v1/node/getNodes'; + var component = this; + axios.post(url) + .then(function (response) { + component.model = response.data; + }) + .catch(function (error) { + }) + .finally(function () { + + }); + }, + methods: { + } + }) + }); + }); +} \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/product.html b/projects/IoTCenter/wwwroot/product.html new file mode 100644 index 00000000..8880e828 --- /dev/null +++ b/projects/IoTCenter/wwwroot/product.html @@ -0,0 +1,19 @@ +
+ + + back + + +
+
+ +
+
+
\ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/product.js b/projects/IoTCenter/wwwroot/product.js new file mode 100644 index 00000000..4f206d77 --- /dev/null +++ b/projects/IoTCenter/wwwroot/product.js @@ -0,0 +1,31 @@ +function IoTCenter_product() { + return Vue.component('IoTCenter_product', function (resolve, reject) { + axios.get("/IoTCenter/product.html").then(function (response) { + resolve({ + template: response.data, + data() { + return { + model: null + }; + }, + mounted: function () { + console.log('当前路由:'); + console.log(this.$route); + var url = '/IoTCenter/api/v1/product/getDevices?number='+this.$route.query.number; + var component = this; + axios.post(url) + .then(function (response) { + component.model = response.data; + }) + .catch(function (error) { + }) + .finally(function () { + + }); + }, + methods: { + } + }) + }); + }); +} \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/products.html b/projects/IoTCenter/wwwroot/products.html new file mode 100644 index 00000000..4eef9b54 --- /dev/null +++ b/projects/IoTCenter/wwwroot/products.html @@ -0,0 +1,19 @@ +
+ + + back + + +
+
+ +
+
+
\ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/products.js b/projects/IoTCenter/wwwroot/products.js new file mode 100644 index 00000000..9f5aa6f8 --- /dev/null +++ b/projects/IoTCenter/wwwroot/products.js @@ -0,0 +1,29 @@ +function IoTCenter_products() { + return Vue.component('IoTCenter_products', function (resolve, reject) { + axios.get("/IoTCenter/products.html").then(function (response) { + resolve({ + template: response.data, + data() { + return { + model: null + }; + }, + mounted: function () { + var url = '/IoTCenter/api/v1/product/getProducts'; + var component = this; + axios.post(url) + .then(function (response) { + component.model = response.data; + }) + .catch(function (error) { + }) + .finally(function () { + + }); + }, + methods: { + } + }) + }); + }); +} \ No newline at end of file diff --git a/projects/WebUI/wwwroot/pc.js b/projects/WebUI/wwwroot/pc.js index c8161529..4fd4c88f 100644 --- a/projects/WebUI/wwwroot/pc.js +++ b/projects/WebUI/wwwroot/pc.js @@ -100,7 +100,7 @@ router.beforeEach((to, from, next) => { var path = to.path === '/' ? '/pchome' : to.path; var url = path + '.js'; var method = path.replace(/\//g, '_').substr(1) + "()"; - console.log('preRoute:' + path + '|' + url + '|' + method); + console.log('preRoute:from ' + from.path + ' to path ' + to.path); $.getScript(url, function () { var route = { path: to.path, diff --git a/projects/WebUI/wwwroot/pchome.html b/projects/WebUI/wwwroot/pchome.html index 8acc7041..2ae00533 100644 --- a/projects/WebUI/wwwroot/pchome.html +++ b/projects/WebUI/wwwroot/pchome.html @@ -1,25 +1,24 @@ 
+

消息

-
-
物联网
-
-
- -
- -
-

设备

-
- -
- -
-

房间

-
-
+
物联网
+
+
+ +
+ +
+

设备

+
+ +
+ +
+

智慧教室

+
@@ -35,7 +34,7 @@
- + 退出