diff --git a/projects/Infrastructure/Extensions/TreeEntityExtensions.cs b/projects/Infrastructure/Extensions/TreeEntityExtensions.cs index 5fd76128..57968dc7 100644 --- a/projects/Infrastructure/Extensions/TreeEntityExtensions.cs +++ b/projects/Infrastructure/Extensions/TreeEntityExtensions.cs @@ -10,7 +10,7 @@ namespace Infrastructure.Extensions { if (list != null) { - foreach (var item in list) + foreach (var item in list.OrderBy(o=>o.DisplayOrder)) { if (item.ParentId.HasValue) { diff --git a/projects/IoT.Shared/wwwroot/css/site.css b/projects/IoT.Shared/wwwroot/css/site.css index e00f2286..4a78d38b 100644 --- a/projects/IoT.Shared/wwwroot/css/site.css +++ b/projects/IoT.Shared/wwwroot/css/site.css @@ -123,4 +123,8 @@ img.pointer { line-height: 24px; margin: 0 auto; overflow: hidden; +} +.ant-tree-switcher-line-icon { + line-height:14px; + vertical-align: text-top; } \ No newline at end of file diff --git a/projects/Platform/Controllers/HomeController.cs b/projects/Platform/Controllers/HomeController.cs index fba5243e..d2b0b900 100644 --- a/projects/Platform/Controllers/HomeController.cs +++ b/projects/Platform/Controllers/HomeController.cs @@ -52,10 +52,10 @@ namespace Platform.Controllers public IActionResult GetOrgan() { - var userOrganId = User.GetOrganId().Value;//当前用户机构Id + var organId = User.GetOrganId().Value;//当前用户机构Id var organ = this._organRepo.ReadOnlyTable() .Include(o => o.Buildings) - .FirstOrDefault(o => o.Id == userOrganId); + .FirstOrDefault(o => o.Id == organId); organ.Buildings.ToTree(); var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.ParentId == null).Select(o => o.Id).FirstOrDefault(); organ.Buildings = organ.Buildings @@ -63,28 +63,37 @@ namespace Platform.Controllers .ToList(); var model = new { Organ= organ, - MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxLight").FirstOrDefault()?.Value, - MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinLight").FirstOrDefault()?.Value, - MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxTemperature").FirstOrDefault()?.Value, - MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinTemperature").FirstOrDefault()?.Value, - MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxHumidity").FirstOrDefault()?.Value, - MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinHumidity").FirstOrDefault()?.Value, - DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]DeviceOpenCount").FirstOrDefault()?.Value, - DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]DeviceCloseCount").FirstOrDefault()?.Value, + MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxLight").FirstOrDefault()?.Value, + MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinLight").FirstOrDefault()?.Value, + MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxTemperature").FirstOrDefault()?.Value, + MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinTemperature").FirstOrDefault()?.Value, + MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxHumidity").FirstOrDefault()?.Value, + MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinHumidity").FirstOrDefault()?.Value, + DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]DeviceOpenCount").FirstOrDefault()?.Value, + DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]DeviceCloseCount").FirstOrDefault()?.Value, }; return Json(model); } public IActionResult GetBuilding(Guid id) { - var model = new - { - Building = this._buildingRepo.ReadOnlyTable() - .Include(o=>o.Scenes) + var organId = User.GetOrganId().Value;//当前用户机构Id + var building = this._buildingRepo.ReadOnlyTable() + .Include(o => o.Scenes) .Include(o => o.IoTGateways) .ThenInclude(o => o.Devices).ThenInclude(o => o.Data) - .ToList() - + .FirstOrDefault(); + var model = new + { + Building = building, + MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxLight").FirstOrDefault()?.Value, + MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinLight").FirstOrDefault()?.Value, + MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxTemperature").FirstOrDefault()?.Value, + MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinTemperature").FirstOrDefault()?.Value, + MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxHumidity").FirstOrDefault()?.Value, + MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinHumidity").FirstOrDefault()?.Value, + DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]DeviceOpenCount").FirstOrDefault()?.Value, + DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]DeviceCloseCount").FirstOrDefault()?.Value, }; return Json(model); } diff --git a/projects/Platform/Data/PlatformDbContext.cs b/projects/Platform/Data/PlatformDbContext.cs index 816f799b..d0a47b39 100644 --- a/projects/Platform/Data/PlatformDbContext.cs +++ b/projects/Platform/Data/PlatformDbContext.cs @@ -113,16 +113,17 @@ namespace Platform.Data public void Seed(DbContext db) { + var order = 0; var root = db.Set().Add(new IoTProductCategory { Name = "产品分类", Number = "root" }).Entity; - db.Set().Add(new IoTProductCategory { ParentId = root.Id, Number = "00", Name = "网关", Image = "/images/gateway.svg" }); - db.Set().Add(new IoTProductCategory { ParentId = root.Id, Number = "10", Name = "安防", Image = "/images/safe.svg" }); - db.Set().Add(new IoTProductCategory { ParentId = root.Id, Number = "20", Name = "电器", Image = "/images/socket.svg" }); - db.Set().Add(new IoTProductCategory { ParentId = root.Id, Number = "30", Name = "照明", Image = "/images/light.svg" }); - db.Set().Add(new IoTProductCategory { ParentId = root.Id, Number = "40", Name = "监测", Image = "/images/monitor.svg" }); + db.Set().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "00", Name = "网关", Image = "/images/gateway.svg" }); + db.Set().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "10", Name = "安防", Image = "/images/safe.svg" }); + db.Set().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "20", Name = "电器", Image = "/images/socket.svg" }); + db.Set().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "30", Name = "照明", Image = "/images/light.svg" }); + db.Set().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "40", Name = "监测", Image = "/images/monitor.svg" }); db.SaveChanges(); db.Set().FirstOrDefault(o => o.Number == "root").Update(); db.SaveChanges(); @@ -157,7 +158,8 @@ namespace Platform.Data { Parent = categoryGroup, Name = name, - Number = number + Number = number, + DisplayOrder=order++ }; var scopeAttribute = type.GetCustomAttribute(); if (scopeAttribute != null) @@ -297,7 +299,7 @@ namespace Platform.Data var organId = db.Set().FirstOrDefault(o => o.Number == "xuexiao").Id; var buildingRoot = new Building { - Image= image, + Image = image, Name = "建筑", Number = "root", OrganId = organRoot.Id, @@ -306,6 +308,7 @@ namespace Platform.Data new Building { Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Building, Name="默认建筑", @@ -313,6 +316,7 @@ namespace Platform.Data Children = new List { new Building { Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Layer, Name="1楼", @@ -321,6 +325,7 @@ namespace Platform.Data { new Building{ Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Room, Name="101室", @@ -328,6 +333,7 @@ namespace Platform.Data }, new Building{ Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Room, Name="102室", @@ -337,6 +343,7 @@ namespace Platform.Data }, new Building { Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Layer, Name="2楼", @@ -345,6 +352,7 @@ namespace Platform.Data { new Building{ Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Room, Name="201室", @@ -352,6 +360,7 @@ namespace Platform.Data }, new Building{ Image= image, + DisplayOrder=order++, OrganId=organId, Type= BuildingType.Room, Name="202室", diff --git a/projects/Platform/wwwroot/components/views/home/index.html b/projects/Platform/wwwroot/components/views/home/index.html index 7ecc9f82..bf704c8d 100644 --- a/projects/Platform/wwwroot/components/views/home/index.html +++ b/projects/Platform/wwwroot/components/views/home/index.html @@ -1,10 +1,11 @@  @@ -163,7 +167,8 @@ url: config.baseUrl + '/Home/GetOrgan', model: { organ: null, - building:null + building: null, + expanded:[], }, events: ['OrganEntityInserted', 'OrganEntityUpdated', @@ -194,34 +199,56 @@ }); }, onSelect(selectedKeys, info) { - var url = config.baseUrl + '/Home/GetBuilding/' + selectedKeys[0]; - axios.get(url).then(function (response) { - parent.model.building = response.data; - }); + var parent = this; + var key = selectedKeys[0]; + if (key === this.model.organ.organ.id) { + this.model.building = null; + } + else { + var url = config.baseUrl + '/Home/GetBuilding/' + key; + axios.get(url).then(function (response) { + parent.model.building = response.data; + }); + } }, - findBuilding: function (buildings, id) { + findBuildings: function (buildings,id) { for (var i in buildings) { var item = buildings[i]; if (item.id == id) { return item.children; } if (item.children.length > 0) { - this.findBuilding(item.children, id); + return this.findBuildings(item.children, id); } } } }, computed: { tree: function () { - return this.model.organ.organ.buildings; + var result = []; + if (this.model.organ != null) { + result.push({ + id:this.model.organ.organ.id, + name:this.model.organ.organ.name, + children: this.model.organ.organ.buildings + }); + } + return result; + }, + expanded : function () { + var result = []; + if (this.model.organ != null) { + result.push(this.model.organ.organ.id); + } + return result; }, buildings: function () { - console.log(this.model.buildingId); - if (!this.model.buildingId) { + //console.log(this.model.buildingId); + if (!this.model.building) { return this.model.organ.organ.buildings; } else { - return this.findBuilding(this.model.organ.organ.buildings, this.model.buildingId); + return this.findBuildings(this.model.organ.organ.buildings,this.model.building.building.id); } } }