Merge branch 'master' of http://192.168.0.12:13000/sc/SunlightAggregationTerminal
This commit is contained in:
commit
ee00cfd25f
6 files changed
+209
-36
No files matched your search
+14
-9
@@ -69,11 +69,11 @@ namespace SunlightAggregationTerminal.Class
|
||||
#region Tcp客户端使用Received异步委托接收数据
|
||||
tcpClient.Received = (client, e) =>
|
||||
{
|
||||
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
||||
var mes = e.Memory.Span.ToString(Encoding.UTF8);
|
||||
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
||||
var mes = e.Memory.Span.ToString(Encoding.UTF8);
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<Dictionary<string, object>>(mes);
|
||||
|
||||
if (data != null)
|
||||
@@ -95,7 +95,11 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
|
||||
|
||||
if (data.TryGetValue("Notification", out val) && val != null)//信息接受
|
||||
if (data.TryGetValue("Query", out val) && val != null)//查询接受
|
||||
{
|
||||
QueryPage.Query_data(val.ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受
|
||||
{
|
||||
var dataNotification = JsonSerializer.Deserialize<Dictionary<string, object>>(val.ToString()!);
|
||||
|
||||
@@ -126,20 +130,21 @@ namespace SunlightAggregationTerminal.Class
|
||||
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + _Type + "');");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
|
||||
return EasyTask.CompletedTask;
|
||||
};
|
||||
#endregion
|
||||
|
||||
try
|
||||
{
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetRemoteIPHost(ip));
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetRemoteIPHost(ip));
|
||||
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
|
||||
} catch (Exception)
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", "不合法的访问地址", "是");
|
||||
}
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ namespace SunlightAggregationTerminal.Models
|
||||
|
||||
//发生登录请求
|
||||
|
||||
// 创建一个 5 秒的延时任务
|
||||
// 创建一个 15 秒的延时任务
|
||||
Task delayTask = Task.Delay(15000);
|
||||
// 创建一个监测任务,不断检查变量
|
||||
Task monitorTask = Task.Run(async () =>
|
||||
|
||||
@@ -23,6 +23,15 @@ namespace SunlightAggregationTerminal.Models
|
||||
public DateTime Time { get; set; }
|
||||
public MsgType Type { get; set; }
|
||||
}
|
||||
public class DyelotItem
|
||||
{
|
||||
public string? Dyelot { get; set; }
|
||||
public string? Machine { get; set; }
|
||||
public string? CreationTime { get; set; }
|
||||
public string? FabricName { get; set; }
|
||||
public string? ColorName { get; set; }
|
||||
public string? CustomerName { get; set; }
|
||||
}
|
||||
|
||||
public static class DataService
|
||||
{
|
||||
|
||||
@@ -17,14 +17,13 @@ public partial class MessagePage : ContentPage
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
// 假设这是你获取数据的地方
|
||||
var allData = DataService._NotificationData;
|
||||
if (allData != null)
|
||||
{
|
||||
// 清空旧数据
|
||||
MessageItems.Clear();
|
||||
|
||||
// 按时间倒序,并只取最新的 N 条(例如 50 条)
|
||||
// 按时间倒序,并只取最新的 50 条
|
||||
var itemsToShow = allData.OrderByDescending(x => x.Time).Take(50).Where(x => x.Type == MsgType.Message);
|
||||
|
||||
// 将数据添加到集合中,UI 会自动更新
|
||||
|
||||
+124
-14
@@ -3,8 +3,10 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="SunlightAggregationTerminal.QueryPage"
|
||||
Title="">
|
||||
<Grid RowDefinitions="Auto, *" ColumnDefinitions="*, Auto">
|
||||
<Border Grid.Row="0"
|
||||
<Grid>
|
||||
<VerticalStackLayout>
|
||||
<Grid RowDefinitions="Auto, *" ColumnDefinitions="*, Auto">
|
||||
<Border Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Stroke="#CCCCCC"
|
||||
StrokeThickness="1"
|
||||
@@ -13,7 +15,7 @@
|
||||
Padding="0,0"
|
||||
VerticalOptions="Center"
|
||||
Margin="10,10,0,10">
|
||||
<Entry x:Name="ResultEntry"
|
||||
<Entry x:Name="ResultEntry"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontSize="Medium"
|
||||
@@ -21,23 +23,131 @@
|
||||
VerticalOptions="Center"
|
||||
BackgroundColor="Transparent"
|
||||
Margin="0,0,0,0" >
|
||||
</Entry>
|
||||
</Border>
|
||||
<!--扫码按钮-->
|
||||
<Button Grid.Row="0"
|
||||
</Entry>
|
||||
</Border>
|
||||
<!--扫码按钮-->
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Clicked="OnScanButtonClicked"
|
||||
BackgroundColor="Transparent"
|
||||
WidthRequest="60"
|
||||
HeightRequest="60"
|
||||
Margin="10">
|
||||
<Button.ImageSource>
|
||||
<!-- 设置图标 -->
|
||||
<FileImageSource File="lucidescanline.png" />
|
||||
</Button.ImageSource>
|
||||
</Button>
|
||||
<VerticalStackLayout>
|
||||
|
||||
<Button.ImageSource>
|
||||
<!-- 设置图标 -->
|
||||
<FileImageSource File="lucidescanline.png" />
|
||||
</Button.ImageSource>
|
||||
</Button>
|
||||
</Grid>
|
||||
<StackLayout >
|
||||
|
||||
<HorizontalStackLayout>
|
||||
<DatePicker Format="yyyy年MM月dd日" FontSize="18"/>
|
||||
<Label Text="~" FontSize="32"/>
|
||||
<DatePicker Format="yyyy年MM月dd日" FontSize="18"/>
|
||||
<Button Text="搜索" Margin="5"/>
|
||||
</HorizontalStackLayout>
|
||||
|
||||
</StackLayout>
|
||||
|
||||
<Grid>
|
||||
<CollectionView x:Name="CardCollectionView"
|
||||
ItemsSource="{Binding DyelotItems}"
|
||||
RemainingItemsThreshold="5">
|
||||
<!-- 保持滚动条 -->
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<!-- 这里定义单个卡片的 UI 结构 -->
|
||||
<Border BackgroundColor="White"
|
||||
Stroke="#CCCCCC" StrokeThickness="1"
|
||||
Margin="10,0,10,10" StrokeShape="RoundRectangle 10">
|
||||
<Grid Padding="15">
|
||||
<VerticalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="工单: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding Dyelot}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="机台: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding Machine}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="下单时间: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding CreationTime}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="面料: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding FabricName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="颜色: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding ColorName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="客户: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding CustomerName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
|
||||
</HorizontalStackLayout>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
<Border.GestureRecognizers>
|
||||
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
|
||||
</Border.GestureRecognizers>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
|
||||
|
||||
<CollectionView ItemsSource="{Binding Items}" IsVisible="False">
|
||||
<CollectionView.Header>
|
||||
<!-- 表头 -->
|
||||
<Grid BackgroundColor="Gray" Padding="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Text="步骤" TextColor="White" FontAttributes="Bold" Grid.Column="0"/>
|
||||
<Label Text="物料" TextColor="White" FontAttributes="Bold" Grid.Column="1"/>
|
||||
<Label Text="状态" TextColor="White" FontAttributes="Bold" Grid.Column="2"/>
|
||||
<Label Text="实际" TextColor="White" FontAttributes="Bold" Grid.Column="3"/>
|
||||
<Label Text="时间" TextColor="White" FontAttributes="Bold" Grid.Column="4"/>
|
||||
</Grid>
|
||||
</CollectionView.Header>
|
||||
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<!-- 数据行 -->
|
||||
<Grid Padding="10" ColumnDefinitions="*,2*,*,*,*">
|
||||
<Label Text="{Binding Id}" Grid.Column="0"/>
|
||||
<Label Text="{Binding Name}" Grid.Column="1"/>
|
||||
<Label Text="{Binding Start}" Grid.Column="2"/>
|
||||
<Label Text="{Binding Value}" Grid.Column="3"/>
|
||||
<Label Text="{Binding date}" Grid.Column="4"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</Grid>
|
||||
</VerticalStackLayout>
|
||||
<!-- 查询中动画页面 -->
|
||||
<Grid x:Name="LoadingIndicator" BackgroundColor="Gray"
|
||||
IsVisible="False" Opacity="0.9">
|
||||
<VerticalStackLayout Padding="30" Spacing="10"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center">
|
||||
<ActivityIndicator IsRunning="True"
|
||||
Color="#512BD4"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center" />
|
||||
<Label Text="查询中..."
|
||||
FontAttributes="Bold"
|
||||
FontSize="24"
|
||||
TextColor="Black"/>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
+60
-10
@@ -1,11 +1,15 @@
|
||||
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 Action<string>? OnScanQuery;
|
||||
public static ObservableCollection<DyelotItem> DyelotItems { get; set; } = new();
|
||||
|
||||
public QueryPage()
|
||||
{
|
||||
@@ -22,17 +26,63 @@ public partial class QueryPage : ContentPage
|
||||
await Navigation.PushAsync(new ScanPage(0));
|
||||
}
|
||||
|
||||
// 处理“回车/完成”按钮点击
|
||||
/* private void OnEntryCompleted()
|
||||
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
|
||||
{
|
||||
string inputText = ResultEntry.Text;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(inputText))
|
||||
}
|
||||
|
||||
//信息回复
|
||||
public static void Query_data(string dat)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 在这里处理用户手动输入的内容
|
||||
// 例如:验证格式、跳转页面、或者搜索商品
|
||||
//DisplayAlert("提示", $"你输入了: {inputText}", "确定");
|
||||
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}", "确定");
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user