2026-05-01 14:44:49 +08:00
|
|
|
using Microsoft.Maui.Controls.Shapes;
|
|
|
|
|
using SunlightAggregationTerminal.Models;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
|
|
|
|
namespace SunlightAggregationTerminal.NotificationView;
|
|
|
|
|
|
|
|
|
|
public partial class MessagePage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
public ObservableCollection<NotificationItem> MessageItems { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public MessagePage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.BindingContext = this;
|
|
|
|
|
LoadData(); // 加载数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
var allData = DataService._NotificationData;
|
|
|
|
|
if (allData != null)
|
|
|
|
|
{
|
|
|
|
|
// 清空旧数据
|
|
|
|
|
MessageItems.Clear();
|
|
|
|
|
|
2026-05-04 20:39:02 +08:00
|
|
|
// 按时间倒序,并只取最新的 50 条
|
2026-06-21 19:01:24 +08:00
|
|
|
var itemsToShow = allData.OrderByDescending(x => x.Time).Take(100).Where(x => x.Type == MsgType.Message);
|
2026-05-01 14:44:49 +08:00
|
|
|
|
|
|
|
|
// 将数据添加到集合中,UI 会自动更新
|
|
|
|
|
foreach (var item in itemsToShow)
|
|
|
|
|
{
|
|
|
|
|
MessageItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 01:29:47 +08:00
|
|
|
|
2026-05-01 14:44:49 +08:00
|
|
|
}
|