feat: Better-Seewo v2.0.0 - 希沃白板功能增强插件
- Fluent Design 风格 UI,深色/浅色主题切换 - 平滑过渡动画(页面切换、按钮交互、状态变化) - 五大核心功能:安装管理、墨迹管理、格式转换、触摸设置、激活管理 - 基于 dotnetCampus.EasiPlugin.Sdk v2.1.1-alpha.3 插件框架 - WPF 安装向导(欢迎页 -> 安装页 -> 完成页)
This commit is contained in:
284
Manager/Pages/ConvertPage.xaml.cs
Normal file
284
Manager/Pages/ConvertPage.xaml.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Better_Seewo.Manager.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// ConvertPage.xaml 的交互逻辑
|
||||
/// 格式转换页面 - PPTX 与 ENBX 格式互转
|
||||
/// </summary>
|
||||
public partial class ConvertPage : Page
|
||||
{
|
||||
// ===== 选中的文件路径 =====
|
||||
private string _selectedPptxFile = string.Empty;
|
||||
private string _selectedEnbxFile = string.Empty;
|
||||
private string _outputFile = string.Empty;
|
||||
|
||||
public ConvertPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += ConvertPage_Loaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 页面加载时播放入场动画
|
||||
/// </summary>
|
||||
private void ConvertPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 简单淡入
|
||||
var fadeIn = new DoubleAnimation
|
||||
{
|
||||
From = 0,
|
||||
To = 1,
|
||||
Duration = TimeSpan.FromMilliseconds(400),
|
||||
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
|
||||
};
|
||||
BeginAnimation(OpacityProperty, fadeIn);
|
||||
}
|
||||
|
||||
// ===== Tab 切换事件 =====
|
||||
|
||||
/// <summary>
|
||||
/// 切换到 PPTX -> ENBX 模式(带滑动指示器动画)
|
||||
/// </summary>
|
||||
private void TabPptxToEnbx_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PanelPptxToEnbx.Visibility = Visibility.Visible;
|
||||
PanelEnbxToPptx.Visibility = Visibility.Collapsed;
|
||||
|
||||
// 滑动指示器动画
|
||||
AnimateTabIndicator(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换到 ENBX -> PPTX 模式(带滑动指示器动画)
|
||||
/// </summary>
|
||||
private void TabEnbxToPptx_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PanelPptxToEnbx.Visibility = Visibility.Collapsed;
|
||||
PanelEnbxToPptx.Visibility = Visibility.Visible;
|
||||
|
||||
// 滑动指示器动画
|
||||
AnimateTabIndicator(120);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tab滑动指示器动画
|
||||
/// </summary>
|
||||
private void AnimateTabIndicator(double targetX)
|
||||
{
|
||||
var transform = (TranslateTransform)TabIndicator.RenderTransform;
|
||||
var animation = new DoubleAnimation
|
||||
{
|
||||
From = transform.X,
|
||||
To = targetX,
|
||||
Duration = TimeSpan.FromMilliseconds(300),
|
||||
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
|
||||
};
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, animation);
|
||||
}
|
||||
|
||||
// ===== 文件选择事件 =====
|
||||
|
||||
/// <summary>
|
||||
/// 选择 PPTX 文件
|
||||
/// </summary>
|
||||
private void BtnSelectPptx_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "PowerPoint 文件 (*.pptx)|*.pptx",
|
||||
DefaultExt = ".pptx",
|
||||
Title = "选择 PPTX 文件"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
_selectedPptxFile = dialog.FileName;
|
||||
PptxFileNameText.Text = Path.GetFileName(dialog.FileName);
|
||||
BtnConvertPptxToEnbx.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择 ENBX 文件
|
||||
/// </summary>
|
||||
private void BtnSelectEnbx_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "希沃白板文件 (*.enbx)|*.enbx",
|
||||
DefaultExt = ".enbx",
|
||||
Title = "选择 ENBX 文件"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
_selectedEnbxFile = dialog.FileName;
|
||||
EnbxFileNameText.Text = Path.GetFileName(dialog.FileName);
|
||||
BtnConvertEnbxToPptx.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 转换按钮事件 =====
|
||||
|
||||
/// <summary>
|
||||
/// PPTX -> ENBX 转换
|
||||
/// </summary>
|
||||
private async void BtnConvertPptxToEnbx_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_selectedPptxFile)) return;
|
||||
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
ConvertProgressPanel.Visibility = Visibility.Visible;
|
||||
ConvertResultPanel.Visibility = Visibility.Collapsed;
|
||||
BtnConvertPptxToEnbx.IsEnabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
ConvertStatusText.Text = "正在读取PPTX文件...";
|
||||
await AnimateConvertProgressAsync(0, 30, 800);
|
||||
|
||||
// TODO: 实际转换逻辑
|
||||
ConvertStatusText.Text = "正在解析页面结构...";
|
||||
await AnimateConvertProgressAsync(30, 60, 1000);
|
||||
|
||||
ConvertStatusText.Text = "正在生成ENBX文件...";
|
||||
await AnimateConvertProgressAsync(60, 90, 1000);
|
||||
|
||||
ConvertStatusText.Text = "正在完成...";
|
||||
await AnimateConvertProgressAsync(90, 100, 500);
|
||||
|
||||
stopwatch.Stop();
|
||||
|
||||
// 模拟输出文件
|
||||
_outputFile = Path.ChangeExtension(_selectedPptxFile, ".enbx");
|
||||
ShowConvertResult(_outputFile, "模拟文件", stopwatch.Elapsed);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ConvertProgressPanel.Visibility = Visibility.Collapsed;
|
||||
BtnConvertPptxToEnbx.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ENBX -> PPTX 转换
|
||||
/// </summary>
|
||||
private async void BtnConvertEnbxToPptx_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_selectedEnbxFile)) return;
|
||||
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
ConvertProgressPanel.Visibility = Visibility.Visible;
|
||||
ConvertResultPanel.Visibility = Visibility.Collapsed;
|
||||
BtnConvertEnbxToPptx.IsEnabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
ConvertStatusText.Text = "正在读取ENBX文件...";
|
||||
await AnimateConvertProgressAsync(0, 25, 600);
|
||||
|
||||
// TODO: 实际转换逻辑
|
||||
ConvertStatusText.Text = "正在提取资源...";
|
||||
await AnimateConvertProgressAsync(25, 55, 1000);
|
||||
|
||||
ConvertStatusText.Text = "正在构建PPTX...";
|
||||
await AnimateConvertProgressAsync(55, 85, 1200);
|
||||
|
||||
ConvertStatusText.Text = "正在完成...";
|
||||
await AnimateConvertProgressAsync(85, 100, 400);
|
||||
|
||||
stopwatch.Stop();
|
||||
|
||||
_outputFile = Path.ChangeExtension(_selectedEnbxFile, ".pptx");
|
||||
ShowConvertResult(_outputFile, "模拟文件", stopwatch.Elapsed);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ConvertProgressPanel.Visibility = Visibility.Collapsed;
|
||||
BtnConvertEnbxToPptx.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进度条平滑填充动画
|
||||
/// </summary>
|
||||
private async Task AnimateConvertProgressAsync(int from, int to, int durationMs)
|
||||
{
|
||||
int totalWidth = 800; // 假设进度条最大宽度
|
||||
var steps = 15;
|
||||
var stepMs = durationMs / steps;
|
||||
var increment = (double)(to - from) / steps;
|
||||
|
||||
for (int i = 0; i <= steps; i++)
|
||||
{
|
||||
var percent = from + increment * i;
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
var targetWidth = totalWidth * (percent / 100.0);
|
||||
|
||||
// 平滑动画更新进度条宽度
|
||||
var widthAnimation = new DoubleAnimation
|
||||
{
|
||||
From = ConvertProgressBar.Width,
|
||||
To = targetWidth,
|
||||
Duration = TimeSpan.FromMilliseconds(stepMs),
|
||||
EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseInOut }
|
||||
};
|
||||
ConvertProgressBar.BeginAnimation(WidthProperty, widthAnimation);
|
||||
|
||||
ConvertPercentText.Text = $"{(int)Math.Round(percent)}%";
|
||||
});
|
||||
|
||||
await Task.Delay(stepMs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示转换结果
|
||||
/// </summary>
|
||||
private void ShowConvertResult(string filePath, string fileSize, TimeSpan elapsed)
|
||||
{
|
||||
ConvertResultPanel.Visibility = Visibility.Visible;
|
||||
OutputFilePath.Text = Path.GetFileName(filePath);
|
||||
OutputFileSize.Text = fileSize;
|
||||
ConvertTime.Text = $"{elapsed.TotalMilliseconds:F0} ms";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开输出文件
|
||||
/// </summary>
|
||||
private void BtnOpenOutput_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_outputFile) && File.Exists(_outputFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = _outputFile,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("无法打开文件,文件可能不存在。", "提示",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("输出文件尚不存在(当前为模拟转换)。", "提示",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user