修正弹窗绑定错误

dev2.0
陈伟 2025-04-17 15:29:26 +08:00
parent 6968d5673d
commit a22b8071fa
4 changed files with 198 additions and 29 deletions

View File

@ -3,11 +3,66 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:h="https://github.com/HeBianGu" xmlns:h="https://github.com/HeBianGu"
xmlns:local="clr-namespace:HeBianGu.App.Disk" xmlns:local="clr-namespace:HeBianGu.App.Disk"
xmlns:provider="clr-namespace:Hopetry.Provider"> xmlns:provider="clr-namespace:Hopetry.Provider"
xmlns:models="clr-namespace:Hopetry.Models">
<h:ApplicationBase.Resources> <h:ApplicationBase.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries /> <ResourceDictionary.MergedDictionaries />
<provider:ViewModelLocator x:Key="S.ViewModelLocator.Locator" /> <provider:ViewModelLocator x:Key="S.ViewModelLocator.Locator" />
<DataTemplate DataType="{x:Type models:DownFolderSelect}">
<Grid Margin="100">
<Border Background="{DynamicResource {x:Static h:BrushKeys.BackgroundDefault}}"
CornerRadius="{DynamicResource {x:Static h:CornerRadiusKeys.CornerRadius}}" />
<DockPanel Margin="10" TextBlock.FontSize="18"
TextBlock.Foreground="{DynamicResource {x:Static h:BrushKeys.ForegroundDefault}}">
<TextBlock Margin="10"
HorizontalAlignment="Left"
DockPanel.Dock="Top"
FontSize="{StaticResource {x:Static h:FontSizeKeys.Header2}}"
FontWeight="Bold"
Text="设置下载路径" />
<h:Row>
<StackPanel Orientation="Horizontal">
<TextBox h:Cattach.Title="下载目录"
Style="{StaticResource {x:Static h:TextBoxKeys.LabelNone}}"
Text="{Binding Path=DownFolder, Mode=TwoWay}"
VerticalAlignment="Center" Width="250" />
<Button h:Cattach.Icon="&#xeadb;"
Command="{Binding Source={StaticResource S.ViewModelLocator.Locator},
Path= LoyoutViewModel.SelectDirCommand }"
VerticalAlignment="Center" />
</StackPanel>
</h:Row>
<Grid
HorizontalAlignment="Right"
VerticalAlignment="Center"
DockPanel.Dock="Bottom">
<Button Width="Auto"
Command="{x:Static h:ObjectContentDialog.Close}"
Content="kkkk" />
<Button Width="Auto"
HorizontalAlignment="Right"
Command="{x:Static h:ObjectContentDialog.Sumit}"
Content="确认" />
</Grid>
</DockPanel>
<Button Width="30"
Height="30"
Margin="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
h:Cattach.AllowsAnimation="True"
h:Cattach.Icon="&#xe72c;"
h:Cattach.IconSize="14"
h:Cattach.MouseOverForeground="{DynamicResource {x:Static h:BrushKeys.Red}}"
Command="{x:Static h:ObjectContentDialog.Close}"
Style="{DynamicResource {x:Static h:ButtonKeys.Transparent}}"
WindowChrome.IsHitTestVisibleInChrome="True" />
</Grid>
</DataTemplate>
<Style <Style
x:Key="{ComponentResourceKey ResourceId=S.ProgressBar.Custom, TypeInTargetAssembly={x:Type h:ProgressBarKeys}}" x:Key="{ComponentResourceKey ResourceId=S.ProgressBar.Custom, TypeInTargetAssembly={x:Type h:ProgressBarKeys}}"
BasedOn="{StaticResource {x:Static h:ProgressBarKeys.Dynamic}}" TargetType="ProgressBar"> BasedOn="{StaticResource {x:Static h:ProgressBarKeys.Dynamic}}" TargetType="ProgressBar">

View File

@ -0,0 +1,31 @@
using System.ComponentModel;
using HeBianGu.Base.WpfBase;
namespace Hopetry.Models;
public class DownFolderSelect : NotifyPropertyChangedBase
{
private bool _isSelect;
public bool IsSelect
{
get => _isSelect;
set
{
_isSelect = value;
RaisePropertyChanged();
}
}
private string _downFolder;
public string DownFolder
{
get => _downFolder;
set
{
_downFolder = value;
RaisePropertyChanged();
}
}
}

View File

@ -1,4 +1,5 @@
using HeBianGu.Base.WpfBase; using HeBianGu.App.Disk;
using HeBianGu.Base.WpfBase;
using Hopetry.ViewModel.Send; using Hopetry.ViewModel.Send;
using Hopetry.ViewModel.Sync; using Hopetry.ViewModel.Sync;
@ -10,9 +11,11 @@ namespace Hopetry.Provider
{ {
ServiceRegistry.Instance.Register<SyncViewModel>(); ServiceRegistry.Instance.Register<SyncViewModel>();
ServiceRegistry.Instance.Register<DownViewModel>(); ServiceRegistry.Instance.Register<DownViewModel>();
ServiceRegistry.Instance.Register<LoyoutViewModel>();
} }
public static SyncViewModel SyncViewModel => ServiceRegistry.Instance.GetInstance<SyncViewModel>(); public static SyncViewModel SyncViewModel => ServiceRegistry.Instance.GetInstance<SyncViewModel>();
public static DownViewModel DownViewModel => ServiceRegistry.Instance.GetInstance<DownViewModel>(); public static DownViewModel DownViewModel => ServiceRegistry.Instance.GetInstance<DownViewModel>();
public static LoyoutViewModel LoyoutViewModel => ServiceRegistry.Instance.GetInstance<LoyoutViewModel>();
} }
} }

View File

@ -17,6 +17,7 @@ using Minio;
using HeBianGu.Control.Explorer; using HeBianGu.Control.Explorer;
using Hopetry.Provider.Behaviors; using Hopetry.Provider.Behaviors;
using System.Text; using System.Text;
using HeBianGu.Control.Message;
using Hopetry.Provider; using Hopetry.Provider;
using Minio.DataModel; using Minio.DataModel;
using Minio.DataModel.Args; using Minio.DataModel.Args;
@ -28,6 +29,7 @@ namespace HeBianGu.App.Disk
internal class LoyoutViewModel : MvcViewModelBase internal class LoyoutViewModel : MvcViewModelBase
{ {
#region 参数定义及初始化 #region 参数定义及初始化
private readonly FileUploadService _uploadService; private readonly FileUploadService _uploadService;
private string _path; private string _path;
@ -67,6 +69,7 @@ namespace HeBianGu.App.Disk
RaisePropertyChanged("SharePath"); RaisePropertyChanged("SharePath");
} }
} }
protected override void Init() protected override void Init()
{ {
Path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); Path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
@ -90,16 +93,19 @@ namespace HeBianGu.App.Disk
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
new Action(() => { SelectLink = LinkActions[0]; })); new Action(() => { SelectLink = LinkActions[0]; }));
} }
protected override void Loaded(string args) protected override void Loaded(string args)
{ {
GetCompletedFiles(); GetCompletedFiles();
} }
#endregion #endregion
#region 文件上传 #region 文件上传
#region 参数定义 #region 参数定义
private SendViewModel _sendViewModel; private SendViewModel _sendViewModel;
private IConfiguration config; private IConfiguration config;
private SemaphoreSlim _semaphore = new SemaphoreSlim(5); private SemaphoreSlim _semaphore = new SemaphoreSlim(5);
@ -114,7 +120,7 @@ namespace HeBianGu.App.Disk
private int regionCount = 0; private int regionCount = 0;
private ExplorerMinIOBehavior _explorerBehavior; private ExplorerMinIOBehavior _explorerBehavior;
private MinIOSearchBehavior _minioBehavior; private MinIOSearchBehavior _minioBehavior;
public ICommand UploadCommand { get; } public ICommand UploadCommand { get; }
public ICommand UploadCommand1 { get; } public ICommand UploadCommand1 { get; }
@ -133,6 +139,7 @@ namespace HeBianGu.App.Disk
CreateFolderCommand = new AsyncRelayCommand(async () => await CreateNewFolderAsync()); CreateFolderCommand = new AsyncRelayCommand(async () => await CreateNewFolderAsync());
DeleteFolderCommand = new AsyncRelayCommand(async () => await DeleteSelectedItemsAsync()); DeleteFolderCommand = new AsyncRelayCommand(async () => await DeleteSelectedItemsAsync());
DownloadCommand = new AsyncRelayCommand(async () => await DoDownloadCommand()); DownloadCommand = new AsyncRelayCommand(async () => await DoDownloadCommand());
SelectDirCommand = new CustomCommand(async () => await DoSelectDirCommand());
//SelectItemsCommand = new AsyncRelayCommand(async () => await RelayCommand<SystemInfoModel>(SelectItem)SelectItem()); //SelectItemsCommand = new AsyncRelayCommand(async () => await RelayCommand<SystemInfoModel>(SelectItem)SelectItem());
// 初始化Timer // 初始化Timer
_progressTimer = new Timer(1000); _progressTimer = new Timer(1000);
@ -141,9 +148,32 @@ namespace HeBianGu.App.Disk
//加载上传完成列表 //加载上传完成列表
GetCompletedFiles(); GetCompletedFiles();
} }
private async Task DoSelectDirCommand()
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog
{
IsFolderPicker = true
};
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
var folderPath = dialog.FileName; // 获取选中的文件夹路径
// todo 设置文件夹
Application.Current.Dispatcher.Invoke(() =>
{
DownFolderSelect.DownFolder = folderPath;
Console.WriteLine($"选择文件夹:{folderPath}");
});
// 处理选中的文件夹路径
}
}
#endregion #endregion
#region 行为方法 #region 行为方法
// 添加设置Behavior的方法 // 添加设置Behavior的方法
public void SetExplorerBehavior(ExplorerMinIOBehavior behavior) public void SetExplorerBehavior(ExplorerMinIOBehavior behavior)
{ {
@ -154,9 +184,11 @@ namespace HeBianGu.App.Disk
{ {
_minioBehavior = behavior; _minioBehavior = behavior;
} }
#endregion #endregion
#region 更新总进度条 每隔1s更新一次 #region 更新总进度条 每隔1s更新一次
private void UpdateProgress(object sender, System.Timers.ElapsedEventArgs e) private void UpdateProgress(object sender, System.Timers.ElapsedEventArgs e)
{ {
lock (_timerLock) lock (_timerLock)
@ -194,9 +226,11 @@ namespace HeBianGu.App.Disk
} }
} }
} }
#endregion #endregion
#region 上传执行 #region 上传执行
//多文件上传 //多文件上传
private async Task UploadFile() private async Task UploadFile()
{ {
@ -227,14 +261,16 @@ namespace HeBianGu.App.Disk
MessageBox.Show("请选择上传路径"); MessageBox.Show("请选择上传路径");
return; return;
} }
foreach (string filePath in newFiles) foreach (string filePath in newFiles)
{ {
var fix = GetCurrentPrefix(); //获取当前所在的文件夹路径,除桶之外的 var fix = GetCurrentPrefix(); //获取当前所在的文件夹路径,除桶之外的
string str = System.IO.Path.GetFileName(filePath); string str = System.IO.Path.GetFileName(filePath);
if (!string.IsNullOrEmpty(fix)) if (!string.IsNullOrEmpty(fix))
{ {
str = fix + "/" + System.IO.Path.GetFileName(filePath); str = fix + "/" + System.IO.Path.GetFileName(filePath);
} }
var ut = CreateUploadItem(filePath, str); var ut = CreateUploadItem(filePath, str);
_sendViewModel.UpLoadItems.Add(ut); _sendViewModel.UpLoadItems.Add(ut);
} }
@ -276,6 +312,7 @@ namespace HeBianGu.App.Disk
MessageBox.Show("没有新文件需要上传或文件已在上传队列中"); MessageBox.Show("没有新文件需要上传或文件已在上传队列中");
return; return;
} }
//判断是否存在上传路径 //判断是否存在上传路径
string bucketName = GetCurrentBucket(); string bucketName = GetCurrentBucket();
if (string.IsNullOrEmpty(bucketName)) if (string.IsNullOrEmpty(bucketName))
@ -283,16 +320,18 @@ namespace HeBianGu.App.Disk
MessageBox.Show("请选择上传路径"); MessageBox.Show("请选择上传路径");
return; return;
} }
foreach (string filePath in files) foreach (string filePath in files)
{ {
var fix = GetCurrentPrefix(); //获取当前所在的文件夹路径,除桶之外的 var fix = GetCurrentPrefix(); //获取当前所在的文件夹路径,除桶之外的
string relativePath = string relativePath =
folderName + "/" + filePath.Substring(folderPath.Length + 1).Replace('\\', '/'); folderName + "/" + filePath.Substring(folderPath.Length + 1).Replace('\\', '/');
if (!string.IsNullOrEmpty(fix)) if (!string.IsNullOrEmpty(fix))
{ {
relativePath = fix + "/" + folderName + "/" + filePath.Substring(folderPath.Length + 1).Replace('\\', '/'); relativePath = fix + "/" + folderName + "/" +
filePath.Substring(folderPath.Length + 1).Replace('\\', '/');
} }
var ut = CreateUploadItem(filePath, relativePath); var ut = CreateUploadItem(filePath, relativePath);
_sendViewModel.UpLoadItems.Add(ut); _sendViewModel.UpLoadItems.Add(ut);
} }
@ -335,8 +374,8 @@ namespace HeBianGu.App.Disk
Value = System.IO.Path.GetFileName(filePath), Value = System.IO.Path.GetFileName(filePath),
Value3 = "等待上传", Value3 = "等待上传",
Value4 = fp.Id, //唯一标识,与数据库一致 Value4 = fp.Id, //唯一标识,与数据库一致
Value5 = filePath, //文件名称 Value5 = filePath, //文件名称
Value6 = objectName, //文件地址 Value6 = objectName, //文件地址
Double1 = fileInfo.Length, Double1 = fileInfo.Length,
Double2 = 0.0, Double2 = 0.0,
Bool1 = false, Bool1 = false,
@ -481,9 +520,11 @@ namespace HeBianGu.App.Disk
Application.Current.Dispatcher.Invoke(() => { ut.Value3 = $"上传失败: {ex.Message}"; }); Application.Current.Dispatcher.Invoke(() => { ut.Value3 = $"上传失败: {ex.Message}"; });
} }
} }
#endregion #endregion
#region 其他 #region 其他
//关机 //关机
private void Shutdown() private void Shutdown()
{ {
@ -507,7 +548,7 @@ namespace HeBianGu.App.Disk
//加载初始完成文件 //加载初始完成文件
public void GetCompletedFiles() public void GetCompletedFiles()
{ {
var files= _uploadService.GetAllFiles().Where(r=>r.IsComplete==true).ToList(); var files = _uploadService.GetAllFiles().Where(r => r.IsComplete == true).ToList();
ObservableCollection<UpLoadItems> up = new ObservableCollection<UpLoadItems>(); ObservableCollection<UpLoadItems> up = new ObservableCollection<UpLoadItems>();
foreach (var file in files) foreach (var file in files)
{ {
@ -516,46 +557,83 @@ namespace HeBianGu.App.Disk
upLoadItems.Value4 = file.Id; upLoadItems.Value4 = file.Id;
upLoadItems.Value5 = file.FilePath; upLoadItems.Value5 = file.FilePath;
upLoadItems.Value1 = file.FileSizeText; upLoadItems.Value1 = file.FileSizeText;
upLoadItems.Value6=file.FileName; upLoadItems.Value6 = file.FileName;
upLoadItems.Value7=file.CompleteTime.ToString("yyyy-MM-dd HH:mm:ss"); upLoadItems.Value7 = file.CompleteTime.ToString("yyyy-MM-dd HH:mm:ss");
up.Add(upLoadItems); up.Add(upLoadItems);
} }
_sendViewModel.CompleteItems.Clear(); _sendViewModel.CompleteItems.Clear();
_sendViewModel.CompleteItems.AddRange(up); _sendViewModel.CompleteItems.AddRange(up);
regionCount = up.Count; regionCount = up.Count;
_sendViewModel.CompleteCount=regionCount; _sendViewModel.CompleteCount = regionCount;
} }
#endregion #endregion
#endregion #endregion
#region 文件下载 #region 文件下载
private DownFolderSelect _downFolderSelect = new DownFolderSelect();
public DownFolderSelect DownFolderSelect
{
get => _downFolderSelect;
set
{
_downFolderSelect = value;
RaisePropertyChanged();
}
}
private async Task DoDownloadCommand() private async Task DoDownloadCommand()
{ {
// todo 当为文件时,处理 // todo 当为文件时,处理
var selectedItems = _selectedItems; var tempSelectedItems = new ObservableCollection<SystemInfoModel>(SelectedItems);
// 清除选中 SelectedItems.Clear();
//SelectedItems = []; if (tempSelectedItems.Count > 0)
foreach (var item in selectedItems)
{ {
if (item is MinIOFileModel file) if (string.IsNullOrEmpty(DownFolderSelect.DownFolder))
{ {
var temp = (MinIOFileInfo)file.Model; DownFolderSelect.DownFolder = "d:/abc";
var objectKey = temp.FullName.Replace(temp.BucketName + "/", "");
ViewModelLocator.DownViewModel.AddTask(temp.BucketName, objectKey, temp.Size);
} }
bool r = await MessageProxy.Presenter.Show(DownFolderSelect, x => true, "下载目录选择", x =>
if (item is MinIODirectoryModel dir)
{ {
Console.WriteLine("建设中..."); x.Width = 800;
//return ((MinIODirectoryInfo)dir.Model).BucketName; x.Height = 450;
//x.Padding = new System.Windows.Thickness(10);
//x.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
//x.VerticalAlignment = System.Windows.VerticalAlignment.Center;
}, ObjectContentDialog.ClearKey);
if (r)
{
// todo 开始下载
foreach (var item in tempSelectedItems)
{
if (item is MinIOFileModel file)
{
var temp = (MinIOFileInfo)file.Model;
var objectKey = temp.FullName.Replace(temp.BucketName + "/", "");
ViewModelLocator.DownViewModel.AddTask(temp.BucketName, objectKey, temp.Size);
MessageProxy.Snacker.Show($"{temp.Name} 加入下载队列");
}
if (item is MinIODirectoryModel dir)
{
Console.WriteLine("建设中...");
//return ((MinIODirectoryInfo)dir.Model).BucketName;
}
}
} }
} }
} }
#endregion #endregion
#region 文件列表 #region 文件列表
private string _currentMinIOPath; private string _currentMinIOPath;
/// <summary> 说明CurrentMinIOPath </summary> /// <summary> 说明CurrentMinIOPath </summary>
public string CurrentMinIOPath public string CurrentMinIOPath
{ {
@ -701,6 +779,8 @@ namespace HeBianGu.App.Disk
public ICommand SelectItemsCommand => _selectItemsCommand ?? public ICommand SelectItemsCommand => _selectItemsCommand ??
(_selectItemsCommand = new RelayCommand<SystemInfoModel>(SelectItem)); (_selectItemsCommand = new RelayCommand<SystemInfoModel>(SelectItem));
public ICommand SelectDirCommand { get; set; }
private void SelectItem(SystemInfoModel item) private void SelectItem(SystemInfoModel item)
{ {
if (item == null) return; if (item == null) return;