You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
using CommunityToolkit.Mvvm.Messaging;
|
|
using SunlightAggregationTerminal.View;
|
|
using ZXing.Multi;
|
|
using ZXing.Net.Maui;
|
|
using ZXing.QrCode.Internal;
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
public partial class ScanPage : ContentPage
|
|
{
|
|
private int mode;
|
|
public ScanPage(int i)
|
|
{
|
|
InitializeComponent();
|
|
mode = i;
|
|
}
|
|
private async void OnBarcodesDetected(object sender, BarcodeDetectionEventArgs e)
|
|
{
|
|
var firstResult = e.Results?.FirstOrDefault();
|
|
if (firstResult is not null)
|
|
{
|
|
barcodeReader.IsDetecting = false;
|
|
|
|
// 触发回调
|
|
if (mode == 0)
|
|
{
|
|
MainThread.BeginInvokeOnMainThread(() =>
|
|
{
|
|
// 震动
|
|
try { Vibration.Default.Vibrate(TimeSpan.FromMilliseconds(100)); } catch { }
|
|
// 传入信息
|
|
WeakReferenceMessenger.Default.Send(firstResult.Value);
|
|
// 等待 1.5 秒(非阻塞,界面不会卡死)
|
|
Task.Delay(1500);
|
|
// 关闭页面
|
|
Navigation.PopAsync();
|
|
});
|
|
}
|
|
if (mode == 3)
|
|
{
|
|
MainThread.BeginInvokeOnMainThread(() =>
|
|
{
|
|
try { Vibration.Default.Vibrate(TimeSpan.FromMilliseconds(100)); } catch { }
|
|
WeakReferenceMessenger.Default.Send(firstResult.Value);
|
|
Task.Delay(1500);
|
|
// 关闭页面
|
|
Navigation.PopModalAsync();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|