diff --git a/projects/Platform/Controllers/HomeController.cs b/projects/Platform/Controllers/HomeController.cs index d2b0b900..214a0de5 100644 --- a/projects/Platform/Controllers/HomeController.cs +++ b/projects/Platform/Controllers/HomeController.cs @@ -54,8 +54,9 @@ namespace Platform.Controllers { var organId = User.GetOrganId().Value;//当前用户机构Id var organ = this._organRepo.ReadOnlyTable() + .Where(o => o.Id == organId) .Include(o => o.Buildings) - .FirstOrDefault(o => o.Id == organId); + .FirstOrDefault(); organ.Buildings.ToTree(); var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.ParentId == null).Select(o => o.Id).FirstOrDefault(); organ.Buildings = organ.Buildings @@ -79,6 +80,7 @@ namespace Platform.Controllers { var organId = User.GetOrganId().Value;//当前用户机构Id var building = this._buildingRepo.ReadOnlyTable() + .Where(o=>o.Id==id) .Include(o => o.Scenes) .Include(o => o.IoTGateways) .ThenInclude(o => o.Devices).ThenInclude(o => o.Data) diff --git a/projects/Platform/wwwroot/components/views/home/index.html b/projects/Platform/wwwroot/components/views/home/index.html index bf704c8d..ddd10cdf 100644 --- a/projects/Platform/wwwroot/components/views/home/index.html +++ b/projects/Platform/wwwroot/components/views/home/index.html @@ -4,7 +4,9 @@
建筑列表
- + ℃

@@ -103,7 +105,7 @@ + RH%"

@@ -138,7 +140,7 @@ -
+
下级建筑
@@ -147,15 +149,27 @@
-
- +
+
场景
+
+ +
@@ -168,7 +182,7 @@ model: { organ: null, building: null, - expanded:[], + expanded: [], }, events: ['OrganEntityInserted', 'OrganEntityUpdated', @@ -198,20 +212,29 @@ parent.model.organ = response.data; }); }, - onSelect(selectedKeys, info) { - 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; - }); + selectBuilding: function (id) { + var keys = [id]; + this.$refs.tree.selectedKeys = keys; + this.$refs.tree.expandedKeys = keys; + this.onSelect(keys); + }, + onSelect: function (selectedKeys, info) { + if (selectedKeys.length > 0) { + this.$refs.tree.selectedKeys = selectedKeys; + var parent = this; + var id = selectedKeys[0]; + if (id === this.model.organ.organ.id) { + this.model.building = null; + } + else { + var url = config.baseUrl + '/Home/GetBuilding/' + id; + axios.get(url).then(function (response) { + parent.model.building = response.data; + }); + } } }, - findBuildings: function (buildings,id) { + findBuildings: function (buildings, id) { for (var i in buildings) { var item = buildings[i]; if (item.id == id) { @@ -228,14 +251,14 @@ var result = []; if (this.model.organ != null) { result.push({ - id:this.model.organ.organ.id, - name:this.model.organ.organ.name, + id: this.model.organ.organ.id, + name: this.model.organ.organ.name, children: this.model.organ.organ.buildings }); } return result; }, - expanded : function () { + expanded: function () { var result = []; if (this.model.organ != null) { result.push(this.model.organ.organ.id); @@ -243,13 +266,19 @@ return result; }, buildings: function () { - //console.log(this.model.buildingId); - if (!this.model.building) { - return this.model.organ.organ.buildings; + if (this.model.building) { + return this.findBuildings(this.model.organ.organ.buildings, this.model.building.building.id); } else { - return this.findBuildings(this.model.organ.organ.buildings,this.model.building.building.id); + return this.model.organ.organ.buildings; + } + }, + scenes: function () { + var result = []; + if (this.model.building) { + result = Enumerable.from(this.model.building.building.scenes).orderBy(o => o.displayOrder).toArray(); } + return result; } } };