day 2
This commit is contained in:
parent
7f2284efc5
commit
e872682d37
@ -21,4 +21,5 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
</Application>
|
@ -14,7 +14,7 @@
|
||||
<SolidColorBrush x:Key="BgBody" Color="GhostWhite" />
|
||||
<SolidColorBrush x:Key="TexPrimary" Color="Black" />
|
||||
<!-- 内容主题 -->
|
||||
<SolidColorBrush x:Key="BodyValueBg" Color="SlateGray" />
|
||||
<SolidColorBrush x:Key="BodyValueBg" Color="White" />
|
||||
</ResourceDictionary>
|
||||
|
||||
<!-- 夜晚主题 -->
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -3,17 +3,23 @@
|
||||
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">
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
<Grid RowDefinitions="Auto, *, Auto">
|
||||
<Grid>
|
||||
<!-- 现有的内容 -->
|
||||
<Grid x:Name="MainContent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" /> <!-- Top Bar -->
|
||||
<RowDefinition Height="*" /> <!-- Middle Area -->
|
||||
<RowDefinition Height="Auto" /> <!-- Bottom Bar -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Top Bar -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource BgBody}" Height="50" Opacity="1.0">
|
||||
<Border Grid.Row="0" Background="{DynamicResource BgBody}" Height="50">
|
||||
<Grid>
|
||||
<Image Source="{Binding LogoUrl}"
|
||||
Width="30"
|
||||
@ -27,28 +33,54 @@
|
||||
FontSize="20"
|
||||
Margin="50 0 0 0"/>
|
||||
<Button Content="{Binding MyValue}"
|
||||
x:Name="OpenPushWindow"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0 0 15 0"></Button>
|
||||
Margin="0 0 15 0"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Middle Area with ScrollViewer -->
|
||||
<ScrollViewer Grid.Row="1" Background="{DynamicResource BodyValueBg}">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" /> <!-- Top Bar -->
|
||||
<RowDefinition Height="*" /> <!-- Middle Area -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" >
|
||||
<Border HorizontalAlignment="Center" Margin=" 6" x:Name="MainBox" CornerRadius="6" ClipToBounds="True">
|
||||
<StackPanel Orientation="Horizontal" Spacing="0" x:Name="MainImageBox">
|
||||
<Image Source="{Binding MainImage1}"
|
||||
x:Name="MainImages1"
|
||||
Stretch="UniformToFill" />
|
||||
<Image Source="{Binding MainImage2}"
|
||||
x:Name="MainImages2"
|
||||
Stretch="UniformToFill" />
|
||||
<Image Source="{Binding MainImage3}"
|
||||
x:Name="MainImages3"
|
||||
Stretch="UniformToFill" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<!-- <StackPanel> -->
|
||||
<!-- -->
|
||||
<!-- <TextBlock Name="DebugTextBlock" Text="{Binding DebugText}"/> -->
|
||||
<!-- <TextBlock x:Name="Fuck" Text="v"/> -->
|
||||
<!-- </StackPanel> -->
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Bottom Bar -->
|
||||
<Border Grid.Row="2" Height="50" Opacity="1.0" Background="{DynamicResource BgBody}">
|
||||
<Border Grid.Row="2" Height="50" Background="{DynamicResource BgBody}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" /> <!-- 左边占比空间 -->
|
||||
<ColumnDefinition Width="Auto" /> <!-- 第一个按钮 -->
|
||||
<ColumnDefinition Width="0.8*" /> <!-- 右边空间 -->
|
||||
<ColumnDefinition Width="Auto" /> <!-- 第二个按钮 -->
|
||||
<ColumnDefinition Width="0.8*" /> <!-- 右边空间 -->
|
||||
<ColumnDefinition Width="Auto" /> <!-- 第三个按钮 -->
|
||||
<ColumnDefinition Width="*" /> <!-- 右边占比空间 -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="0.8*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="0.8*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="1" Content="{Binding Friendly}"
|
||||
@ -63,5 +95,38 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<!-- <TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/> -->
|
||||
|
||||
<!-- 侧边栏 -->
|
||||
<Border Grid.Column="0" Background="{DynamicResource BgBody}" x:Name="PushWindow" IsVisible="True" ZIndex="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" /> <!-- Top Bar -->
|
||||
<RowDefinition Height="*" /> <!-- Middle Area -->
|
||||
<RowDefinition Height="Auto" /> <!-- Bottom Bar -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Height="50">
|
||||
<Image Source="{Binding UpLoadUrl}"
|
||||
Width="30"
|
||||
Stretch="Uniform"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="10 0 0 0"/>
|
||||
<TextBlock Text="{Binding UpLoadTitle}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource TexPrimary}"
|
||||
FontSize="20"
|
||||
Margin="50 0 0 0"/>
|
||||
<Button Content="{Binding CloseMyValue}"
|
||||
x:Name="ClosePushWindow"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0 0 15 0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
@ -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;
|
||||
}
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user