diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index f5103661..e732bf68 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -206,23 +206,47 @@ namespace IoTCenter.Controllers public IActionResult AllPowerOn(string connectionId, string[] nodes) { - this.Power(connectionId, nodes, "On"); + this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关") || o.Name.Contains("插座")); return Json(ApiResponse.AsyncSuccess()); } public IActionResult AllPowerOff(string connectionId, string[] nodes) { - this.Power(connectionId, nodes, "Off"); + this.Power(connectionId, nodes, "Off", o => o.Name.Contains("开关") || o.Name.Contains("插座")); return Json(ApiResponse.AsyncSuccess()); } - private void Power(string connectionId, string[] nodes, string command) + public IActionResult AllSwitchOn(string connectionId, string[] nodes) + { + this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult AllSwitchOff(string connectionId, string[] nodes) + { + this.Power(connectionId, nodes, "Off", o => o.Name.Contains("开关")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult AllSocketOn(string connectionId, string[] nodes) + { + this.Power(connectionId, nodes, "On", o => o.Name.Contains("插座")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult AllSocketOff(string connectionId, string[] nodes) + { + this.Power(connectionId, nodes, "Off", o => o.Name.Contains("插座")); + return Json(ApiResponse.AsyncSuccess()); + } + + private void Power(string connectionId, string[] nodes, string command, Func func) { var devices = this._deviceRepo.ReadOnlyTable() .Include(o => o.Node) .Include(o => o.Product.Apis) .Where(o => nodes.Contains(o.Node.Number)) - .Where(o => o.Name.Contains("开关") || o.Name.Contains("插座")) + .Where(func) .ToList(); foreach (var device in devices) { diff --git a/projects/IoTCenter/wwwroot/home.default.html b/projects/IoTCenter/wwwroot/home.default.html index 0192212e..42b14685 100644 --- a/projects/IoTCenter/wwwroot/home.default.html +++ b/projects/IoTCenter/wwwroot/home.default.html @@ -40,22 +40,22 @@
- +
- +
- +
- +
- +
- +
@@ -202,11 +202,20 @@ $('body').on('click', 'button.ajax', function (e) { var data = $.map($('.switch:checked').toArray(), function (o) { return $(o).attr('data-node-number'); }); - if ($(this).hasClass('allpoweron')) { + if ($(this).hasClass('AllPowerOn')) { ajax('/App/AllPowerOn', { nodes: data }, 'post'); - } else if ($(this).hasClass('allpoweroff')) { + } else if ($(this).hasClass('AllPowerOff')) { ajax('/App/AllPowerOff', { nodes: data }, 'post'); + } else if ($(this).hasClass('AllSwitchOn')) { + ajax('/App/AllSwitchOn', { nodes: data }, 'post'); + } else if ($(this).hasClass('AllSwitchOff')) { + ajax('/App/AllSwitchOff', { nodes: data }, 'post'); + } else if ($(this).hasClass('AllSocketOn')) { + ajax('/App/AllSocketOn', { nodes: data }, 'post'); + } else if ($(this).hasClass('AllSocketOff')) { + ajax('/App/AllSocketOff', { nodes: data }, 'post'); } + return false; });