!2383 feat(#I4SLOR): add OnDeviceChanged parameter on BarcodeReader component

* doc: 更新 OnDeviceChanged 说明文档
* doc: 更新资源文件
* feat: 增加 OnDeviceChanged 回调方法
This commit is contained in:
Argo 2022-02-03 16:24:06 +00:00
parent 3b180b956d
commit f28347dc59
5 changed files with 137 additions and 115 deletions

View File

@ -1889,6 +1889,7 @@
"OnStart": "Turn on the camera callback method",
"OnClose": "Turn off the camera callback method",
"OnError": "An error callback method occurred",
"OnDeviceChanged": "switch camera device callback method",
"InitLog": "Initialize the camera to complete",
"ScanCodeLog": "Scan to barcode",
"ErrorLog": "An error has occurred",

View File

@ -1891,6 +1891,7 @@
"OnStart": "打开摄像头回调方法",
"OnClose": "关闭摄像头回调方法",
"OnError": "发生错误回调方法",
"OnDeviceChanged": "设别切换时回调方法",
"InitLog": "初始化摄像头完成",
"ScanCodeLog": "扫描到条码",
"ErrorLog": "发生错误",

View File

@ -66,117 +66,125 @@ public sealed partial class BarcodeReaders
/// <returns></returns>
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
new AttributeItem()
{
Name = "ButtonScanText",
Description = Localizer["ButtonScanText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["ButtonScanTextDefaultValue"]
},
new AttributeItem()
{
Name = "ButtonStopText",
Description = Localizer["ButtonStopText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["ButtonStopTextDefaultValue"]
},
new AttributeItem()
{
Name = "AutoStopText",
Description = Localizer["AutoStopText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["AutoStopTextDefaultValue"]
},
new AttributeItem()
{
Name = "DeviceLabel",
Description = Localizer["DeviceLabel"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["DeviceLabelDefaultValue"]
},
new AttributeItem()
{
Name = "InitDevicesString",
Description = Localizer["InitDevicesString"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["InitDevicesStringDefaultValue"]
},
new AttributeItem()
{
Name = "NotFoundDevicesString",
Description = Localizer["NotFoundDevicesString"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["NotFoundDevicesStringDefaultValue"]
},
new AttributeItem()
{
Name = "AutoStart",
Description = Localizer["AutoStart"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new AttributeItem()
{
Name = "AutoStop",
Description = Localizer["AutoStart"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new AttributeItem()
{
Name = "ScanType",
Description = "",
Type = "ScanType",
ValueList = "Camera|Image",
DefaultValue = "Camera"
},
new AttributeItem()
{
Name = "OnInit",
Description = Localizer["OnInit"],
Type = "Func<IEnumerable<Camera>, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnResult",
Description = Localizer["OnResult"],
Type = "Func<string, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnStart",
Description = Localizer["OnStart"],
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnClose",
Description = Localizer["OnClose"],
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnError",
Description = Localizer["OnError"],
Type = "Func<string, Task>",
ValueList = " — ",
DefaultValue = " — "
}
new AttributeItem()
{
Name = "ButtonScanText",
Description = Localizer["ButtonScanText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["ButtonScanTextDefaultValue"]
},
new AttributeItem()
{
Name = "ButtonStopText",
Description = Localizer["ButtonStopText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["ButtonStopTextDefaultValue"]
},
new AttributeItem()
{
Name = "AutoStopText",
Description = Localizer["AutoStopText"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["AutoStopTextDefaultValue"]
},
new AttributeItem()
{
Name = "DeviceLabel",
Description = Localizer["DeviceLabel"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["DeviceLabelDefaultValue"]
},
new AttributeItem()
{
Name = "InitDevicesString",
Description = Localizer["InitDevicesString"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["InitDevicesStringDefaultValue"]
},
new AttributeItem()
{
Name = "NotFoundDevicesString",
Description = Localizer["NotFoundDevicesString"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["NotFoundDevicesStringDefaultValue"]
},
new AttributeItem()
{
Name = "AutoStart",
Description = Localizer["AutoStart"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new AttributeItem()
{
Name = "AutoStop",
Description = Localizer["AutoStart"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new AttributeItem()
{
Name = "ScanType",
Description = "",
Type = "ScanType",
ValueList = "Camera|Image",
DefaultValue = "Camera"
},
new AttributeItem()
{
Name = "OnInit",
Description = Localizer["OnInit"],
Type = "Func<IEnumerable<Camera>, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnResult",
Description = Localizer["OnResult"],
Type = "Func<string, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnStart",
Description = Localizer["OnStart"],
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnClose",
Description = Localizer["OnClose"],
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnError",
Description = Localizer["OnError"],
Type = "Func<string, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = "OnDeviceChanged",
Description = Localizer["OnDeviceChanged"],
Type = "Func<DeviceItem, Task>",
ValueList = " — ",
DefaultValue = " — "
}
};
}

View File

@ -14,7 +14,7 @@
<Checkbox DisplayText="@AutoStopText" ShowAfterLabel="true" @bind-Value="@AutoStop" class="mt-3" />
</div>
<div class="col-12 scanner-devices">
<Select Items="@Devices" @bind-Value="@DeviceId" DisplayText="@DeviceLabel" ShowLabel="true" placeholder="@InitDevicesString" />
<Select TValue="string" Items="@Devices" DisplayText="@DeviceLabel" OnSelectedItemChanged="OnSelectedItemChanged" ShowLabel="true" placeholder="@InitDevicesString" />
</div>
<div class="col-12 scanner-video">
<video id="@GetHashCode()"></video>

View File

@ -67,6 +67,12 @@ public partial class BarcodeReader : IAsyncDisposable
[Parameter]
public ScanType ScanType { get; set; }
/// <summary>
/// 获得/设置 摄像头设备切换回调方法 默认 null
/// </summary>
[Parameter]
public Func<DeviceItem, Task>? OnDeviceChanged { get; set; }
/// <summary>
/// 获得/设置 初始化摄像头回调方法
/// </summary>
@ -109,8 +115,6 @@ public partial class BarcodeReader : IAsyncDisposable
[Parameter]
public Func<Task>? OnClose { get; set; }
private string DeviceId { get; set; } = "";
private ElementReference ScannerElement { get; set; }
private IEnumerable<SelectedItem> Devices { get; set; } = Enumerable.Empty<SelectedItem>();
@ -206,6 +210,14 @@ public partial class BarcodeReader : IAsyncDisposable
if (OnClose != null) await OnClose.Invoke();
}
private async Task OnSelectedItemChanged(SelectedItem item)
{
if (OnDeviceChanged != null)
{
await OnDeviceChanged(new DeviceItem() { DeviceId = item.Value, Label = item.Text });
}
}
/// <summary>
/// DisposeAsyncCore 方法
/// </summary>