96 lines
2.8 KiB
C#
96 lines
2.8 KiB
C#
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);
|
||
}
|
||
}
|