From acb2ed64d04c39babe7d95e5847e73cd4ad6a1fc Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Fri, 16 Aug 2024 13:15:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RustTools/ApiFox/user.cs | 36 +++++ RustTools/DataList/Message.cs | 32 +++++ RustTools/DataList/UserSpaceInfo.cs | 126 ++++++++++++++++++ RustTools/README.md | 9 +- RustTools/RustTools.csproj | 25 +--- .../Styles/TitleSubtitleControlStyle.xaml | 10 +- RustTools/Themes/LoginPage.xaml | 51 ++++--- RustTools/Themes/LoginPage.xaml.cs | 120 ++++++++++++++--- RustTools/ViewModels/HomePageViewModel.cs | 9 +- RustTools/ViewModels/UserViewModel.cs | 1 + RustTools/Views/ModulePage.xaml | 9 +- RustTools/Views/UserPage.xaml | 31 +++-- RustTools/Views/UserPage.xaml.cs | 81 +++++++++++ RustTools/muqing/IniHelper.cs | 17 +++ RustTools/muqing/wl.cs | 4 +- 15 files changed, 475 insertions(+), 86 deletions(-) create mode 100644 RustTools/ApiFox/user.cs create mode 100644 RustTools/DataList/Message.cs create mode 100644 RustTools/DataList/UserSpaceInfo.cs diff --git a/RustTools/ApiFox/user.cs b/RustTools/ApiFox/user.cs new file mode 100644 index 0000000..86a1d2f --- /dev/null +++ b/RustTools/ApiFox/user.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using RustTools.muqing; + +namespace RustTools.ApiFox; + +public class user +{ + public static async Task loginPc(string account, string passWord) + { + var pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; + var v = Regex.IsMatch(account, pattern); + //gj.sc(account + " " + v); //这里不知道为什么会出现 True 而不是 true 导致识别邮箱失败 + var task = await wl.postAsync("/php/user.php?action=loginPc", new string[][] + { + new string[]{ "account",account}, + new string[]{ "passWord", passWord }, + new string[]{ "isEmail", v.ToString().ToLower() } + }); + return task; + } + public static async Task SpaceInfo(string account) + { + var pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; + var v = Regex.IsMatch(account, pattern); + var task = await wl.postAsync("/php/user.php?action=getSpaceInfo", new string[][] + { + new string[]{ "account",account} + }); + return task; + } +} diff --git a/RustTools/DataList/Message.cs b/RustTools/DataList/Message.cs new file mode 100644 index 0000000..c423844 --- /dev/null +++ b/RustTools/DataList/Message.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RustTools.DataList; + +#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 +#pragma warning disable IDE1006 // 命名样式 +public class Message +{ + public int code{get; set;} + public string message { get; set;} + public Data? data { get; set;} + public class Data + { + public string token + { + get; set; + } + public string account + { + get;set; + } + public string a + { + get;set; + } + + } +} diff --git a/RustTools/DataList/UserSpaceInfo.cs b/RustTools/DataList/UserSpaceInfo.cs new file mode 100644 index 0000000..7d3f711 --- /dev/null +++ b/RustTools/DataList/UserSpaceInfo.cs @@ -0,0 +1,126 @@ + +using System.Runtime.CompilerServices; +using Newtonsoft.Json; + +namespace RustTools.DataList; + +#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 +#pragma warning disable IDE1006 // 命名样式 +public class UserSpaceInfo +{ + [JsonProperty("code")] + public int Code + { + get; set; + } + + [JsonProperty("message")] + public string Message + { + get; set; + } + + [JsonProperty("data")] + public UserData Data + { + get; set; + } + public class UserData + { + [JsonProperty("account")] + public string Account + { + get; set; + } + + [JsonProperty("userName")] + public string UserName + { + get; set; + } + + [JsonProperty("headIcon")] + public string HeadIcon + { + get; set; + } + + [JsonProperty("email")] + public string Email + { + get; set; + } + + [JsonProperty("permission")] + public string Permission + { + get; set; + } + + [JsonProperty("loginTime")] + public DateTime LoginTime + { + get; set; + } + + [JsonProperty("gender")] + public string Gender + { + get; set; + } + + [JsonProperty("enable")] + public bool Enable + { + get; set; + } + + [JsonProperty("expirationTime")] + public string ExpirationTime + { + get; set; + } + + [JsonProperty("dynamicColor")] + public string DynamicColor + { + get; set; + } + + [JsonProperty("cover")] + public string Cover + { + get; set; + } + + [JsonProperty("introduce")] + public string Introduce + { + get; set; + } + + [JsonProperty("fans")] + public string Fans + { + get; set; + } + + [JsonProperty("follower")] + public string Follower + { + get; set; + } + + [JsonProperty("praise")] + public string Praise + { + get; set; + } + + [JsonProperty("location")] + public string Location + { + get; set; + } + } +} diff --git a/RustTools/README.md b/RustTools/README.md index b4299ec..794c2ca 100644 --- a/RustTools/README.md +++ b/RustTools/README.md @@ -51,4 +51,11 @@ WinUI还是比较冷门的一个技术,代码和例子都不多 关于编译器 margin-top: 5px; font-size: 16px; color: #333;">薄荷

- \ No newline at end of file + + + +## 开源协议 + 虽然没什么用但还是要写一写 + 如果你用到本项目中的源码的话请务必表明出处@铁锈助手 + 如果你也是开源软件可以把这个标记在注释中 + 如果不是则务必在你软件的窗口关于中标注上 diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index 4f030a3..c018940 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -60,28 +60,5 @@ - - - - - - - - - - $(DefaultXamlRuntime) - Designer - - - MSBuild:Compile - - - - - - - - - - + \ No newline at end of file diff --git a/RustTools/Styles/TitleSubtitleControlStyle.xaml b/RustTools/Styles/TitleSubtitleControlStyle.xaml index afc325d..8e4dbaa 100644 --- a/RustTools/Styles/TitleSubtitleControlStyle.xaml +++ b/RustTools/Styles/TitleSubtitleControlStyle.xaml @@ -12,8 +12,14 @@ Padding="3" HorizontalAlignment="Center" VerticalAlignment="Center"> - - + + diff --git a/RustTools/Themes/LoginPage.xaml b/RustTools/Themes/LoginPage.xaml index 19683eb..648c6dd 100644 --- a/RustTools/Themes/LoginPage.xaml +++ b/RustTools/Themes/LoginPage.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:RustTools.Themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewmodels="using:RustTools.ViewModels" mc:Ignorable="d"> @@ -14,29 +15,35 @@ Padding="26" Background="{StaticResource CardStrokeColorDefault}" CornerRadius="13"> - + - + + Click="Button_Click" + Glyph="" /> - - + @@ -28,6 +29,13 @@ Padding="9,9,26,9" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" CornerRadius="10"> + + + + + + + @@ -40,19 +48,21 @@ Height="86" Background="BlanchedAlmond" CornerRadius="16"> - + + Text="{Binding userInfo.UserName}" /> + Text="{Binding userInfo.Introduce}" /> - + + TitleText="{Binding userInfo.Follower}" /> + TitleText="{Binding userInfo.Fans}" /> + TitleText="{Binding userInfo.Praise}" /> diff --git a/RustTools/Views/UserPage.xaml.cs b/RustTools/Views/UserPage.xaml.cs index 512fce4..cf4bab1 100644 --- a/RustTools/Views/UserPage.xaml.cs +++ b/RustTools/Views/UserPage.xaml.cs @@ -1,4 +1,13 @@ +using System.Net.Http.Json; +using System.Security.Principal; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RustTools.DataList; +using RustTools.muqing; +using RustTools.Themes; using RustTools.ViewModels; // To learn more about WinUI, the WinUI project structure, @@ -11,6 +20,7 @@ namespace RustTools.Views; /// public sealed partial class UserPage : Page { + public UserSpaceInfo.UserData userInfo { get; set; } = new(); public UserViewModel UserViewModel { get; set; @@ -19,5 +29,76 @@ public sealed partial class UserPage : Page { UserViewModel = App.GetService(); InitializeComponent(); + Init(); + + } + private async void Init() + { + var iniHelper = new IniHelper(); + iniHelper.Load(IniHelper.FILE.User); + var account = iniHelper.GetValue(IniHelper.CODE.User, IniHelper.KEY.account); + var token = iniHelper.GetValue(IniHelper.CODE.User, IniHelper.KEY.token); + try + { + var v = await ApiFox.user.loginPc(account, token); + var userSpaceInfo = JsonConvert.DeserializeObject(v); + + //δ¼ + if (userSpaceInfo.Code == 0) + { + nulllogin(); + } + else + { + await login(account); + } + } + catch (Exception ex) + { + nulllogin(); + gj.sc(ex); + } + } + private void nulllogin() + { + gridview.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed; + var loginPage = new LoginPage(); + loginPage.LoginSucceeded += LoginPage_LoginSucceeded; + view.Children.Add(loginPage); + + } + + private async void LoginPage_LoginSucceeded(object sender, string account) + { + + // ¼ɹ󣬴 Grid Ƴ LoginPage + view.Children.Remove((LoginPage)sender); + await login(account); + } + public string aaa { get; set; } = "aaa"; + + private async Task login(string account) + { + var v = await ApiFox.user.SpaceInfo(account); + var userSpaceInfo = JsonConvert.DeserializeObject(v); + if (userSpaceInfo != null && userSpaceInfo.Code == 0) + { + var data = userSpaceInfo.Data; + if (data == null) { return; } + data.HeadIcon=data.HeadIcon == string.Empty ? "/Assets/tool.png" : data.HeadIcon.Replace("..", wl.api); + gj.sc(data.HeadIcon); + userInfo = data; + + DataContext = this; + } + gridview.Visibility = Microsoft.UI.Xaml.Visibility.Visible; + } + + private void MenuFlyoutItemLogout_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) + { + var iniHelper = new IniHelper(IniHelper.FILE.User); + iniHelper.Clean(); + iniHelper.Save(); + nulllogin(); } } diff --git a/RustTools/muqing/IniHelper.cs b/RustTools/muqing/IniHelper.cs index 3ff615d..fe0c761 100644 --- a/RustTools/muqing/IniHelper.cs +++ b/RustTools/muqing/IniHelper.cs @@ -10,6 +10,7 @@ public class IniHelper public class FILE { public const string Config = "config.ini"; + public const string User = "user.ini"; } /// /// 节 @@ -18,6 +19,7 @@ public class IniHelper { public const string Settings = "Settings"; public const string Rust = "Rust"; + public const string User = "User"; } public class KEY @@ -25,6 +27,10 @@ public class IniHelper public const string SystemBackdrop = "SystemBackdrop"; public const string ModFileUrl = "ModFileUrl";//模组路径 public const string MapsFileUrl = "MapsFileUrl"; + + public const string token = "token"; + public const string account = "account"; + } private string filePath = string.Empty; @@ -48,6 +54,17 @@ public class IniHelper Console.WriteLine($"Loaded value: {value}"); */ } + public IniHelper(string filePath) + { + Load(filePath); + } + /// + /// 清空数据 + /// + public void Clean() + { + _sections.Clear(); + } /// diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index 24f2879..fbfbb14 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -16,7 +16,7 @@ class wl /// 参数 /// /// - public static async Task postAsync(string url, string[][] parameters) + public static async Task postAsync(string url, string[][] parameters) { var client = new RestClient(api); var request = new RestRequest(url, Method.Post); @@ -30,7 +30,7 @@ class wl var str = response.Content; return str; } - return null; + return string.Empty; } ///