From 3da0341de85d0b5f5edcf11ca37967c4d0e485df Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Fri, 6 Dec 2024 09:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E6=B3=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=92=8C=E7=99=BB=E9=99=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RustTools/ApiFox/community.cs | 25 ++++++++ RustTools/DataList/CommunityList.cs | 22 ++++++- RustTools/MainWindow.xaml.cs | 3 + RustTools/Styles/ItemView.xaml | 5 +- RustTools/Themes/LoginPage.xaml.cs | 24 ++++--- RustTools/ViewModels/ConcernViewModel.cs | 79 ------------------------ RustTools/ViewModels/UserViewModel.cs | 1 + RustTools/Views/ConcernPage.xaml | 27 +++++--- RustTools/Views/ConcernPage.xaml.cs | 66 +++++++++++++++++++- RustTools/Views/ModulePage.xaml | 1 + RustTools/Views/ModulePage.xaml.cs | 13 +++- RustTools/Views/SettingsPage.xaml.cs | 8 +-- RustTools/Views/UserPage.xaml.cs | 14 ++++- RustTools/muqing/IniHelper.cs | 5 +- RustTools/muqing/wj.cs | 10 ++- 15 files changed, 188 insertions(+), 115 deletions(-) create mode 100644 RustTools/ApiFox/community.cs diff --git a/RustTools/ApiFox/community.cs b/RustTools/ApiFox/community.cs new file mode 100644 index 0000000..892146a --- /dev/null +++ b/RustTools/ApiFox/community.cs @@ -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 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() } + }); + } + + +} diff --git a/RustTools/DataList/CommunityList.cs b/RustTools/DataList/CommunityList.cs index 8e0511d..ca1f203 100644 --- a/RustTools/DataList/CommunityList.cs +++ b/RustTools/DataList/CommunityList.cs @@ -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 + { + 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"); + } + } + } diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index 8b22a21..5004d00 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -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 diff --git a/RustTools/Styles/ItemView.xaml b/RustTools/Styles/ItemView.xaml index 8835a41..79a5b9c 100644 --- a/RustTools/Styles/ItemView.xaml +++ b/RustTools/Styles/ItemView.xaml @@ -5,7 +5,6 @@ Margin="0,0,0,16" Padding="16" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" - BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}"> @@ -20,7 +19,7 @@ Width="56" Height="56"> - + @@ -41,7 +40,7 @@ Style="{StaticResource BodyTextBlockStyle}" Text="内容是大概就是这个东西了" /> diff --git a/RustTools/Themes/LoginPage.xaml.cs b/RustTools/Themes/LoginPage.xaml.cs index 1576f57..b6bae57 100644 --- a/RustTools/Themes/LoginPage.xaml.cs +++ b/RustTools/Themes/LoginPage.xaml.cs @@ -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; } - /// /// ص½ /// @@ -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(v); + var message = JsonConvert.DeserializeObject(v); if (message != null) { if (message.message.Equals("ȼ˻")) @@ -137,7 +140,8 @@ 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.account, message.data.account); + 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(v); + var message = JsonConvert.DeserializeObject(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(v); + var message = JsonConvert.DeserializeObject(v); if (message != null) { Toast.Title = "ʾ"; diff --git a/RustTools/ViewModels/ConcernViewModel.cs b/RustTools/ViewModels/ConcernViewModel.cs index ee63aeb..0dbde64 100644 --- a/RustTools/ViewModels/ConcernViewModel.cs +++ b/RustTools/ViewModels/ConcernViewModel.cs @@ -8,86 +8,7 @@ namespace RustTools.ViewModels; public partial class ConcernViewModel : ObservableRecipient { - public ObservableCollection communitylist = new(); - public ObservableCollection 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(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")); } } diff --git a/RustTools/ViewModels/UserViewModel.cs b/RustTools/ViewModels/UserViewModel.cs index 326b8be..2353ec3 100644 --- a/RustTools/ViewModels/UserViewModel.cs +++ b/RustTools/ViewModels/UserViewModel.cs @@ -6,4 +6,5 @@ public partial class UserViewModel : ObservableRecipient public UserViewModel() { } + } diff --git a/RustTools/Views/ConcernPage.xaml b/RustTools/Views/ConcernPage.xaml index 2ac32a3..96f97a8 100644 --- a/RustTools/Views/ConcernPage.xaml +++ b/RustTools/Views/ConcernPage.xaml @@ -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 @@ + Text="请登陆后使用此功能" + Visibility="Collapsed" /> - - + - + + + Padding="9"> + + + Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" + CornerRadius="9"> diff --git a/RustTools/Views/ConcernPage.xaml.cs b/RustTools/Views/ConcernPage.xaml.cs index a9556ee..734f318 100644 --- a/RustTools/Views/ConcernPage.xaml.cs +++ b/RustTools/Views/ConcernPage.xaml.cs @@ -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 = new(); + public ObservableCollection MovingInfoList = new(); + private bool IsLogin = false; public ConcernPage() { ViewModels = App.GetService(); 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(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); + } + + + } + + + /// + /// ÿעĶ̬Ϣ + /// + 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) diff --git a/RustTools/Views/ModulePage.xaml b/RustTools/Views/ModulePage.xaml index 7bf835c..dc89877 100644 --- a/RustTools/Views/ModulePage.xaml +++ b/RustTools/Views/ModulePage.xaml @@ -59,6 +59,7 @@ + /// 模组碎片 @@ -254,7 +255,7 @@ public sealed partial class ModulePage : Page /// /// /// - 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 } } + + /// + /// 打开目录 + /// + /// + /// + private void Button_OpenDir(object sender, RoutedEventArgs e) + { + wj.OpenFileExplorer(ViewModel.ListMod[0].Dri); + } } public class MyItemTemplateSelector : DataTemplateSelector { diff --git a/RustTools/Views/SettingsPage.xaml.cs b/RustTools/Views/SettingsPage.xaml.cs index 74296e7..bf0ec39 100644 --- a/RustTools/Views/SettingsPage.xaml.cs +++ b/RustTools/Views/SettingsPage.xaml.cs @@ -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(); diff --git a/RustTools/Views/UserPage.xaml.cs b/RustTools/Views/UserPage.xaml.cs index 018e94a..afcb8d5 100644 --- a/RustTools/Views/UserPage.xaml.cs +++ b/RustTools/Views/UserPage.xaml.cs @@ -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 } + /// + /// ½ɹ + /// + /// + /// 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; } + /// + /// ˳½ + /// + /// + /// 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(); } diff --git a/RustTools/muqing/IniHelper.cs b/RustTools/muqing/IniHelper.cs index f91b8c9..fca2cfb 100644 --- a/RustTools/muqing/IniHelper.cs +++ b/RustTools/muqing/IniHelper.cs @@ -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); diff --git a/RustTools/muqing/wj.cs b/RustTools/muqing/wj.cs index f8babad..a91f919 100644 --- a/RustTools/muqing/wj.cs +++ b/RustTools/muqing/wj.cs @@ -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; } } + /// + /// 打开文件管理器-在资源管理器中打开 + /// + /// + /// 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; } }