优化关注模块和登陆功能

This commit is contained in:
muqing 2024-12-06 09:26:57 +08:00
parent 03c697b2b6
commit 3da0341de8
15 changed files with 188 additions and 115 deletions

View File

@ -0,0 +1,25 @@
using System.Diagnostics;
using Newtonsoft.Json;
using RestSharp;
using RustTools.muqing;
namespace RustTools.ApiFox;
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
#pragma warning disable IDE1006 // 命名样式
public class community
{
public static async Task<string> getList(string account,bool isFollowMode,int limit=0)
{
//Debug.WriteLine("account:" + account);
Debug.WriteLine("isFollowMode:" + isFollowMode.ToString());
return await wl.postAsync("/php/community.php?action=getList", new string[][]{
new string[] { "account", account },
new string[] { "isFollowMode",isFollowMode.ToString().ToLower() },
new string[] { "limit", limit==0?"0" : limit.ToString() }
});
}
}

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
public class CommunityList
{
@ -67,7 +68,7 @@ public class CommunityList
public string HeadIcon
{
get; set;
}
} = string.Empty;
[JsonProperty("email")]
public string Email
@ -93,7 +94,7 @@ public class CommunityList
get; set;
}
[JsonProperty("enable")]
[JsonConverter(typeof(BoolStringConverter))] // 使用自定义转换器
public bool Enable
{
get; set;
@ -106,4 +107,19 @@ public class CommunityList
}
}
public class BoolStringConverter : JsonConverter<bool>
{
public override bool ReadJson(JsonReader reader, Type objectType, [AllowNull] bool existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var value = reader.Value.ToString();
return value.ToLower() == "true";
}
// 重写 WriteJson 方法
public override void WriteJson(JsonWriter writer, bool value, JsonSerializer serializer)
{
writer.WriteValue(value ? "true" : "false");
}
}
}

View File

@ -1,5 +1,6 @@
using RustTools.Helpers;
using RustTools.muqing;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
namespace RustTools;
@ -24,6 +25,8 @@ public sealed partial class MainWindow : WindowEx
settings.ColorValuesChanged += Settings_ColorValuesChanged;
// cannot use FrameworkElement.ActualThemeChanged event
//var editorWin = new Editor.EditorWin();
}
// this handles updating the caption button colors correctly when indows system theme is changed

View File

@ -5,7 +5,6 @@
Margin="0,0,0,16"
Padding="16"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="{StaticResource ControlCornerRadius}">
<Grid>
@ -20,7 +19,7 @@
Width="56"
Height="56">
<Ellipse.Fill>
<ImageBrush ImageSource="/Assets/image/a.jpeg" Stretch="UniformToFill" />
<ImageBrush ImageSource="/Assets/image/image.svg" Stretch="UniformToFill" />
</Ellipse.Fill>
</Ellipse>
<StackPanel Grid.Column="1" Margin="9,0,0,0">
@ -41,7 +40,7 @@
Style="{StaticResource BodyTextBlockStyle}"
Text="内容是大概就是这个东西了" />
<StackPanel
Margin="16,0,16,0"
Margin="16,0,0,0"
HorizontalAlignment="Right"
FlowDirection="RightToLeft"
Orientation="Horizontal">

View File

@ -5,6 +5,7 @@ using Newtonsoft.Json;
using RustTools.ApiFox;
using RustTools.DataList;
using RustTools.muqing;
using WinUIEx.Messaging;
namespace RustTools.Themes;
public sealed partial class LoginPage : UserControl
@ -26,14 +27,16 @@ public sealed partial class LoginPage : UserControl
ZpasswordBox.PasswordChanged += ZPasswordBox_PasswordChanged;
ZpasswordyesBox.PasswordChanged += ZPasswordBox_PasswordChanged;
//ZaccountBox.Text = "muqing1";
//ZnameBox.Text = "muqing153";
//ZpasswordBox.Password = "123456";
//ZpasswordBox.Password= "123456";
//ZemialBox.Text="123456@qq.com";
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.User);
var account = iniHelper.GetValue(IniHelper.CODE.User, IniHelper.KEY.account);
accountBox.Text = account;
var password = iniHelper.GetValue(IniHelper.CODE.User, IniHelper.KEY.password);
passwordBox.Password = password;
}
/// <summary>
/// 返回到登陆
/// </summary>
@ -116,7 +119,7 @@ public sealed partial class LoginPage : UserControl
{
Toast.IsOpen = false;
var v = await user.loginPc(accountBox.Text, passwordBox.Password);
var message = JsonConvert.DeserializeObject<Message>(v);
var message = JsonConvert.DeserializeObject<DataList.Message>(v);
if (message != null)
{
if (message.message.Equals("请先激活您的账户"))
@ -137,6 +140,7 @@ public sealed partial class LoginPage : UserControl
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.User);
iniHelper.SetValue(IniHelper.CODE.User, IniHelper.KEY.token, message.data.token);
iniHelper.SetValue(IniHelper.CODE.User, IniHelper.KEY.password,passwordBox.Password);
iniHelper.SetValue(IniHelper.CODE.User, IniHelper.KEY.account,message.data.account);
iniHelper.Save();
LoginSucceeded?.Invoke(this, message.data.account);
@ -177,7 +181,7 @@ public sealed partial class LoginPage : UserControl
{
var v = await user.register(ZaccountBox.Text, ZnameBox.Text, ZpasswordBox.Password, ZemialBox.Text);
gj.sc(v);
var message = JsonConvert.DeserializeObject<Message>(v);
var message = JsonConvert.DeserializeObject<DataList.Message>(v);
if (message.code == 0)
{
Toast.Title = "提示";
@ -227,7 +231,7 @@ public sealed partial class LoginPage : UserControl
{
gj.sc(textBox.Text);
var v = await user.enableAccount(account, textBox.Text);
var message = JsonConvert.DeserializeObject<Message>(v);
var message = JsonConvert.DeserializeObject<DataList.Message>(v);
if (message != null)
{
Toast.Title = "提示";

View File

@ -8,86 +8,7 @@ namespace RustTools.ViewModels;
public partial class ConcernViewModel : ObservableRecipient
{
public ObservableCollection<CommunityList.Data> communitylist = new();
public ObservableCollection<MovingInfo.Data> MovingInfoList = new();
private readonly string json = @"
{
""code"": 0,
""message"": ""3"",
""data"": [
{
""account"": ""offical"",
""cover"": ""../user/offical/cover.png"",
""introduce"": null,
""fans"": ""64"",
""follower"": ""5"",
""praise"": ""0"",
""userName"": """",
""headIcon"": ""http://rust.coldmint.top/user/offical/icon.png"",
""email"": ""2923268971@qq.com"",
""permission"": ""2"",
""loginTime"": ""2023-10-21 22:28:18"",
""gender"": ""1"",
""enable"": ""true"",
""dynamicColor"": ""null""
},
{
""account"": ""coldmint"",
""cover"": ""http://rust.coldmint.top/user/coldmint/covers/181d019f-7cb7-9c07-389e-5a78b98eea54.png"",
""introduce"": """",
""fans"": ""141"",
""follower"": ""13"",
""praise"": ""0"",
""userName"": ""?"",
""headIcon"": ""https://rust.coldmint.top/user/coldmint/icons/4006dc55-9101-39cc-7076-34c4b32924d5.png"",
""email"": ""cold_mint@qq.com"",
""permission"": ""1"",
""loginTime"": ""2024-08-02 22:04:48"",
""gender"": ""-1"",
""enable"": ""true"",
""dynamicColor"": ""null""
},
{
""account"": ""muqing"",
""cover"": ""../user/muqing/covers/d4083a79-1e7f-d3bc-5944-ae9bce0d6714.png"",
""introduce"": ""nihao"",
""fans"": ""1"",
""follower"": ""1"",
""praise"": ""0"",
""userName"": """",
""headIcon"": ""../user/muqing/icons/cf0582bb-584c-176f-098b-a9a95af22a44.png"",
""email"": ""2583089389@qq.com"",
""permission"": ""3"",
""loginTime"": ""2024-04-18 14:08:22"",
""gender"": ""1"",
""enable"": ""true"",
""dynamicColor"": ""null""
}
]
}";
public ConcernViewModel()
{
var response = JsonConvert.DeserializeObject<CommunityList>(json);
var a = new CommunityList.Data
{
UserName = "全部",
HeadIcon = "/Assets/tool.png"
};
communitylist.Add(a);
foreach (var item in response.data)
{
//item.UserName
item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
communitylist.Add(item);
}
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
}
}

View File

@ -6,4 +6,5 @@ public partial class UserViewModel : ObservableRecipient
public UserViewModel()
{
}
}

View File

@ -3,6 +3,7 @@
x:Class="RustTools.Views.ConcernPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RustTools.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -15,43 +16,49 @@
<TextBlock
HorizontalAlignment="Center"
Style="{StaticResource BodyStrongTextBlockStyle}"
Text="请登陆后使用此功能" />
Text="请登陆后使用此功能"
Visibility="Collapsed" />
</Grid>
<!--<themes:NullPage x:Name="nullpage" Visibility="Visible" />-->
<Grid x:Name="gridview" Visibility="Collapsed">
<Grid x:Name="gridview" Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="56" MaxWidth="320" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel
Name="StackPanelA"
MinWidth="95"
MaxWidth="300"
Margin="0,9,9,9"
Padding="9"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Padding="9">
<ListView
Name="ListViewA"
Grid.Column="0"
ItemTemplate="{StaticResource ConCernItem}"
ItemsSource="{x:Bind ViewModels.communitylist}"
ItemsSource="{x:Bind communitylist}"
Loaded="ListViewA_Loaded"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectionChanged="ListViewA_SelectionChanged"
SelectionMode="Single" />
</StackPanel>
<controls:ContentSizer Grid.Column="1" TargetControl="{x:Bind StackPanelA}" />
<StackPanel
Grid.Column="1"
Grid.Column="2"
Margin="9"
Padding="9"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
CornerRadius="9">
<ListView
Name="ListViewB"
IsItemClickEnabled="False"
ItemTemplate="{StaticResource MovingInfo}"
ItemsSource="{x:Bind ViewModels.MovingInfoList}"
ItemsSource="{x:Bind MovingInfoList}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectionMode="None" />

View File

@ -1,5 +1,9 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.muqing;
using RustTools.ViewModels;
@ -17,12 +21,17 @@ public sealed partial class ConcernPage : Page
{
get; set;
}
public ObservableCollection<CommunityList.Data> communitylist = new();
public ObservableCollection<MovingInfo.Data> MovingInfoList = new();
private bool IsLogin = false;
public ConcernPage()
{
ViewModels = App.GetService<ConcernViewModel>();
InitializeComponent();
//如果未登陆
if (false)
Init();
if (IsLogin)
{
}
@ -30,6 +39,60 @@ public sealed partial class ConcernPage : Page
}
private async void Init()
{
try
{
var ini = new IniHelper();
ini.Load(IniHelper.FILE.User);
var account = ini.GetValue(IniHelper.CODE.User, IniHelper.KEY.account);
var value = await ApiFox.community.getList(account, true, 0);
//Debug.WriteLine(value);
if (value == string.Empty) return;
var response = JsonConvert.DeserializeObject<CommunityList>(value);
var a = new CommunityList.Data
{
UserName = "全部",
HeadIcon = "/Assets/tool.png"
};
communitylist.Add(a);
foreach (var item in response.data)
{
//item.UserName
item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
communitylist.Add(item);
}
ListViewA.SelectedIndex = 0;
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
/// <summary>
/// 每个关注的动态消息内容
/// </summary>
private void dongtaixiaoxi()
{
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("已经在写了"));
}
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
@ -59,6 +122,7 @@ public sealed partial class ConcernPage : Page
// 获取当前选中的项目
var selectedItem = ListViewA.SelectedItem;
gj.sc(selectedItem);
dongtaixiaoxi();
}
private void ListViewA_Loaded(object sender, RoutedEventArgs e)

View File

@ -59,6 +59,7 @@
<MenuFlyoutItem Click="Button_Rwmod" Text="打包" />
<MenuFlyoutItem Click="Button_PostRwmod" Text="发布" />
<MenuFlyoutItem Click="Button_Delete" Text="删除" />
<MenuFlyoutItem Click="Button_OpenDir" Text="资源管理器" />
</MenuFlyout>
</Grid.ContextFlyout>
<Grid

View File

@ -7,6 +7,7 @@ using RustTools.muqing;
using RustTools.Themes;
using RustTools.ViewModels;
using SharpCompress.Common;
using WinRT.Interop;
namespace RustTools.Views;
/// <summary>
/// 模组碎片
@ -254,7 +255,7 @@ public sealed partial class ModulePage : Page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void BasicGridView_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
private void BasicGridView_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
{
var gridView = sender as GridView;
@ -310,6 +311,16 @@ public sealed partial class ModulePage : Page
}
}
/// <summary>
/// 打开目录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_OpenDir(object sender, RoutedEventArgs e)
{
wj.OpenFileExplorer(ViewModel.ListMod[0].Dri);
}
}
public class MyItemTemplateSelector : DataTemplateSelector
{

View File

@ -25,7 +25,7 @@ public sealed partial class SettingsPage : Page
Init();
}
private async void Init()
private void Init()
{
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.Config);
@ -51,7 +51,7 @@ public sealed partial class SettingsPage : Page
MapsFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl);
}
private bool Backone = false;
private async void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Backone)
{
@ -124,7 +124,7 @@ public sealed partial class SettingsPage : Page
}
}
private async void SaveModAndMaps()
private void SaveModAndMaps()
{
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.Config);
@ -133,7 +133,7 @@ public sealed partial class SettingsPage : Page
iniHelper.Save();
}
private async void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e)
private void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e)
{
var a = (AutoSuggestBox)sender;
var iniHelper = new IniHelper();

View File

@ -50,6 +50,7 @@ public sealed partial class UserPage : Page
}
else
{
//nulllogin();
await login(account);
}
}
@ -67,9 +68,13 @@ public sealed partial class UserPage : Page
}
/// <summary>
/// 登陆成功
/// </summary>
/// <param name="sender"></param>
/// <param name="account"></param>
private async void LoginPage_LoginSucceeded(object sender, string account)
{
// µÇ¼³É¹¦ºó£¬´Ó Grid ÖÐÒƳý LoginPage
view.Children.Remove((LoginPage)sender);
await login(account);
@ -91,10 +96,15 @@ public sealed partial class UserPage : Page
gridview.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
}
/// <summary>
/// 退出登陆
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuFlyoutItemLogout_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
var iniHelper = new IniHelper(IniHelper.FILE.User);
iniHelper.Clean();
iniHelper.SetValue(IniHelper.CODE.User, IniHelper.KEY.token, "");
iniHelper.Save();
nulllogin();
}

View File

@ -1,4 +1,5 @@
using RustTools.muqing;
using System.Diagnostics;
using RustTools.muqing;
using Windows.Storage;
#pragma warning disable CA1050 // 在命名空间中声明类型
@ -32,6 +33,7 @@ public class IniHelper
public const string token = "token";
public const string account = "account";
public const string password = "password";//密码
}
@ -77,6 +79,7 @@ public class IniHelper
public void Load(string a)
{
filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, a);
//Debug.WriteLine($"加载配置文件: {filePath}");
if (!File.Exists(filePath))
{// 使用 File.Create 创建文件并立即关闭
using var fs = File.Create(filePath);

View File

@ -1,6 +1,8 @@
using System.Diagnostics;
using System.IO.Compression;
using Windows.Storage;
using Windows.UI.Popups;
using WinRT.Interop;
namespace RustTools.muqing;
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
@ -134,6 +136,11 @@ public class wj
return string.Empty;
}
}
/// <summary>
/// 打开文件管理器-在资源管理器中打开
/// </summary>
/// <param name="path"></param>
/// <exception cref="Exception"></exception>
public static void OpenFileExplorer(string path)
{
try
@ -147,8 +154,9 @@ public class wj
else
throw;
}
catch (System.Exception other)
catch (Exception other)
{
//Dialog.DialogWarn(other.Message, App.MainWindow.XamlRoot);
throw other;
}
}