Former-commit-id: a336153668c816d6a7900902d43d49ca2b952dcd
Former-commit-id: 59945ed6d3431018cc92dbcaea176fd9b7934613
1.0
wanggang 4 years ago
parent 7e199ecff3
commit cd8230022f

@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

@ -15,19 +15,34 @@ namespace Platform.Api
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
[Authorize]
public class SiteController : Controller
public class SiteController : ControllerBase
{
private readonly ISettingService _settingService;
private readonly IRepository<User> _userRepo;
private readonly IRepository<AppModule> _appModuleRepo;
private readonly IRepository<OrganUser> _organUserRepo;
private readonly IRepository<Area> _areaRepo;
private readonly IRepository<Organ> _organRepo;
private readonly IRepository<Building> _buildingRepo;
private readonly IRepository<Statistic> _statisticRepo;
public SiteController(ISettingService settingService, IRepository<User> userRepo, IRepository<AppModule> appModuleRepo, IRepository<OrganUser> organUserRepo)
public SiteController(ISettingService settingService,
IRepository<User> userRepo,
IRepository<AppModule> appModuleRepo,
IRepository<OrganUser> organUserRepo,
IRepository<Area> areaRepo,
IRepository<Organ> organRepo,
IRepository<Building> buildingRepo,
IRepository<Statistic> statisticRepo)
{
this._settingService = settingService;
this._userRepo = userRepo;
this._appModuleRepo = appModuleRepo;
this._organUserRepo = organUserRepo;
this._organUserRepo = organUserRepo;
this._areaRepo = areaRepo;
this._organRepo = organRepo;
this._buildingRepo = buildingRepo;
this._statisticRepo = statisticRepo;
}
[HttpPost]
@ -72,5 +87,61 @@ namespace Platform.Api
return Problem(ex.Message);
}
}
[HttpPost]
public IActionResult GetOrgan()
{
var organId = User.GetOrganId().Value;//当前用户机构Id
var organ = this._organRepo.ReadOnlyTable()
.Where(o => o.Id == organId)
.Include(o => o.Buildings)
.FirstOrDefault();
organ.Buildings.ToTree();
var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.ParentId == null).Select(o => o.Id).FirstOrDefault();
organ.Buildings = organ.Buildings
.Where(o => o.ParentId == rootBuildingId)
.ToList();
var model = new
{
Organ = organ,
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 new JsonResult(model);
}
[HttpPost]
public IActionResult GetBuilding(Guid id)
{
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)
.Include(o => o.IoTGateways).ThenInclude(o => o.Devices).ThenInclude(o => o.IoTProduct)
.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 new JsonResult(model);
}
}
}

@ -4,10 +4,6 @@ using Infrastructure.Extensions;
using Infrastructure.Web;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Platform.ViewModels;
using System;
using System.Linq;
namespace Platform.Controllers
{
@ -32,287 +28,6 @@ namespace Platform.Controllers
}
public IActionResult Index()
{
var area = this._areaRepo.ReadOnlyTable()
.Where(o => o.Name == "南关区")
.Include(o => o.Parent).ThenInclude(o => o.Parent).First();
return View();
}
public IActionResult GetOrgan()
{
var organId = User.GetOrganId().Value;//当前用户机构Id
var organ = this._organRepo.ReadOnlyTable()
.Where(o => o.Id == organId)
.Include(o => o.Buildings)
.FirstOrDefault();
organ.Buildings.ToTree();
var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.ParentId == null).Select(o => o.Id).FirstOrDefault();
organ.Buildings = organ.Buildings
.Where(o => o.ParentId == rootBuildingId)
.ToList();
var model = new
{
Organ = organ,
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 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)
.Include(o => o.IoTGateways).ThenInclude(o => o.Devices).ThenInclude(o => o.IoTProduct)
.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);
}
public IActionResult Building(HomeModel model)
{
var userOrganId = User.GetOrganId().Value;//当前用户机构Id
var currentUserOrgan = this._organRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == userOrganId);//当前用户机构
var organList = this._organRepo.ReadOnlyTable()//当前用户机构及下级机构
.Where(o => o.ParentId != null)
.Where(o => o.Left >= currentUserOrgan.Left && o.Right <= currentUserOrgan.Right)
.Include(o => o.Buildings)
.ToList();
organList.ToTree();
var rootOrganId = this._organRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
model.Organs = organList.Where(o => o.Parent == null).ToList();
if (model.BuildingId.HasValue)//选中建筑,则建筑所属机构为当前机构
{
model.Organ = organList.SelectMany(o => o.Buildings).FirstOrDefault(o => o.Id == model.BuildingId.Value).Organ;
model.Scenes = this._buildingRepo.ReadOnlyTable()
.Where(o => o.Id == model.BuildingId.Value)
.SelectMany(o => o.Scenes)
.Where(o => o.Hidden == false)
.ToList();
}
else
{
if (model.OrganId.HasValue)
{
model.Organ = organList.FirstOrDefault(o => o.Id == model.OrganId.Value);
}
else
{//即未选中建筑也未选中机构,则用户所在机构为当前机构
model.Organ = organList.FirstOrDefault(o => o.Id == userOrganId);
}
}
model.OrganId = model.Organ.Id;
var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
if (model.BuildingId.HasValue)
{
model.Building = model.Organ.Buildings.FirstOrDefault(o => o.Id == model.BuildingId.Value);
model.Buildings = model.Organ.Buildings.Where(o => o.ParentId == model.BuildingId.Value).ToList();
}
else
{
model.Buildings = model.Organ.Buildings.Where(o => o.ParentId == rootBuildingId).ToList();
}
var currentBuilding = model.BuildingId.HasValue ?
this._buildingRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.BuildingId.Value) :
null;
var query = this._buildingRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.Where(o => o.OrganId == model.OrganId.Value)
.WhereIf(!model.ShowAll && model.BuildingId.HasValue, o => o.Id == model.BuildingId.Value)
.WhereIf(!model.ShowAll && !model.BuildingId.HasValue, o => false)
.WhereIf(model.ShowAll && model.BuildingId.HasValue, o => o.Left >= currentBuilding.Left && o.Right <= currentBuilding.Right)
.SelectMany(o => o.IoTGateways)
.SelectMany(o => o.Devices);
model.TotalCount = query.Count();
model.Deviceses = query
.Include(o => o.Data)
.Include(o => o.IoTProduct)
.Skip(model.PageSize * (model.PageIndex - 1))
.Take(model.PageSize).ToList();
foreach (var item in organList)
{
item.Buildings = item.Buildings.ToTree().Where(o => o.ParentId == rootBuildingId).ToList();
}
//
var light = this.GetDataValue<int>(query, "Light");
model.MinLight = light.Item1;
model.MaxLight = light.Item2;
var temperature = this.GetDataValue<float>(query, "Temperature");
model.MinTemperaturest = temperature.Item1;
model.MaxTemperatures = temperature.Item2;
var humidity = this.GetDataValue<float>(query, "Humidity");
model.MinHumidity = humidity.Item1;
model.MaxHumidity = humidity.Item2;
var query2 = query.Where(o => o.Name.Contains("开关") || o.Name.Contains("插座")).SelectMany(o => o.Data).Where(o => o.Key == "State");
var hasDevices = query2.Any();
model.Open = hasDevices ? new int?(query2.Where(o => o.Value == "开").Count()) : null;
model.Close = hasDevices ? new int?(query2.Where(o => o.Value == "关").Count()) : null;
return View(model);
}
public IActionResult BuildingData(HomeModel model)
{
var userOrganId = User.GetOrganId().Value;//当前用户机构Id
var currentUserOrgan = this._organRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == userOrganId);//当前用户机构
var organList = this._organRepo.ReadOnlyTable()//当前用户机构及下级机构
.Where(o => o.ParentId != null)
.Where(o => o.Left >= currentUserOrgan.Left && o.Right <= currentUserOrgan.Right)
.Include(o => o.Buildings)
.ToList();
organList.ToTree();
var rootOrganId = this._organRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
model.Organs = organList.Where(o => o.Parent == null).ToList();
if (model.BuildingId.HasValue)//选中建筑,则建筑所属机构为当前机构
{
model.Organ = organList.SelectMany(o => o.Buildings).FirstOrDefault(o => o.Id == model.BuildingId.Value).Organ;
model.Scenes = this._buildingRepo.ReadOnlyTable()
.Where(o => o.Id == model.BuildingId.Value)
.SelectMany(o => o.Scenes)
.Where(o => o.Hidden == false)
.ToList();
}
else
{
if (model.OrganId.HasValue)
{
model.Organ = organList.FirstOrDefault(o => o.Id == model.OrganId.Value);
}
else
{//即未选中建筑也未选中机构,则用户所在机构为当前机构
model.Organ = organList.FirstOrDefault(o => o.Id == userOrganId);
}
}
model.OrganId = model.Organ.Id;
var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
if (model.BuildingId.HasValue)
{
model.Building = model.Organ.Buildings.FirstOrDefault(o => o.Id == model.BuildingId.Value);
model.Buildings = model.Organ.Buildings.Where(o => o.ParentId == model.BuildingId.Value).ToList();
}
else
{
model.Buildings = model.Organ.Buildings.Where(o => o.ParentId == rootBuildingId).ToList();
}
var currentBuilding = model.BuildingId.HasValue ?
this._buildingRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.BuildingId.Value) :
null;
var query = this._buildingRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.Where(o => o.OrganId == model.OrganId.Value)
.WhereIf(!model.ShowAll && model.BuildingId.HasValue, o => o.Id == model.BuildingId.Value)
.WhereIf(!model.ShowAll && !model.BuildingId.HasValue, o => false)
.WhereIf(model.ShowAll && model.BuildingId.HasValue, o => o.Left >= currentBuilding.Left && o.Right <= currentBuilding.Right)
.SelectMany(o => o.IoTGateways)
.SelectMany(o => o.Devices);
model.TotalCount = query.Count();
model.Deviceses = query
.Include(o => o.Data)
.Include(o => o.IoTProduct)
.Skip(model.PageSize * (model.PageIndex - 1))
.Take(model.PageSize).ToList();
foreach (var item in organList)
{
item.Buildings = item.Buildings.ToTree().Where(o => o.ParentId == rootBuildingId).ToList();
}
//
var light = this.GetDataValue<int>(query, "Light");
model.MinLight = light.Item1;
model.MaxLight = light.Item2;
var temperature = this.GetDataValue<float>(query, "Temperature");
model.MinTemperaturest = temperature.Item1;
model.MaxTemperatures = temperature.Item2;
var humidity = this.GetDataValue<float>(query, "Humidity");
model.MinHumidity = humidity.Item1;
model.MaxHumidity = humidity.Item2;
var query2 = query.Where(o => o.Name.Contains("开关") || o.Name.Contains("插座")).SelectMany(o => o.Data).Where(o => o.Key == "State");
var hasDevices = query2.Any();
model.Open = hasDevices ? new int?(query2.Where(o => o.Value == "开").Count()) : null;
model.Close = hasDevices ? new int?(query2.Where(o => o.Value == "关").Count()) : null;
return Json(model);
}
private Tuple<T?, T?> GetDataValue<T>(IQueryable<IoTDevice> query, string key) where T : struct
{
var list = query.SelectMany(o => o.Data)
.Where(o => o.Key == key).Select(o => o.Value)
.ToList()
.Select(o => ConvertTo<T>(o));
return new Tuple<T?, T?>(
list.Any() ? new T?(list.Min()) : null,
list.Any() ? new T?(list.Max()) : null
);
}
private T ConvertTo<T>(string value) where T : struct
{
T result = (T)Convert.ChangeType(value, typeof(T));
return result;
}
public IActionResult Alarm()
{
return View();
}
public IActionResult Product()
{
return View();
}
public IActionResult Device()
{
return View();
}
public IActionResult Organ()
{
return View();
}
public IActionResult Nodes()
{
return View();
}
public IActionResult Node()
{
return View();
}
public IActionResult Index3()
{
return View();
}
public IActionResult Index4()
{
return View();
}

@ -1,7 +1,7 @@
<ul class="nav nav-pills nav-sidebar flex-column nav-flat" data-widget="treeview" role="menu" data-accordion="false">
<li class="nav-header">智慧校园</li>
<li class="nav-item"><a href="@Url.Action("Index","Home")" class="@GetLinkClass("Home","Index")"><i class="far fa-circle nav-icon"></i><p>机构概览</p></a></li>
<li class="nav-item"><a href="@Url.Action("Building","Home")" class="@GetLinkClass("Home","Building")"><i class="far fa-circle nav-icon"></i><p>设备中心</p></a></li>
<li class="nav-item"><a href="@Url.Action("Building","Home")" class="@GetLinkClass("Home","Device")"><i class="far fa-circle nav-icon"></i><p>设备中心</p></a></li>
<li class="nav-item"><a href="@Url.Action("Alarm","Home")" class="@GetLinkClass("Home","Alarm")"><i class="far fa-circle nav-icon"></i><p>告警中心</p></a></li>
<li class="nav-header">业务系统</li>
<li class="nav-item"><a href="#" class="@GetLinkClass("Home","Index1")"><i class="far fa-circle nav-icon"></i><p>环境监测</p></a></li>

@ -176,7 +176,7 @@
export default {
data() {
return {
url: config.service('platform/Home/GetOrgan'),
url: config.service('platform/api/v1/Site/GetOrgan'),
model: {
organ: null,
building: null,
@ -270,7 +270,7 @@
this.model.building = null;
}
else {
var url = config.service('platform/Home/GetBuilding/' + id);
var url = config.service('platform/api/v1/Site/GetBuilding?id=' + id);
axios.post(url).then(function (response) {
parent.model.building = response.data;
});

@ -0,0 +1,331 @@
<template>
<views-shared-layout>
<div class="row" style="padding-top:1rem;" v-if="model.organ">
<div class="col-sm-2">
<div class="card">
<div class="card-header">建筑列表</div>
<div class="card-body">
<a-tree ref="tree"
:tree-data="tree"
:auto-expand-parent="true"
:default-expanded-keys="expanded"
:replace-fields="{title:'name',key:'id'}"
block-node
show-line
@select="onSelect">
</a-tree>
</div>
</div>
</div>
<div class="col-sm-10">
<div class="card">
<div class="card-header">
<h5 class="card-title">
当前{{model.building?model.building.building.name:model.organ.organ.name}}
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
光照
</div>
</div>
<p>
最大值
<template v-if="model.building">
{{model.building.maxLight}}
</template>
<template v-else>
{{model.organ.maxLight}}
</template>
Lux
</p>
<p>
最小值
<template v-if="model.building">
{{model.building.minLight}}
</template>
<template v-else>
{{model.organ.minLight}}
</template>
Lux
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
温度
</div>
</div>
<p>
最大值
<template v-if="model.building">
{{model.building.maxTemperature}}
</template>
<template v-else>
{{model.organ.maxTemperature}}
</template>
</p>
<p>
最小值
<template v-if="model.building">
{{model.building.minTemperature}}
</template>
<template v-else>
{{model.organ.minTemperature}}
</template>
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
湿度
</div>
</div>
<p>
最大值
<template v-if="model.building">
{{model.building.maxHumidity}}
</template>
<template v-else>
{{model.organ.maxHumidity}}
</template>
RH%"
</p>
<p>
最小值
<template v-if="model.building">
{{model.building.minHumidity}}
</template>
<template v-else>
{{model.organ.minHumidity}}
</template>
RH%"
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
用电
</div>
</div>
<p>
<template v-if="model.building">
{{model.building.deviceOpenCount}}
</template>
<template v-else>
{{model.organ.deviceOpenCount}}
</template>
</p>
<p>
<template v-if="model.building">
{{model.building.deviceCloseCount}}
</template>
<template v-else>
{{model.organ.deviceCloseCount}}
</template>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="card" v-if="scenes.length>0">
<div class="card-header">场景</div>
<div class="card-body">
<div class="row">
<div class="col-sm-1" v-for="item in scenes">
<div class="card bg-light p-2">
<a class="card-body text-center" href="javascript:;" style="padding:0;" v-on:click="execScene(item.id)">
<img class="card-img-top" :src="item.image" :alt="item.name" style="width:64px;height:64px;margin:0 auto;">
<div>{{item.name}}</div>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="card" v-if="devices.length>0">
<div class="card-header">设备</div>
<div class="card-body">
<div class="row">
<div v-for="item in devices" class="col device-container" :title="item.name+item.ioTProduct.template">
<component :device="item" :is="'devices-'+item.ioTProduct.template"></component>
</div>
</div>
</div>
</div>
</div>
</div>
</views-shared-layout>
</template>
<script>
export default {
data() {
return {
url: config.service('platform/api/v1/Site/GetOrgan'),
model: {
organ: null,
building: null,
expanded: [],
},
events: [
'OrganEntityInserted',
'OrganEntityUpdated',
'OrganEntityDeleted',
'BuildingEntityInserted',
'BuildingEntityUpdated',
'BuildingEntityDeleted',
'IoTSceneEntityInserted',
'IoTSceneEntityUpdated',
'IoTSceneEntityDeleted',
'IoTDeviceEntityInserted',
'IoTDeviceEntityUpdated',
'IoTDeviceEntityDeleted',
'IoTDataEntityInserted',
'IoTDataEntityUpdated',
'IoTDataEntityDeleted',
]
};
},
mounted: function () {
this.subscribe();
this.load();
},
beforeDestroy: function () {
PubSub.unsubscribes(this.events);
},
methods: {
subscribe: function () {
var parent = this;
PubSub.subscribes(this.events, function (method, data) {
if (method.indexOf('Statistic') !== -1 || method.indexOf('Organ') !== -1 || method.indexOf('Building') !== -1) {
parent.load();
}
else {
parent.updateItem(method, data);
}
});
},
load: function () {
var parent = this;
axios.post(this.url).then(function (response) {
parent.model.organ = response.data;
});
},
updateItem: function (method, data) {
if (this.model.building) {
var item = JSON.parse(data.message);
var list;
if (method.indexOf('Device') !== -1)
{
var gateway = Enumerable.from(this.model.building.building.ioTGateways).where(o => o.id == item.ioTGatewayId).firstOrDefault();
if (gateway) {
list = gateway.devices;
}
}
else if (method.indexOf('Data') !== -1) {
var device = Enumerable.from(this.model.building.building.ioTGateways)
.selectMany(o => o.devices)
.firstOrDefault(function (o) { return o.id === item.ioTDeviceId; });
if (device) {
list = device.data;
}
}
else if (method.indexOf('Scene') !== -1) {
if (this.model.building && this.model.building.building.id === item.buildingId) {
list = this.model.building.building.scenes;
}
}
//
if (list) {
if (method.indexOf('Deleted') !== -1) {
removeById(list, item);
}
else {
updateById(list, item);
}
}
}
},
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.service('platform/api/v1/Site/GetBuilding?id=' + id);
axios.post(url).then(function (response) {
parent.model.building = response.data;
});
}
}
},
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) {
return this.findBuildings(item.children, id);
}
}
}
},
computed: {
tree: function () {
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;
},
scenes: function () {
var result = [];
if (this.model.building) {
result = Enumerable.from(this.model.building.building.scenes).orderBy(o => o.order).toArray();
}
return result;
},
devices: function () {
var result = [];
if (this.model.building) {
result = Enumerable.from(this.model.building.building.ioTGateways)
.selectMany(o => o.devices)
.where(o => !o.disabled)
.orderBy(o => o.ioTProductId)
.toArray();
}
return result;
}
}
};
</script>

@ -10,7 +10,7 @@
<a class="nav-link" data-widget="pushmenu" href="#"><i class="fas fa-bars"></i></a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<router-link to="/" :class="getLinkClass('default','/')">首页</router-link>
<router-link to="/" :class="getLinkClass()">首页</router-link>
</li>
<li v-for="item in getModules()">
<router-link :to="getPath(item.number)" :class="getLinkClass(item.number,getPath(item.number))">{{item.name}}</router-link>
@ -47,7 +47,10 @@
<template v-if="getArea()==='default'">
<li class="nav-header">智慧校园</li>
<li class="nav-item">
<router-link to="/" :class="getLinkClass('default','/')"><i class="far fa-circle nav-icon"></i><p>首页</p></router-link>
<router-link to="/" :class="getLinkClass('default','/')"><i class="far fa-circle nav-icon"></i><p>机构概览</p></router-link>
</li>
<li class="nav-item">
<router-link :to="viewPath+'default/product.vue'" :class="getLinkClass('default','/product.vue')"><i class="far fa-circle nav-icon"></i><p>设备中心</p></router-link>
</li>
</template>
<template v-else>
@ -128,7 +131,7 @@
if (response.status === 200) {
store.commit('login', response.data);
setTimeout(function () {
router.push({ path: '/components/views/shared/redirect.vue', query: { url: router.currentRoute.fullPath,message:'正在切换当前机构' } });
router.push({ path: '/components/views/shared/redirect.vue', query: { url: router.currentRoute.fullPath, message: '正在切换当前机构' } });
}, 1000);
}
else if (response.status === 400) {
@ -138,12 +141,12 @@
});
},
getArea: function () {
var path = this.$route.path === '/' ? (this.viewPath + 'default/index.html') : this.$route.path;
var path = this.$route.path === '/' ? (this.viewPath + 'default/index.vue') : this.$route.path;
path = path.substr(this.viewPath.length);
return path === '/' ? 'default' : path.substr(0, path.indexOf('/'));
},
getPath: function (area) {
return this.viewPath + area + '/index.html';
return this.viewPath + area + '/index.vue';
},
getModules: function () {
var numbers = Enumerable.from(store.state.layout.user.claims).where(o => o.type === store.state.layout.user.roleClaimType).select(o => o.value).toArray();
@ -163,17 +166,29 @@
.toArray()
return permissions;
},
getLinkClass: function (area) {
var cls = 'nav-link';
getLinkClass: function (area, view) {
area = area || 'default';
var mapView = view ? true : false;
view = view || '/';
view = view === '/' ? '/index.vue' : view;
var path = this.$route.path;
if (area === "default" && path === '/') {
cls += ' active';
}
else {
if (path.indexOf(this.viewPath + area) === 0) {
var currentArea = this.getArea();
var currentView = path === '/' ? (this.viewPath + area + '/index.vue') : path;
var cls = 'nav-link';
if (area === currentArea) {
if (!mapView) {
cls += ' active';
}
else {
if (currentView === (this.viewPath + area + view)) {
cls += ' active';
}
}
}
console.warn('area:' + area + ',currentArea:' + currentArea + ',view:' + view + ',currentView:' + currentView + ',route path:' + this.$route.path);
return cls;
}
}

Loading…
Cancel
Save