增强原材料卡片管理功能,新增免密接口和数据处理逻辑,支持原材料卡片的增删改查操作。更新前端视图以支持多行拆码明细拼接,优化用户体验和系统实时数据同步能力。
This commit is contained in:
@@ -1,30 +1,118 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using YY.Admin.ViewModels.RawMaterialEntry;
|
||||
|
||||
namespace YY.Admin.Views.RawMaterialEntry;
|
||||
|
||||
public partial class RawMaterialEntryOperationView : UserControl
|
||||
{
|
||||
private RawMaterialEntryOperationViewModel? _vm;
|
||||
private bool _initialized;
|
||||
|
||||
public RawMaterialEntryOperationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += OnLoaded;
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
Unloaded += (_, _) => DetachVm();
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
DetachVm();
|
||||
if (DataContext is RawMaterialEntryOperationViewModel vm)
|
||||
{
|
||||
_vm = vm;
|
||||
vm.PropertyChanged += OnVmPropertyChanged;
|
||||
}
|
||||
|
||||
ApplySplitLayout();
|
||||
}
|
||||
|
||||
private void DetachVm()
|
||||
{
|
||||
if (_vm != null)
|
||||
{
|
||||
_vm.PropertyChanged -= OnVmPropertyChanged;
|
||||
_vm = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnVmPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
// null/空 表示“所有属性”通知(Prism/BindableBase 批量刷新时),需同步分割布局
|
||||
if (!string.IsNullOrEmpty(e.PropertyName)
|
||||
&& e.PropertyName is not nameof(RawMaterialEntryOperationViewModel.IsRightPanelExpanded)
|
||||
&& e.PropertyName is not nameof(RawMaterialEntryOperationViewModel.ExpandedRightPanelWidth))
|
||||
return;
|
||||
|
||||
_ = Dispatcher.InvokeAsync(ApplySplitLayout);
|
||||
}
|
||||
|
||||
/// <summary>按钮 Click 在 Command 之后执行,用于兜底刷新列宽(不重复切换状态)。</summary>
|
||||
private void ToggleTodayPanelButton_OnClick(object sender, RoutedEventArgs e) => ApplySplitLayout();
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 兜底:XAML 解析 prism:AutoWireViewModel 时设置 DataContext 早于构造函数订阅 DataContextChanged,
|
||||
// 首次进入页面 OnDataContextChanged 会错过回调,导致 _vm 为 null、PropertyChanged 未挂接,
|
||||
// 表现为「首次点击展开/收起按钮不生效」。这里在 Loaded 时补一次订阅。
|
||||
EnsureVmAttached();
|
||||
|
||||
if (DataContext is RawMaterialEntryEditDialogViewModel vm)
|
||||
ApplySplitLayout();
|
||||
|
||||
if (DataContext is RawMaterialEntryOperationViewModel vm && !_initialized)
|
||||
{
|
||||
vm.InitializeForAdd();
|
||||
_initialized = true;
|
||||
_ = vm.LoadTodayEntriesOnFirstShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureVmAttached()
|
||||
{
|
||||
if (_vm != null) return;
|
||||
if (DataContext is RawMaterialEntryOperationViewModel vm)
|
||||
{
|
||||
_vm = vm;
|
||||
vm.PropertyChanged += OnVmPropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 ViewModel 同步右侧栏与分割条:展开时使用持久化宽度;折叠时右栏与分割条占宽均为 0(完全隐藏)。
|
||||
/// </summary>
|
||||
private void ApplySplitLayout()
|
||||
{
|
||||
var vm = _vm ?? DataContext as RawMaterialEntryOperationViewModel;
|
||||
if (vm == null) return;
|
||||
|
||||
if (vm.IsRightPanelExpanded)
|
||||
{
|
||||
RightPaneSplitter.Visibility = Visibility.Visible;
|
||||
SplitterCol.Width = new GridLength(4);
|
||||
RightPaneCol.Width = new GridLength(vm.ExpandedRightPanelWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
RightPaneSplitter.Visibility = Visibility.Collapsed;
|
||||
SplitterCol.Width = new GridLength(0);
|
||||
RightPaneCol.Width = new GridLength(0);
|
||||
}
|
||||
|
||||
MainSplitRoot.InvalidateMeasure();
|
||||
MainSplitRoot.UpdateLayout();
|
||||
}
|
||||
|
||||
private void RightPaneSplitter_OnDragCompleted(object sender, DragCompletedEventArgs e)
|
||||
{
|
||||
var vm = _vm ?? DataContext as RawMaterialEntryOperationViewModel;
|
||||
if (vm == null || !vm.IsRightPanelExpanded || e.Canceled) return;
|
||||
|
||||
var w = RightPaneCol.ActualWidth;
|
||||
if (w >= 120)
|
||||
vm.CommitRightPanelWidthFromView(w);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user