重构和增强动态信息处理
在 `MovingInfo.cs` 中: * 添加了类注释 `/// <summary>动态信息</summary>`。 * 将 `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<CommunityList.Data>` 和 `ObservableCollection<MovingInfo.Data>` 分别修改为 `ObservableCollection<CommunityList.Data>` 和 `ObservableCollection<MovingInfo.DynamicRecord>`。 * 修改了 `dongtaixiaoxi` 方法,添加了 `account` 和 `ALL` 参数,并根据 `ALL` 参数调用不同的 API 获取数据。 * 在 `ListViewA_SelectionChanged` 方法中,修改了调用 `dongtaixiaoxi` 方法时传递的参数。 在 `Dynamic.cs` 中: * 新增了 `Dynamic` 类,并添加了两个静态方法 `GetAllDynamic` 和 `Getlist`,用于异步获取动态信息。
This commit is contained in:
parent
d33aaf056e
commit
9c6b6f24ed
26
ApiFox/Dynamic.cs
Normal file
26
ApiFox/Dynamic.cs
Normal file
|
@ -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<string> 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<string> Getlist(string account, int limit = 0)
|
||||
{
|
||||
return wl.postAsync("/php/dynamic.php?action=list", [
|
||||
["account", account],
|
||||
["limit", limit == 0 ? "0" : limit.ToString()]
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,77 @@
|
|||
namespace RustTools.DataList;
|
||||
/// <summary>
|
||||
/// 动态信息
|
||||
/// </summary>
|
||||
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<DynamicRecord> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:DataType="datalist:MovingInfo">
|
||||
<DataTemplate x:Key="MovingInfo">
|
||||
<StackPanel
|
||||
Margin="0,0,0,16"
|
||||
|
@ -19,26 +22,29 @@
|
|||
Width="56"
|
||||
Height="56">
|
||||
<Ellipse.Fill>
|
||||
<ImageBrush ImageSource="/Assets/image/image.svg" Stretch="UniformToFill" />
|
||||
<ImageBrush ImageSource="{Binding HeadIcon}" Stretch="UniformToFill" />
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
<StackPanel Grid.Column="1" Margin="9,0,0,0">
|
||||
|
||||
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="名称" />
|
||||
<!-- 名称 -->
|
||||
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{Binding UserName}" />
|
||||
<!-- 信息 日期 -->
|
||||
<TextBlock
|
||||
Margin="0,3,0,0"
|
||||
Style="{StaticResource BodyTextBlockStyle}"
|
||||
Text="信息 日期" />
|
||||
Text="{Binding Time}" />
|
||||
</StackPanel>
|
||||
<FontIcon
|
||||
Grid.Column="2"
|
||||
VerticalAlignment="Top"
|
||||
Glyph="" />
|
||||
</Grid>
|
||||
<!-- 内容是大概就是这个东西了 -->
|
||||
<TextBlock
|
||||
Margin="16"
|
||||
Style="{StaticResource BodyTextBlockStyle}"
|
||||
Text="内容是大概就是这个东西了" />
|
||||
Text="{Binding Content}" />
|
||||
<StackPanel
|
||||
Margin="16,0,0,0"
|
||||
HorizontalAlignment="Right"
|
||||
|
|
|
@ -21,8 +21,8 @@ public sealed partial class ConcernPage : Page
|
|||
{
|
||||
get; set;
|
||||
}
|
||||
public ObservableCollection<CommunityList.Data> communitylist = new();
|
||||
public ObservableCollection<MovingInfo.Data> MovingInfoList = new();
|
||||
public ObservableCollection<CommunityList.Data> communitylist = [];
|
||||
public ObservableCollection<MovingInfo.DynamicRecord> 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
|
|||
/// <summary>
|
||||
/// 每个关注的动态消息内容
|
||||
/// </summary>
|
||||
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<MovingInfo>(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<MovingInfo>(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("全部"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user