更新搜索

This commit is contained in:
muqing 2024-08-23 07:59:16 +08:00
parent bf54ae4dd0
commit 1424fb2de9
17 changed files with 406 additions and 73 deletions

View File

@ -1,15 +1,19 @@
using RustTools.muqing;
using System.Diagnostics;
using RustTools.muqing;
namespace RustTools.ApiFox;
class mod
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
#pragma warning disable IDE1006 // 命名样式
public class mod
{
//最新时间 下载数量 投币数量 更新数量
//latestTime downloadNumbercoinNumber updateNumber
public static string latestTime = "latestTime";
public static string downloadNumber = "downloadNumber";
public static string coinNumber = "coinNumber";
public static string updateNumber = "updateNumber";
public const string latestTime = "latestTime";
public const string downloadNumber = "downloadNumber";
public const string coinNumber = "coinNumber";
public const string updateNumber = "updateNumber";
/// <summary>

View File

@ -0,0 +1,17 @@

using RustTools.muqing;
using static IniHelper;
namespace RustTools.ApiFox;
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
#pragma warning disable IDE1006 // 命名样式
public class search
{
public static async Task<string> searchAll(string key)
{
return await wl.postAsync("/php/search.php?action=searchAll", new string[][]
{
new string[]{ "key", key},
});
}
}

View File

@ -39,8 +39,13 @@
<!-- 模组列表的视图 -->
<DataTemplate x:Key="HomePageListItem">
<StackPanel Orientation="Horizontal">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border
Grid.Column="0"
Width="56"
Height="56"
BorderBrush="White"
@ -50,15 +55,16 @@
<ImageBrush ImageSource="{Binding Icon}" Stretch="UniformToFill" />
</Border.Background>
</Border>
<StackPanel Margin="10,10,10,10" Orientation="Vertical">
<StackPanel
Grid.Column="1"
Margin="10,10,10,10"
Orientation="Vertical">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{Binding Name}" />
<TextBlock
Width="500"
MaxLines="2"
Style="{StaticResource BodyStrongTextBlockStyle}"
Text="{Binding Description}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap" />
TextTrimming="CharacterEllipsis" />
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{Binding UpdateTime}" />
<TextBlock
@ -68,8 +74,7 @@
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="次下载" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>

View File

@ -0,0 +1,88 @@
using Newtonsoft.Json;
namespace RustTools.DataList;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
#pragma warning disable IDE1006 // 命名样式
public class SearchAllList
{
[JsonProperty("code")]
public int Code
{
get; set;
}
[JsonProperty("message")]
public string Message
{
get; set;
}
[JsonProperty("data")]
public Data data
{
get; set;
}
public class Data
{
[JsonProperty("total")]
public List<TotalItem> Total
{
get; set;
}
[JsonProperty("type")]
public List<TypeItem> Type
{
get; set;
}
}
public class TotalItem
{
[JsonProperty("title")]
public string Title
{
get; set;
}
[JsonProperty("type")]
public string Type
{
get; set;
}
[JsonProperty("content")]
public string Content
{
get; set;
}
[JsonProperty("icon")]
public string Icon
{
get; set;
}
[JsonProperty("id")]
public string Id
{
get; set;
}
}
public class TypeItem
{
[JsonProperty("typeName")]
public string TypeName
{
get; set;
}
[JsonProperty("num")]
public int Num
{
get; set;
}
}
}

View File

@ -6,7 +6,7 @@
xmlns:local="using:RustTools"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:windowex="using:WinUIEx"
MinWidth="500"
MinWidth="600"
MinHeight="500"
PersistenceId="MainWindow"
mc:Ignorable="d" />

View File

@ -71,4 +71,5 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
</Project>

View File

@ -3,6 +3,7 @@
using Microsoft.UI.Xaml.Navigation;
using RustTools.Contracts.Services;
using RustTools.muqing;
using RustTools.Views;
namespace RustTools.ViewModels;
@ -35,9 +36,8 @@ public partial class ShellViewModel : ObservableRecipient
private void OnNavigated(object sender, NavigationEventArgs e)
{
System.GC.Collect();
GC.Collect();
IsBackEnabled = NavigationService.CanGoBack;
if (e.SourcePageType == typeof(SettingsPage))
{
Selected = NavigationViewService.SettingsItem;
@ -49,5 +49,9 @@ public partial class ShellViewModel : ObservableRecipient
{
Selected = selectedItem;
}
else
{
Selected = null;
}
}
}

View File

@ -34,7 +34,7 @@ using static RustTools.DataList.DataBaseManifest;
namespace RustTools.Views;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// エ惲<EFBFBD>棏鯣ャ
/// </summary>
public sealed partial class CodeTablePage : Page
{
@ -250,4 +250,4 @@ public sealed partial class CodeTablePage : Page
//Debug.WriteLine("Ctrl+J pressed "+ a?.Count);
}
}
}
}

View File

@ -31,7 +31,7 @@ public sealed partial class HomePage : Page
ListA.ItemClick += ListAClick;
ListB.ItemClick += ListAClick;
//为了节省流量测试的时候不加载这些
if (true)
if (false)
{
ViewModel.random();
ViewModel.Latest();

View File

@ -12,8 +12,7 @@
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
@ -22,7 +21,6 @@
<AppBarButton
Grid.Row="0"
Grid.Column="1"
Margin="0,3,9,0"
Icon="Sort"
IsCompact="False"
Label="下载量"
@ -52,6 +50,7 @@
<ListView
x:Name="list"
Grid.Row="1"
Margin="0,0,0,9"
Padding="0,0,16,0"
HorizontalAlignment="Stretch"
IsItemClickEnabled="True"

View File

@ -29,7 +29,7 @@ public sealed partial class RankingPage : Page
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
list.Height = ActualHeight - 100;
//list.Height = ActualHeight - 100;
}

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page
x:Class="RustTools.Views.SearchModPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RustTools.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0">
<Run Text="一共搜索到" />
<Run Text="{x:Bind ListSearch.Count}" />
<Run Text="个数据" />
</TextBlock>
<ListView
Name="list"
Grid.Row="1"
IsItemClickEnabled="True"
ItemsSource="{x:Bind ListSearch}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate xmlns:a="using:RustTools.DataList" x:DataType="a:SearchAllList">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border
Grid.Column="0"
Width="56"
Height="56"
BorderBrush="White"
BorderThickness="0"
CornerRadius="9">
<Border.Background>
<ImageBrush ImageSource="{Binding Icon}" Stretch="UniformToFill" />
</Border.Background>
</Border>
<StackPanel
Grid.Column="1"
Margin="10,10,10,10"
Orientation="Vertical">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{Binding Title}" />
<TextBlock
LineHeight="2"
MaxLines="2"
Style="{StaticResource BodyTextBlockStyle}"
Text="{Binding Content}"
TextTrimming="CharacterEllipsis" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>

View File

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.muqing;
using RustTools.WindowUI;
using Windows.Foundation;
using Windows.Foundation.Collections;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace RustTools.Views;
/// <summary>
/// 搜索模组碎片
/// </summary>
public sealed partial class SearchModPage : Page
{
public ObservableCollection<SearchAllList.TotalItem> ListSearch
{
get; set;
} = new();
public SearchModPage()
{
InitializeComponent();
list.ItemClick += List_ItemClick; ;
}
private void List_ItemClick(object sender, ItemClickEventArgs e)
{
if (e.ClickedItem is not SearchAllList.TotalItem item) { return; }
if (item.Type == "mod")
{
// 查找已存在的 ModulePage如果存在则激活它
var existingWindow = ModuleInfoWin.ModulePageList.FirstOrDefault(window => window.Mod.Id == item.Id);
if (existingWindow != null)
{
existingWindow.Activate();
}
else
{
var newWindow = new ModuleInfoWin(item.Id);
newWindow.Activate();
ModuleInfoWin.ModulePageList.Add(newWindow);
}
}
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter is string param)
{
try
{
var v = await ApiFox.search.searchAll(param);
//gj.sc(v);
var searchAllList = JsonConvert.DeserializeObject<SearchAllList>(v);
if (searchAllList.Code == 0)
{
foreach (var item in searchAllList.data.Total)
{
if (item.Type == "mod")
{
item.Icon = string.IsNullOrEmpty(item.Icon) ? "/Assets/image/image.svg" : item.Icon.Replace("..", wl.api);
ListSearch.Add(item);
}
}
}
}
catch (Exception ex)
{
await Dialog.DialogWarn(ex.Message,XamlRoot);
}
}
}
protected override void OnNavigatedFrom(NavigationEventArgs e){
base.OnNavigatedFrom(e);
}
}

View File

@ -104,8 +104,17 @@
<HyperlinkButton x:Uid="SettingsPage_PrivacyTermsLink" Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
</StackPanel>
</StackPanel>
<TextBlock Style="{ThemeResource SubtitleTextBlockStyle}" Text="特别鸣谢" />
<StackPanel Margin="{StaticResource XSmallTopMargin}" Orientation="Horizontal">
<PersonPicture
Width="56"
Height="56"
Margin="6"
ProfilePicture="http://q.qlogo.cn/headimg_dl?dst_uin=2923268971&amp;spec=640&amp;img_type=jpg"
ToolTipService.ToolTip="感谢薄荷对本软件后端的帮助,也希望薄荷能尽快出来官方的电脑版" />
</StackPanel>
</StackPanel>
</Grid>
</ScrollView>
</Page>

View File

@ -7,34 +7,60 @@
xmlns:helpers="using:RustTools.Helpers"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Loaded="OnLoaded">
Loaded="OnLoaded"
SizeChanged="Page_SizeChanged">
<Grid>
<Grid x:Name="gridview">
<!-- Height="{Binding ElementName=NavigationViewControl, Path=CompactPaneLength}" -->
<Grid
x:Name="AppTitleBar"
Height="{Binding ElementName=NavigationViewControl, Path=CompactPaneLength}"
Height="48"
VerticalAlignment="Top"
Canvas.ZIndex="1"
IsHitTestVisible="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="IconColumn" Width="Auto" />
<ColumnDefinition x:Name="TitleColumn" Width="Auto" />
<ColumnDefinition
x:Name="RightDragColumn"
Width="*"
MinWidth="48" />
</Grid.ColumnDefinitions>
<Image
x:Name="TitleIcon"
Grid.Column="0"
Width="16"
Height="16"
HorizontalAlignment="Left"
Margin="0,0,6,0"
Source="/Assets/WindowIcon.ico" />
<TextBlock
x:Name="AppTitleBarText"
Margin="28,0,0,0"
Grid.Column="1"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
TextWrapping="NoWrap" />
<AutoSuggestBox
x:Name="TitleBarSearchBox"
Grid.Column="2"
MaxWidth="600"
Margin="6,0,150,0"
VerticalAlignment="Center"
PlaceholderText="搜索模组"
QueryIcon="Find"
QuerySubmitted="TitleBarSearchBox_QuerySubmitted" />
<!--<PersonPicture
x:Name="PersonPic"
Grid.Column="6"
Height="32"
Margin="0,0,16,0" />-->
</Grid>
<NavigationView
x:Name="NavigationViewControl"
Canvas.ZIndex="0"
DisplayModeChanged="NavigationViewControl_DisplayModeChanged"
ExpandedModeThresholdWidth="1280"
Header="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}"
IsBackButtonVisible="Visible"
IsBackButtonVisible="Auto"
IsBackEnabled="{x:Bind ViewModel.IsBackEnabled, Mode=OneWay}"
IsSettingsVisible="True"
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}">
@ -84,7 +110,7 @@
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.MenuItems>
<NavigationView.HeaderTemplate>
<!--<NavigationView.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{Binding}" />
@ -102,7 +128,7 @@
</DataTemplate>
</behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
</behaviors:NavigationViewHeaderBehavior>
</i:Interaction.Behaviors>
</i:Interaction.Behaviors>-->
<Grid Margin="{StaticResource NavigationViewPageContentMargin}">
<Frame x:Name="NavigationFrame" />
</Grid>

View File

@ -1,4 +1,5 @@

using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
@ -7,7 +8,7 @@ using RustTools.Contracts.Services;
using RustTools.Helpers;
using RustTools.muqing;
using RustTools.ViewModels;
using Windows.Foundation;
using Windows.System;
namespace RustTools.Views;
@ -26,7 +27,7 @@ public sealed partial class ShellPage : Page
InitializeComponent();
ViewModel.NavigationService.Frame = NavigationFrame;
//ViewModel.NavigationService.Frame.ElementSoundMode.isna = "False";
//ViewModel.NavigationService.UnregisterFrameEvents();
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
// TODO: Set the title bar icon by updating /Assets/WindowIcon.ico.
@ -37,46 +38,48 @@ public sealed partial class ShellPage : Page
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
}
AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized();
//NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems[0];
//NavigationViewControl.SelectionChanged += NavigationViewControl_SelectionChanged;
//NavigateToPage("Home");
}
private void NavigationViewControl_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
System.GC.Collect();
if (args.SelectedItem is NavigationViewItem selectedItem)
{
var tag = selectedItem.Tag.ToString();
gj.sc(tag);
if (tag != null)
{
NavigateToPage(tag);
}
}
}
private void NavigateToPage(string pageTag)
{
var pageType = pageTag switch
{
"Home" => typeof(HomePage),
"Concern" => typeof(ConcernPage),
"Ranking" => typeof(RankingPage),
"User"=>typeof(UserPage),
"Module" => typeof(ModulePage),
"Settings" => typeof(SettingsPage),
_ => typeof(HomePage),
};
NavigationFrame.Navigate(pageType);
AppTitleBarText.Text = "app_name".GetLocalized() + " PC";//+ "app_version".GetLocalized();
}
private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
//gj.sc(RequestedTheme);
TitleBarHelper.UpdateTitleBar(RequestedTheme);
if (App.MainWindow?.ExtendsContentIntoTitleBar == true)
{
// Update interactive regions if the size of the window changes.
SetRegionsForCustomTitleBar();
}
//TitleBarHelper.UpdateTitleBar(RequestedTheme);
KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu));
KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack));
//KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu));
//KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack));
}
private void SetRegionsForCustomTitleBar()
{
// Specify the interactive regions of the title bar.
var m_AppWindow = App.MainWindow?.AppWindow;
if (m_AppWindow == null) { return; }
var scaleAdjustment = AppTitleBar.XamlRoot.RasterizationScale;
var transform = TitleBarSearchBox.TransformToVisual(null);
var bounds = transform.TransformBounds(new Rect(0, 0,
TitleBarSearchBox.ActualWidth,
TitleBarSearchBox.ActualHeight));
Windows.Graphics.RectInt32 SearchBoxRect = GetRect(bounds, scaleAdjustment);
var rectArray = new Windows.Graphics.RectInt32[] { SearchBoxRect };
InputNonClientPointerSource nonClientInputSrc =
InputNonClientPointerSource.GetForWindowId(m_AppWindow.Id);
nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, rectArray);
}
private Windows.Graphics.RectInt32 GetRect(Rect bounds, double scale)
{
return new Windows.Graphics.RectInt32(
_X: (int)Math.Round(bounds.X * scale),
_Y: (int)Math.Round(bounds.Y * scale),
_Width: (int)Math.Round(bounds.Width * scale),
_Height: (int)Math.Round(bounds.Height * scale)
);
}
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
@ -84,11 +87,13 @@ public sealed partial class ShellPage : Page
App.AppTitlebar = AppTitleBarText;
}
//DisplayModeChanged="NavigationViewControl_DisplayModeChanged"
private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
{
AppTitleBar.Margin = new Thickness()
{
Left = sender.CompactPaneLength * (sender.DisplayMode == NavigationViewDisplayMode.Minimal ? 2 : 1),
//Left = sender.CompactPaneLength,
Top = AppTitleBar.Margin.Top,
Right = AppTitleBar.Margin.Right,
Bottom = AppTitleBar.Margin.Bottom
@ -118,4 +123,21 @@ public sealed partial class ShellPage : Page
args.Handled = result;
}
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (App.MainWindow?.ExtendsContentIntoTitleBar == true)
{
// Update interactive regions if the size of the window changes.
SetRegionsForCustomTitleBar();
}
}
private void TitleBarSearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
var text = sender.Text;
NavigationFrame.Navigate(typeof(SearchModPage),text);
NavigationFrame.BackStack.Clear();
//ViewModel.NavigationService.Frame.Visibility= Visibility.Collapsed;
}
}

View File

@ -4,7 +4,7 @@ namespace RustTools.muqing;
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
class wl
{
public static string api = "https://rust.coldmint.top";
public const string api = "https://rust.coldmint.top";
/// <summary>
/// <para>异步Post请求</para>
@ -28,7 +28,7 @@ class wl
if (response != null)
{
var str = response.Content;
return str;
return str ?? string.Empty;
}
return string.Empty;
}