121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
using System.Collections.ObjectModel;
|
||
using System.Diagnostics;
|
||
using Microsoft.UI;
|
||
using Microsoft.UI.Windowing;
|
||
using Microsoft.UI.Xaml;
|
||
using Microsoft.UI.Xaml.Controls;
|
||
using Newtonsoft.Json;
|
||
using RustTools.DataList;
|
||
using RustTools.muqing;
|
||
using RustTools.Services;
|
||
using RustTools.ViewModels;
|
||
using Windows.UI.WindowManagement;
|
||
using System.Threading;
|
||
using Microsoft.UI.Xaml.Media.Imaging;
|
||
using System.Text.RegularExpressions;
|
||
namespace RustTools.Views;
|
||
public sealed partial class HomePage : Page
|
||
{
|
||
public HomePageViewModel ViewModel
|
||
{
|
||
get;
|
||
}
|
||
public ObservableCollection<HomeBanner.Data> Pictures = new();
|
||
public HomePage()
|
||
{
|
||
ViewModel = App.GetService<HomePageViewModel>();
|
||
//轮播图
|
||
var lunbo = JsonConvert.DeserializeObject<HomeBanner>(ViewModel.lunbo);
|
||
if (lunbo != null)
|
||
{
|
||
foreach (var item in lunbo.data)
|
||
{
|
||
Pictures.Add(item);
|
||
}
|
||
}
|
||
ViewModel.random();
|
||
ViewModel.Latest();
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
|
||
{
|
||
//var height = DisplayArea.Primary.WorkArea.Height;
|
||
//double a = height / 5;
|
||
//Debug.WriteLine(a);
|
||
//// 设置FlipView的高度
|
||
//Banner.Height = a;
|
||
|
||
}
|
||
private void ListAClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
if (e.ClickedItem is not ModData item) { return; }
|
||
var newWindow = new ModulePage(item.Id);
|
||
newWindow.Activate();
|
||
//// 获取点击的列表项的数据
|
||
//// 假设 RandomItem 是您的数据模型中的一个类
|
||
|
||
//// 获取被点击的项
|
||
//// 创建一个新的Window实例
|
||
//var window = new Window
|
||
//{
|
||
// // 将NewPage设置为新Window的内容
|
||
// Content = new ModulePage(item?.Id),
|
||
|
||
// // 设置新Window的一些属性,如标题和大小
|
||
// Title =item?.Name,
|
||
|
||
//};
|
||
//window.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
|
||
////window.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/创意工坊.svg"));
|
||
|
||
//// 显示新Window
|
||
//window.Show();
|
||
}
|
||
|
||
private void RefreshRandom(object sender,RoutedEventArgs e)
|
||
{
|
||
ViewModel.random();
|
||
}
|
||
private void RefreshLatest(object sender, RoutedEventArgs e)
|
||
{
|
||
ViewModel.Latest();
|
||
}
|
||
|
||
private void Image_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
|
||
{
|
||
// 获取点击的 Image 控件
|
||
var image = sender as Image;
|
||
if (image != null)
|
||
{
|
||
|
||
// 获取 Image 控件的绑定数据上下文
|
||
var item = image.DataContext as HomeBanner.Data;
|
||
var link1 = item?.link;
|
||
if (link1 != null)
|
||
{
|
||
// 使用正则表达式匹配大括号内的内容
|
||
var match = MyRegex().Match(link1);
|
||
if (match.Success)
|
||
{
|
||
var link = match.Groups[1].Value;
|
||
Process.Start(new ProcessStartInfo
|
||
{
|
||
FileName = link,
|
||
UseShellExecute = true,
|
||
Verb = "open"
|
||
});
|
||
}
|
||
else
|
||
{
|
||
Debug.WriteLine("No match found.");
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
[GeneratedRegex("\\{(.+?)\\}")]
|
||
private static partial Regex MyRegex();
|
||
}
|