From 9c6b6f24edd4afade4259e77573a72b39044e72e Mon Sep 17 00:00:00 2001
From: muqing <1966944300@qq.com>
Date: Sun, 19 Jan 2025 17:30:46 +0800
Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=92=8C=E5=A2=9E=E5=BC=BA?=
=?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=A1=E6=81=AF=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
在 `MovingInfo.cs` 中:
* 添加了类注释 `/// 动态信息`。
* 将 `Data` 类重命名为 `MovingInfo`,并添加了属性 `Code`、`Message` 和 `Data`。
* 将 `Data` 类中的 `name` 字段重命名为 `Id`,并添加了多个属性:`Account`、`Content`、`Visible`、`Time`、`Location`、`UserName`、`HeadIcon`、`Email`、`Permission`、`LoginTime`、`Gender` 和 `Enable`。
在 `ItemView.xaml` 中:
* 添加了 `xmlns:DataType="datalist:MovingInfo"` 命名空间。
* 修改了 `Ellipse.Fill` 的 `ImageBrush`,将 `ImageSource` 从固定路径改为绑定 `HeadIcon`。
* 修改了 `TextBlock` 的 `Text` 属性,绑定 `UserName` 和 `Time`。
* 修改了 `TextBlock` 的 `Text` 属性,绑定 `Content`。
在 `ConcernPage.xaml.cs` 中:
* 将 `ObservableCollection` 和 `ObservableCollection` 分别修改为 `ObservableCollection` 和 `ObservableCollection`。
* 修改了 `dongtaixiaoxi` 方法,添加了 `account` 和 `ALL` 参数,并根据 `ALL` 参数调用不同的 API 获取数据。
* 在 `ListViewA_SelectionChanged` 方法中,修改了调用 `dongtaixiaoxi` 方法时传递的参数。
在 `Dynamic.cs` 中:
* 新增了 `Dynamic` 类,并添加了两个静态方法 `GetAllDynamic` 和 `Getlist`,用于异步获取动态信息。
---
ApiFox/Dynamic.cs | 26 +++++++++++++
DataList/MovingInfo.cs | 78 +++++++++++++++++++++++++++++++++++----
Styles/ItemView.xaml | 16 +++++---
Views/ConcernPage.xaml.cs | 68 +++++++++++++++++++++++++++-------
4 files changed, 162 insertions(+), 26 deletions(-)
create mode 100644 ApiFox/Dynamic.cs
diff --git a/ApiFox/Dynamic.cs b/ApiFox/Dynamic.cs
new file mode 100644
index 0000000..8f291fd
--- /dev/null
+++ b/ApiFox/Dynamic.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RustTools.muqing;
+
+namespace RustTools.ApiFox;
+
+public class Dynamic
+{
+ public static Task GetAllDynamic(string account,int limit = 0)
+ {
+ return wl.postAsync("/php/dynamic.php?action=getAllDynamic", [
+ ["account", account],
+ ["limit", limit == 0 ? "0" : limit.ToString()]
+ ]);
+ }
+ public static Task Getlist(string account, int limit = 0)
+ {
+ return wl.postAsync("/php/dynamic.php?action=list", [
+ ["account", account],
+ ["limit", limit == 0 ? "0" : limit.ToString()]
+ ]);
+ }
+}
diff --git a/DataList/MovingInfo.cs b/DataList/MovingInfo.cs
index f35d37e..5765226 100644
--- a/DataList/MovingInfo.cs
+++ b/DataList/MovingInfo.cs
@@ -1,13 +1,77 @@
namespace RustTools.DataList;
+///
+/// 动态信息
+///
public class MovingInfo
{
- public class Data
- {
- public string name;
- public Data(string name)
- {
- this.name = name;
- }
+ public int Code
+ {
+ get; set;
+ }
+ public string Message
+ {
+ get; set;
+ }
+ public List Data
+ {
+ get; set;
+ }
+
+
+ public class DynamicRecord
+ {
+ public string Id
+ {
+ get; set;
+ }
+ public string Account
+ {
+ get; set;
+ }
+ public string Content
+ {
+ get; set;
+ }
+ public bool Visible
+ {
+ get; set;
+ }
+ public DateTime Time
+ {
+ get; set;
+ }
+ public string Location
+ {
+ get; set;
+ }
+ public string UserName
+ {
+ get; set;
+ }
+ public string HeadIcon
+ {
+ get; set;
+ }
+ public string Email
+ {
+ get; set;
+ }
+ public int Permission
+ {
+ get; set;
+ }
+ public DateTime LoginTime
+ {
+ get; set;
+ }
+ public int Gender
+ {
+ get; set;
+ } // -1 未知, 0 女, 1 男
+ public bool Enable
+ {
+ get; set;
+ }
}
}
diff --git a/Styles/ItemView.xaml b/Styles/ItemView.xaml
index 79a5b9c..7ccf959 100644
--- a/Styles/ItemView.xaml
+++ b/Styles/ItemView.xaml
@@ -1,5 +1,8 @@
-
+
-
+
-
+
+
+
+ Text="{Binding Time}" />
+
+ Text="{Binding Content}" />
communitylist = new();
- public ObservableCollection MovingInfoList = new();
+ public ObservableCollection communitylist = [];
+ public ObservableCollection MovingInfoList = [];
private bool IsLogin = false;
public ConcernPage()
{
@@ -54,7 +54,8 @@ public sealed partial class ConcernPage : Page
var a = new CommunityList.Data
{
UserName = "ȫ",
- HeadIcon = "/Assets/tool.png"
+ HeadIcon = "/Assets/tool.png",
+ Account = account
};
communitylist.Add(a);
foreach (var item in response.data)
@@ -81,17 +82,55 @@ public sealed partial class ConcernPage : Page
///
/// ÿעĶ̬Ϣ
///
- private void dongtaixiaoxi()
+ private void dongtaixiaoxi(string account, bool ALL)
{
MovingInfoList.Clear();
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
- MovingInfoList.Add(new MovingInfo.Data("Ѿд"));
+ if (account == null)
+ {
+ return;
+ };
+ if (ALL)
+ {
+ ApiFox.Dynamic.GetAllDynamic(account).ContinueWith((task) =>
+ {
+ var value = task.Result;
+ if (string.IsNullOrEmpty(value)) return;
+
+ // ʹ Newtonsoft.Json зл
+ var response = JsonConvert.DeserializeObject(value);
+
+ if (response != null && response.Code == 0)
+ {
+ foreach (var item in response.Data)
+ {
+ // 滻ͷе·Ϊ·
+ item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
+
+ // ļ¼ӵ ObservableCollection
+ MovingInfoList.Add(item);
+ }
+ }
+ else if (response != null)
+ {
+ Console.WriteLine($"Error: {response.Message}");
+ }
+ }, TaskScheduler.FromCurrentSynchronizationContext()); // ȷUI̸߳
+ }
+ else
+ {
+ ApiFox.Dynamic.Getlist(account).ContinueWith((task) =>
+ {
+ var value = task.Result;
+ if (value == string.Empty) return;
+ var response = JsonConvert.DeserializeObject(value);
+ foreach (var item in response.Data)
+ {
+ item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
+ MovingInfoList.Add(item);
+ }
+ },TaskScheduler.FromCurrentSynchronizationContext());
+
+ }
}
@@ -123,7 +162,8 @@ public sealed partial class ConcernPage : Page
{
// ȡǰѡеĿ
var selectedItem = ListViewA.SelectedItem;
- gj.sc(selectedItem);
- dongtaixiaoxi();
+ var data = selectedItem as CommunityList.Data;
+ gj.sc(data?.Account);
+ dongtaixiaoxi(data?.Account, data.UserName.Equals("ȫ"));
}
}