WIn_RustTools/RustTools/Views/SearchModPage.xaml.cs

96 lines
2.8 KiB
C#
Raw Permalink Normal View History

2024-08-22 23:59:16 +00:00
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>
/// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ƭ
/// </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")
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڵ<EFBFBD> ModulePage<67><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򼤻<EFBFBD><F2BCA4BB><EFBFBD>
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);
}
}