diff --git a/山海奇闻录/山海奇闻录/App.axaml b/山海奇闻录/山海奇闻录/App.axaml
index 9c6c1b0..4529bba 100644
--- a/山海奇闻录/山海奇闻录/App.axaml
+++ b/山海奇闻录/山海奇闻录/App.axaml
@@ -21,4 +21,5 @@
+
\ No newline at end of file
diff --git a/山海奇闻录/山海奇闻录/Assets/Themes.axaml b/山海奇闻录/山海奇闻录/Assets/Themes.axaml
index 4787e42..ba46635 100644
--- a/山海奇闻录/山海奇闻录/Assets/Themes.axaml
+++ b/山海奇闻录/山海奇闻录/Assets/Themes.axaml
@@ -14,7 +14,7 @@
-
+
diff --git a/山海奇闻录/山海奇闻录/ViewModels/MainViewModel.cs b/山海奇闻录/山海奇闻录/ViewModels/MainViewModel.cs
index 9d925d9..2e2b3e4 100644
--- a/山海奇闻录/山海奇闻录/ViewModels/MainViewModel.cs
+++ b/山海奇闻录/山海奇闻录/ViewModels/MainViewModel.cs
@@ -1,62 +1,125 @@
-using System.ComponentModel;
-using System.Net.Http;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
+using System;
+using System.Net;
+using System.IO;
+using Avalonia;
+using Avalonia.Animation;
+using Avalonia.Controls;
+using Avalonia.Media;
using Avalonia.Media.Imaging;
-using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace 山海奇闻录.ViewModels;
public partial class MainViewModel : ViewModelBase
{
- //界面文字
[ObservableProperty] private string _AppTitle = "山海奇闻录";
- [ObservableProperty] private string _MyValue = "我的 / 上传";
+ [ObservableProperty] private string _UpLoadTitle = "上传内容库";
+ [ObservableProperty] private string _MyValue = "内容上传";
+ [ObservableProperty] private string _CloseMyValue = "返回主页";
[ObservableProperty] private string _Friendly = "社交";
[ObservableProperty] private string _TextBook = "文案";
[ObservableProperty] private string _TalkPhotos = "图片";
-}
-//加载logo
-public partial class MainViewModel : INotifyPropertyChanged
-{
- private Bitmap _LogoUrl;
- public Bitmap LogoUrl
- {
- get => _LogoUrl;
- set
- {
- _LogoUrl = value;
- OnPropertyChanged();
- }
- }
+ [ObservableProperty] private string _DebugText = "调试输出";
+
+ [ObservableProperty] private Bitmap? _LogoUrl;
+ [ObservableProperty] private Bitmap? _UpLoadUrl;
+
+ [ObservableProperty] private Bitmap? _MainImage1;
+ [ObservableProperty] private Bitmap? _MainImage2;
+ [ObservableProperty] private Bitmap? _MainImage3;
+
+ private readonly string _LogoUrlAddr = "https://shanhai.linuxacme.com/logo.png";
+ private readonly string _UpLoadUrlAddr = "https://shanhai.linuxacme.com/logo.png";
+ private readonly string _MainImage1Addr = "https://shanhai.linuxacme.com/image/2021102818050.jpg";
+ private readonly string _MainImage2Addr = "https://shanhai.linuxacme.com/image/2021091109343.jpg";
+ private readonly string _MainImage3Addr = "https://shanhai.linuxacme.com/image/210903/210903.jpg";
+ // private static readonly HttpClient client = new HttpClient();
+
public MainViewModel()
{
- LoadImageAsync();
+ //加载icon
+ LoadIcon(_LogoUrlAddr);
+ LoadUpLoad(_UpLoadUrlAddr);
+ LoadMainImage1(_MainImage1Addr);
+ LoadMainImage2(_MainImage2Addr);
+ LoadMainImage3(_MainImage3Addr);
}
-
- private async Task LoadImageAsync()
+
+ private void LoadIcon(string url)
{
- var url = "https://shanhai.linuxacme.com/logo.png";
- using (var httpClient = new HttpClient())
+ using (var webClient = new WebClient())
{
- var imageData = await httpClient.GetByteArrayAsync(url);
- var bitmap = new Bitmap(new System.IO.MemoryStream(imageData));
-
- // 确保在 UI 线程上更新属性
- Dispatcher.UIThread.InvokeAsync(() =>
+ byte[] imageBytes = webClient.DownloadData(url);
+ using (var memoryStream = new MemoryStream(imageBytes))
{
- LogoUrl = bitmap;
- });
+ LogoUrl = new Bitmap(memoryStream);
+ }
}
}
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
+
+ private void LoadUpLoad(string url)
{
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ using (var webClient = new WebClient())
+ {
+ byte[] imageBytes = webClient.DownloadData(url);
+ using (var memoryStream = new MemoryStream(imageBytes))
+ {
+ UpLoadUrl = new Bitmap(memoryStream);
+ }
+ }
}
-}
\ No newline at end of file
+
+ private void LoadMainImage1(string url)
+ {
+ using (var webClient = new WebClient())
+ {
+ byte[] imageBytes = webClient.DownloadData(url);
+ using (var memoryStream = new MemoryStream(imageBytes))
+ {
+ MainImage1 = new Bitmap(memoryStream);
+ }
+ }
+ }
+
+ private void LoadMainImage2(string url)
+ {
+ using (var webClient = new WebClient())
+ {
+ byte[] imageBytes = webClient.DownloadData(url);
+ using (var memoryStream = new MemoryStream(imageBytes))
+ {
+ MainImage2 = new Bitmap(memoryStream);
+ }
+ }
+ }
+
+ private void LoadMainImage3(string url)
+ {
+ using (var webClient = new WebClient())
+ {
+ byte[] imageBytes = webClient.DownloadData(url);
+ using (var memoryStream = new MemoryStream(imageBytes))
+ {
+ MainImage3 = new Bitmap(memoryStream);
+ }
+ }
+ }
+
+ // private async Task Post(string data)
+ // {
+ // using (var client = new HttpClient())
+ // {
+ // // 将字符串数据转化为 StringContent
+ // var content = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded");
+ //
+ // // 发送请求
+ // var response = await client.PostAsync("https://shanhai.linuxacme.com/Php/PushText.php", content);
+ //
+ // // 获取数据
+ // var responseString = await response.Content.ReadAsStringAsync();
+ // DebugText = responseString;
+ // }
+ // }
+}
diff --git a/山海奇闻录/山海奇闻录/Views/MainView.axaml b/山海奇闻录/山海奇闻录/Views/MainView.axaml
index 47e60c7..dd30056 100644
--- a/山海奇闻录/山海奇闻录/Views/MainView.axaml
+++ b/山海奇闻录/山海奇闻录/Views/MainView.axaml
@@ -3,52 +3,84 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:山海奇闻录.ViewModels"
- mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ mc:Ignorable="d"
x:Class="山海奇闻录.Views.MainView"
x:DataType="vm:MainViewModel">
-
-
+
+
+
+
+
+
+
+
+
-
+
+ Margin="10 0 0 0"/>
-
+
+ Margin="0 0 15 0"/>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs b/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs
index c2a9deb..dcccbb9 100644
--- a/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs
+++ b/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs
@@ -1,11 +1,132 @@
+using System.Threading.Tasks;
using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Media;
+using 山海奇闻录.ViewModels;
namespace 山海奇闻录.Views;
public partial class MainView : UserControl
{
+ public double WindowWidth;
+ public double WindowHeight;
+
public MainView()
{
InitializeComponent();
+
+ //获取程序的宽高
+ this.Loaded += GetWindowBodySize;
+
+ //打开侧边栏
+ this.OpenPushWindow.Click += OpenPushWindowHandler;
+ //关闭侧边栏
+ this.ClosePushWindow.Click += ClosePushWindowHandler;
}
-}
\ No newline at end of file
+ private void InitPushWindow()
+ {
+ var NewTransForm = new TranslateTransform
+ {
+ X = (-1 * WindowWidth), // 设置 X 坐标偏移
+ Y = (0 * WindowHeight) // 设置 Y 坐标偏移
+ };
+ this.PushWindow.RenderTransform = NewTransForm;
+ }
+
+ private void InitLunBoTu()
+ {
+ //设置轮播图宽高
+ this.MainBox.Width = (WindowWidth - 12);
+ this.MainBox.Height = (WindowHeight / 3.5);
+
+ this.MainImages1.Width = (WindowWidth - 12);
+ this.MainImages1.Height = (WindowHeight / 3.5);
+ this.MainImages2.Width = (WindowWidth - 12);
+ this.MainImages2.Height = (WindowHeight / 3.5);
+ this.MainImages3.Width = (WindowWidth - 12);
+ this.MainImages3.Height = (WindowHeight / 3.5);
+ }
+
+ private void GetWindowBodySize(object sender, RoutedEventArgs e)
+ {
+ WindowWidth = this.Bounds.Width;
+ WindowHeight = this.Bounds.Height;
+
+ InitLunBoTu();
+
+ InitPushWindow();
+ }
+
+ private async void OpenPushWindowHandler(object? sender, RoutedEventArgs e)
+ {
+ await OpenPushWindowExecAsync();
+ }
+
+ private async Task OpenPushWindowExecAsync()
+ {
+ var NewTransForm = new TranslateTransform
+ {
+ X = (-1 * WindowWidth), // 设置 X 坐标偏移
+ Y = (0 * WindowHeight) // 设置 Y 坐标偏移
+ };
+
+ for (int i = 0; i < (WindowWidth / 10) - 1; i++)
+ {
+ NewTransForm.X += 10;
+ NewTransForm.Y = 0;
+
+ // 使用异步延迟,避免阻塞 UI 线程
+ await Task.Delay(1);
+
+ // 直接更新 UI
+ this.PushWindow.RenderTransform = NewTransForm;
+ }
+
+ NewTransForm.X = 0;
+ NewTransForm.Y = 0;
+
+ this.PushWindow.RenderTransform = NewTransForm;
+ }
+
+ private async Task ClosePushWindowExec()
+ {
+ var NewTransForm = new TranslateTransform
+ {
+ X = (0 * WindowWidth), // 设置 X 坐标偏移
+ Y = (0 * WindowHeight) // 设置 Y 坐标偏移
+ };
+
+ for (int i = 0; i < (WindowWidth / 10) - 1; i++)
+ {
+ NewTransForm.X -= 10;
+ NewTransForm.Y = 0;
+
+ // 使用异步延迟,避免阻塞 UI 线程
+ await Task.Delay(1);
+
+ // 直接更新 UI
+ this.PushWindow.RenderTransform = NewTransForm;
+ }
+
+ NewTransForm.X = (-1 * WindowWidth);
+ NewTransForm.Y = 0;
+
+ this.PushWindow.RenderTransform = NewTransForm;
+ }
+ private async void ClosePushWindowHandler(object? sender, RoutedEventArgs e)
+ {
+ await ClosePushWindowExec();
+ }
+
+ //轮播图上一张
+ void MainImageBoxPre()
+ {
+
+ }
+
+ //轮播图上一张
+ void MainImageBoxNext()
+ {
+
+ }
+}