|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using SunlightAggregationTerminal.Class;
|
|
|
|
|
using SunlightAggregationTerminal.Models;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using static SunlightAggregationTerminal.QueryPage;
|
|
|
|
|
|
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
|
|
|
|
|
|
public partial class QueryPage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
public static ObservableCollection<DyelotItem> DyelotItems { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public QueryPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Register<string>(this, (r, scannedValue) =>
|
|
|
|
|
{
|
|
|
|
|
ResultEntry.Text = scannedValue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private async void OnScanButtonClicked(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 跳转到扫码页面
|
|
|
|
|
await Navigation.PushAsync(new ScanPage(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//信息回复
|
|
|
|
|
public static void Query_data(string dat)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var data = JsonSerializer.Deserialize<List<DyelotItem>>(dat);
|
|
|
|
|
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in data)
|
|
|
|
|
{
|
|
|
|
|
DyelotItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void Query_Command(string dat)
|
|
|
|
|
{
|
|
|
|
|
LoadingIndicator.IsVisible = true;
|
|
|
|
|
DyelotItems.Clear();
|
|
|
|
|
|
|
|
|
|
TcpServer.TcpTransmit(dat);
|
|
|
|
|
|
|
|
|
|
// 创建一个 15 秒的延时任务
|
|
|
|
|
Task delayTask = Task.Delay(15000);
|
|
|
|
|
// 创建一个监测任务,不断检查变量
|
|
|
|
|
Task monitorTask = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
while (DyelotItems.Count==0)
|
|
|
|
|
{
|
|
|
|
|
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
|
|
|
|
|
await Task.Delay(100);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 使用 Task.WhenAny 等待任意一个任务完成
|
|
|
|
|
await Task.WhenAny(delayTask, monitorTask);
|
|
|
|
|
|
|
|
|
|
LoadingIndicator.IsVisible = false;
|
|
|
|
|
}
|
|
|
|
|
// 处理“回车/完成”按钮点击
|
|
|
|
|
/* private void OnEntryCompleted()
|
|
|
|
|
{
|
|
|
|
|
string inputText = ResultEntry.Text;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(inputText))
|
|
|
|
|
{
|
|
|
|
|
// 在这里处理用户手动输入的内容
|
|
|
|
|
// 例如:验证格式、跳转页面、或者搜索商品
|
|
|
|
|
//DisplayAlert("提示", $"你输入了: {inputText}", "确定");
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|