|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
|
|
|
|
|
using SunlightAggregationTerminal.Class;
|
|
|
|
|
using SunlightAggregationTerminal.Models;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
|
|
|
|
|
|
public partial class InfoPage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
public static ObservableCollection<InfoItem> InfoItems { get; set; } = new();
|
|
|
|
|
private DateTime _lastRefreshTime = DateTime.MinValue;
|
|
|
|
|
public static string? _Name, _State, _MachineName, _Machine, _Information, _Model,
|
|
|
|
|
_Type, _ModelA, _ModelB, _ModelC, _ModelD, _ModelE, _ModelF;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InfoPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
CardCollectionView.ItemsSource = InfoItems;
|
|
|
|
|
// 注册订阅一个不携带数据的消息(使用 object 作为泛型)
|
|
|
|
|
WeakReferenceMessenger.Default.Register<object>(this, (r, m) =>
|
|
|
|
|
{
|
|
|
|
|
// 收到信号,直接触发函数
|
|
|
|
|
HandleUITrigger();
|
|
|
|
|
});
|
|
|
|
|
//注册当前页面的下滑刷新
|
|
|
|
|
myRefreshView_.Refreshing += (sender, e) => {
|
|
|
|
|
// 5秒防抖判断:如果距离上次刷新不足5秒,直接取消本次操作
|
|
|
|
|
if ((DateTime.Now - _lastRefreshTime).TotalSeconds < 5)
|
|
|
|
|
{
|
|
|
|
|
myRefreshView_.IsRefreshing = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 更新刷新时间
|
|
|
|
|
_lastRefreshTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
TcpServer.TcpTransmit("{\"Command\":\"Info\"}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
private void HandleUITrigger()
|
|
|
|
|
{
|
|
|
|
|
InfoItems.Clear();
|
|
|
|
|
foreach (Dictionary<string, object> List in DataModel.Info_data)
|
|
|
|
|
{
|
|
|
|
|
if (List.TryGetValue("Name", out var val) && val != null) _Name = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("State", out val) && val != null) _State = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("MachineName", out val) && val != null) _MachineName = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("Machine", out val) && val != null) _Machine = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("Information", out val) && val != null) _Information = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("Type", out val) && val != null) _Type = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("Model", out val) && val != null) _Model = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelA", out val) && val != null) _ModelA = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelB", out val) && val != null) _ModelB = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelC", out val) && val != null) _ModelC = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelD", out val) && val != null) _ModelD = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelE", out val) && val != null) _ModelE = val.ToString()!;
|
|
|
|
|
if (List.TryGetValue("ModelF", out val) && val != null) _ModelF = val.ToString()!;
|
|
|
|
|
|
|
|
|
|
InfoItems.Add(new InfoItem
|
|
|
|
|
{
|
|
|
|
|
Name = _Name,
|
|
|
|
|
State = _State,
|
|
|
|
|
MachineName = _MachineName,
|
|
|
|
|
Machine = _Machine,
|
|
|
|
|
Information = _Information,
|
|
|
|
|
Type = _Type,
|
|
|
|
|
Model = _Model,
|
|
|
|
|
ModelA = _ModelA,
|
|
|
|
|
ModelB = _ModelB,
|
|
|
|
|
ModelC = _ModelC,
|
|
|
|
|
ModelD = _ModelD,
|
|
|
|
|
ModelE = _ModelE,
|
|
|
|
|
ModelF = _ModelF
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
CardCollectionView.ItemsSource = InfoItems;
|
|
|
|
|
myRefreshView_.IsRefreshing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~InfoPage()//关闭时注销消息
|
|
|
|
|
{
|
|
|
|
|
WeakReferenceMessenger.Default.UnregisterAll(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 将 sender 强制转换为 BindingContext 定义在 BindableObject
|
|
|
|
|
if (sender is Microsoft.Maui.Controls.BindableObject bindable)
|
|
|
|
|
{
|
|
|
|
|
var context = bindable.BindingContext;
|
|
|
|
|
|
|
|
|
|
if (context is InfoItem item)
|
|
|
|
|
{
|
|
|
|
|
DisplayAlert("提示", $"你点击了工单: {item.MachineName}", "确定");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|