pc端设备详情页自定义红外指令

Former-commit-id: f9be88fe7633fafb40625d4af1e59ef89df26f98
TangShanKaiPing
wanggang 6 years ago
parent 7036fbc94a
commit 511706a9c3

@ -473,6 +473,41 @@
</form>
</div>
<div class="tab-pane" :id="'tab_4'+model.Number">
<form class="ir type3" method="get" action="/App/ExecApi">
<input type="hidden" name="Number" :value="model.Number" />
<input type="hidden" name="Method" value="/Ir/Send" />
<input type="hidden" name="Type" value="5" />
<div class="row">
<div class="col-md-12 col-xs-12">
<label v-for="btn in GetButtons()" class="btn btn-sm btn-success"><input v-on:click="SendCode1($event)" name="Code" type="radio" :value="btn.Value" />{{btn.Key}}</label>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">自定义指令</h3>
</div>
<div class="card-body">
<div id="irbuttons">
<div class="row button" v-for="btn in GetButtons()">
<label>按键名称:</label>
<input type="text" name="key" :value="btn.Key" v-on:change="UpdateButton($event,btn.key)" />
<label>按键编码:</label>
<input type="text" name="value" :value="btn.Value" v-on:change="UpdateButton($event,btn,key)" />
<button class="btn btn-sm btn-success" v-on:click="Study(btn.Value)">学习</button>
<button class="btn btn-sm btn-success" v-on:click="RemoveButton(btn.Key)">移除</button>
</div>
<div class="row">
<button class="btn btn-sm btn-success" v-on:click="AddButton()">添加</button>
<button class="btn btn-sm btn-success" v-on:click="SaveButtons()">保存</button>
</div>
</div>
</div>

@ -70,6 +70,47 @@ methods = {
ajax(url, null, 'get');
});
},
GetButtons() {
return Enumerable.from(JSON.parse(this.GetDataValue("指令")))
//.orderBy(function (o) { return o.Value; })
.toArray();
},
Study(code) {
ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: this.model.Number, method: "/Ir/Study", type: 5,code:code }, 'post');
},
AddButton() {
var data = Enumerable.from(this.model.Data)
.where(function (o) { return o.Name === "指令" })
.firstOrDefault();
var buttons = this.GetButtons();
var newBtn = { Key:"测试", Value:603};
buttons.push(newBtn);
data.Value = JSON.stringify(buttons);
},
RemoveButton(key) {
var data = Enumerable.from(this.model.Data)
.where(function (o) { return o.Name === "指令" })
.firstOrDefault();
var buttons = this.GetButtons();
for (var i = buttons.length - 1; i >= 0; i--) {
if (buttons[i].Key == key) {
buttons.splice(i, 1);
break;
}
}
data.Value = JSON.stringify(buttons);
},
SaveButtons() {
var buttons = [];
$('#irbuttons').find('.button').each(function () {
buttons.push({
Key: $(this).find("input[name='key']").val(),
Value: $(this).find("input[name='value']").val()
});
});
var value = JSON.stringify(buttons);
ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: this.model.Number, method: "/Ir/Buttons", buttons: value }, 'post');
},
SendCode1(event) {
console.log(event.target + ',' + event.type + ',' + event.target.checked);
var form = $(event.target).parents('form');

@ -30,7 +30,7 @@ namespace IoTNode.Controllers
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse Study([SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值"), Required, Range(1, 10)]ushort code)
public ApiResponse Study([SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值"), Required, Range(603, 703)]ushort code)
{
return this.AsyncAction(() =>
{
@ -38,5 +38,14 @@ namespace IoTNode.Controllers
this._deviceService.XA70083(values[0], values[1], type, code);
});
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse Buttons([SwaggerParameter("设备编号")]string number, [SwaggerParameter("指令")]string buttons)
{
return this.AsyncAction(() =>
{
this._deviceService.UpdateButtons(number, buttons);
});
}
}
}

@ -55,6 +55,27 @@ namespace IoTNode.DeviceServices.FBee
return base.StartAsync(cancellationToken);
}
public void UpdateButtons(string number, string buttons)
{
using (var scope = _applicationServices.CreateScope())
{
var deviceRepo = scope.ServiceProvider.GetService<IRepository<Device>>();
var device = deviceRepo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == number);
if (device != null)
{
var data = device.Data.FirstOrDefault(o => o.Key == Keys.Buttons);
if (data != null)
{
data.Value = buttons.FromJson<List<KeyValuePair<string, int>>>().ToJson();
if (deviceRepo.SaveChanges() > 0)
{
this.SendDataToServer(data);
}
}
}
}
}
public override void Execute()
{
var ips = NetworkInterface.GetAllNetworkInterfaces()
@ -480,6 +501,7 @@ namespace IoTNode.DeviceServices.FBee
var deviceRepo = scope.ServiceProvider.GetService<IRepository<Device>>();
var device = this.GetDevice(deviceRepo, sn, ieee);
var online = isOnline != 0x00;
if (device == null)
{
device = new Device
@ -493,9 +515,19 @@ namespace IoTNode.DeviceServices.FBee
NodeId = node.Id
};
deviceRepo.Add(device);
device.IsOnline = online;
this.UpdateDevice(deviceRepo, device);
if (device.Name == "红外转发器")
{
var buttons = new List<KeyValuePair<string, int>>() { new KeyValuePair<string, int>("测试", 603) }.ToJson();
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Buttons, buttons, DeviceDataType.String, "指令", timestamp: timestamp));
}
}
else
{
device.IsOnline = online;
this.UpdateDevice(deviceRepo, device);
}
device.IsOnline = isOnline != 0x00;
this.UpdateDevice(deviceRepo, device);
this.UpdateData(deviceRepo, device, device.CreateData(Keys.DeviceId, deviceId, DeviceDataType.Int, Keys.DeviceId, hidden: true, timestamp: timestamp));
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Address, address, DeviceDataType.String, Keys.Address, hidden: true, timestamp: timestamp));
this.UpdateData(deviceRepo, device, device.CreateData(Keys.EndPoint, endpoint, DeviceDataType.Int, Keys.EndPoint, hidden: true, timestamp: timestamp));

@ -13,6 +13,7 @@
public const string L2State = "L2State";
public const string L3State = "L3State";
public const string Battery = "Battery";
public const string Buttons = "Buttons";
public const string EndPointCount = "EndPointCount";
public const string Data = "Data";
public const string ZoneType = "ZoneType";

Loading…
Cancel
Save