Former-commit-id: cd1a1b9f161985409f02721be3006e059e6b66c3
Former-commit-id: 39613c0faddef20ccbbb924302cae2fe18e89fa3
1.0
wanggang 4 years ago
parent 4e5fb2e10b
commit a0b267dfb3

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading;
namespace IoTNode.Controllers
{
@ -18,51 +19,19 @@ namespace IoTNode.Controllers
this._deviceService = deviceService;
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse SetBrightness([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("亮度"), Range(0, 255), Required] int brightness)
{
if (number is null)
{
throw new ArgumentNullException(nameof(number));
}
try
{
var values = number.Split('-');
this._deviceService.X83(values[0], values[1], (byte)brightness);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse SetColor([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("色调"), Range(0, 255), Required] int hue, [SwaggerParameter("饱和度"), Range(0, 255), Required] int saturation)
{
try
{
var values = number.Split('-');
this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse Change([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("亮度"), Range(0, 255), Required] int brightness, [SwaggerParameter("色调"), Required][Range(0, 255)] int hue, [SwaggerParameter("饱和度"), Range(0, 255), Required] int saturation)
{
try
{
var values = number.Split('-');
this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation);
this._deviceService.X83(values[0], values[1], (byte)brightness);
var sn = values[0];
var ieee = values[1];
this._deviceService.X84(sn, ieee, (byte)hue, (byte)saturation);
this._deviceService.X83(sn, ieee, (byte)brightness);
Thread.Sleep(100);
this._deviceService.X87(sn, ieee);
this._deviceService.X86(sn, ieee);
}
catch (Exception ex)
{

@ -422,7 +422,7 @@ namespace IoTNode.DeviceServices.FBee
//deviceRepo.SaveChanges();
//var deviceDto = device.To<EditDeviceModel>();
//this.SendToServer(Methods.EditDevice, deviceDto);
//this.UpdateStatus(device);
this.UpdateStatus(device);
}
else
{

@ -1,4 +1,22 @@
var app = new Vue({
PubSub.subscribes = function (events, action) {
if (!events || !action) {
return;
}
for (var i = 0; i < events.length; i++) {
PubSub.subscribe(events[i], function (m, d) { action(m, d); });
}
}
PubSub.unsubscribes = function (events) {
if (!events) {
return;
}
for (var i = 0; i < events.length; i++) {
PubSub.unsubscribe(events[i]);
}
}
//
var app = new Vue({
el: '#app',
data() {
return {

@ -10,6 +10,7 @@
{
<router-view></router-view>
@section scripts{
<script src="/js/config.js"></script>
<script src="/js/app.js"></script>
<script src="/js/main.js"></script>
}

@ -13,7 +13,7 @@
<div class="card-body">
<div class="row">
<div class="col-4 align-self-center">
<div :style="'width:48px;height:48px;border-radius: 24px;background:'+hsl"></div>
<div :style="'width:48px;height:48px;border-radius: 24px;background:'+hsl+';'"></div>
</div>
<div class="col-8 align-self-center">
<div class="row">
@ -30,9 +30,20 @@
<img style="height:32px;margin:0 auto;" v-else v-on:click="execApi(device.number,'/Socket/On')" src="/platform/images/off.svg" />
</div>
<div class="row text-center">
<label style="width:100%;">色调:<input @change="changeHue($event.target.value)" type="range" min="0" step="1" max="255" name="hue" :value="hue" style="height:5px;margin:5px auto;-webkit-appearance:none;background: -webkit-linear-gradient(left, #F00 0%, #FF0 16.66%, #0F0 33.33%, #0FF 50%,#00F 66.66%, #F0F 83.33%, #F00 100%);" /></label>
<label style="width:100%;">色度:<input @change="changeSaturation($event.target.value)" type="range" min="0" step="1" max="254" name="saturation" :value="saturation" :style="'height:5px;margin:5px auto;-webkit-appearance:none;background: -webkit-linear-gradient(left, #fff 0%, '+color+' 100%);'" /></label>
<label style="width:100%;">亮度:<input @change="changeBrightness($event.target.value)" type="range" min="0" step="1" max="254" name="brightness" :value="brightness" style="height:5px;margin:5px auto;-webkit-appearance:none;background: -webkit-linear-gradient(left, #000 0%, #fff 100%);" /></label>
<table style="margin:0 auto;">
<tr>
<td style="text-align:right;">色调:</td>
<td><input @change="changeHue($event.target.value)" type="range" min="0" step="1" max="255" name="hue" :value="hue" style="outline:none;height: 5px; margin: 5px auto; -webkit-appearance: none; background: -webkit-linear-gradient(left, #F00 0%, #FF0 16.66%, #0F0 33.33%, #0FF 50%,#00F 66.66%, #F0F 83.33%, #F00 100%);" /></td>
</tr>
<tr>
<td style="text-align:right;">饱和度:</td>
<td><input @change="changeSaturation($event.target.value)" type="range" min="0" step="1" max="254" name="saturation" :value="saturation" :style="'outline:none;height:5px;margin:5px auto;-webkit-appearance:none;background: -webkit-linear-gradient(left, #fff 0%, '+color+' 100%);'" /></td>
</tr>
<tr>
<td style="text-align:right;">亮度:</td>
<td><input @change="changeBrightness($event.target.value)" type="range" min="0" step="1" max="254" name="brightness" :value="brightness" style="outline: none; height: 5px; margin: 5px auto; -webkit-appearance: none; background: -webkit-linear-gradient(left, #000 0%, #fff 100%);" /></td>
</tr>
</table>
</div>
</a-modal>
</div>
@ -47,7 +58,7 @@
},
methods: {
changeHue: function (hue) {
execApi(this.device.number, '/ColorLight/Change', 'hue=' + hue + '&saturation=' + this.saturation + '&brightness=' + this.brightness);
execApi(this.device.number, '/ColorLight/Change', 'hue=' + hue + '&saturation=' + 254 + '&brightness=' + this.brightness);
},
changeSaturation: function (saturation) {
execApi(this.device.number, '/ColorLight/Change', 'hue=' + this.hue + '&saturation=' + saturation + '&brightness=' + this.brightness);
@ -76,12 +87,17 @@
return result;
},
hsl: function () {
var h = Math.round(parseInt(this.hue || 128) * 360 / 255);
var h = Math.round(parseInt(this.hue || 128) * 360 / 254);
var s = Math.round(parseInt(this.saturation || 128) * 100 / 254);
var l = Math.round(parseInt(this.brightness || 128) * 100 / 254);
var result = 'hsl(' + h + ',' + s + '%,' + l + '%);';
console.log('hsl:' + result);
var result = 'hsl(' + h + ',' + s + '%,' + l + '%)';
console.warn('raw:'+this.hue+' '+this.saturation+' '+this.brightness);
console.warn('hsl:' + result);
return result;
},
color: function () {
var h = Math.round(parseInt(this.hue || 128) * 360 / 254);
return 'hsl(' + h + ',100%,0%)';
}
}
};

@ -91,7 +91,7 @@ function getIoTDataDescription(device, name) {
//调用API
function execApi(number, method, query) {
loading.show();
axios.post(config.service('platform') + 'api/v1/api/execApi', { connectionId, number, method, query })
axios.post(config.service('platform/api/v1/api/execApi'), { connectionId, number, method, query })
.then(function (response) {
})
.catch(function (error) {
@ -104,7 +104,7 @@ function execApi(number, method, query) {
//调用场景
function execScene(id) {
loading.show();
axios.post(config.service('platform') + 'api/v1/api/execScene', { id, connectionId })
axios.post(config.service('platform/api/v1/api/execScene'), { id, connectionId })
.then(function (response) {
console.log(response);
})

@ -10,6 +10,6 @@ const config = {
},
gateway: 'http://example_gateway_host/',
service: function (service) {
return (this.crossDomain ? this.gateway : '/') + service + '/';
return (this.crossDomain ? this.gateway : '/') + service;
}
};
Loading…
Cancel
Save