新增物料类型处理逻辑,确保在保存和编辑称重记录时自动设置默认物料类型。更新前端表单以支持密炼物料的选择和显示,优化用户体验。添加分类字典和数据字典的事件广播功能,增强系统的实时数据同步能力。

This commit is contained in:
geht
2026-05-07 17:53:48 +08:00
parent ce9dc8efd8
commit f60a4fb203
55 changed files with 2968 additions and 375 deletions

View File

@@ -1,6 +1,8 @@
using HandyControl.Controls;
using Prism.Events;
using System.Collections.ObjectModel;
using YY.Admin.Core;
using YY.Admin.Core.Events;
using YY.Admin.Core.Helper;
using YY.Admin.Services.Service.Category;
using YY.Admin.Services.Service.Category.Dto;
@@ -11,6 +13,7 @@ namespace YY.Admin.ViewModels.SysManage;
public class CategoryDictionaryManagementViewModel : BaseViewModel
{
private readonly IJeecgCategorySyncService _categorySyncService;
private SubscriptionToken? _categoryChangedToken;
private PaginationDataGridViewModel<JeecgCategoryItemOutput> _paginationDataGridViewModel;
public PaginationDataGridViewModel<JeecgCategoryItemOutput> PaginationDataGridViewModel
@@ -28,7 +31,6 @@ public class CategoryDictionaryManagementViewModel : BaseViewModel
public DelegateCommand SearchCommand { get; }
public DelegateCommand ResetCommand { get; }
public DelegateCommand SyncCommand { get; }
public ObservableCollection<CategoryTreeNode> TreeNodes { get; } = [];
private CategoryTreeNode? _selectedTreeNode;
@@ -49,7 +51,10 @@ public class CategoryDictionaryManagementViewModel : BaseViewModel
SearchCommand = new DelegateCommand(async () => await SearchAsync());
ResetCommand = new DelegateCommand(async () => await ResetAsync());
SyncCommand = new DelegateCommand(async () => await SyncAsync());
_categoryChangedToken = _eventAggregator
.GetEvent<CategoryChangedEvent>()
.Subscribe(async _ => await OnCategoryChangedAsync(), ThreadOption.UIThread);
_ = InitializeAsync();
}
@@ -84,21 +89,6 @@ public class CategoryDictionaryManagementViewModel : BaseViewModel
await SearchAsync();
}
private async Task SyncAsync()
{
var count = await _categorySyncService.SyncFromJeecgAsync();
if (count > 0)
{
Growl.Success($"同步完成,共处理 {count} 条分类字典数据");
}
else
{
Growl.Warning("未同步到分类字典,请确认后端可访问");
}
await LoadTreeAsync();
await SearchAsync();
}
public async Task OnTreeSelectedAsync(CategoryTreeNode? node)
{
SelectedTreeNode = node;
@@ -131,6 +121,22 @@ public class CategoryDictionaryManagementViewModel : BaseViewModel
return node;
}
private async Task OnCategoryChangedAsync()
{
await LoadTreeAsync();
await PaginationDataGridViewModel.LoadDataAsync();
}
protected override void CleanUp()
{
base.CleanUp();
if (_categoryChangedToken != null)
{
_eventAggregator.GetEvent<CategoryChangedEvent>().Unsubscribe(_categoryChangedToken);
_categoryChangedToken = null;
}
}
public class CategoryTreeNode
{
public string Id { get; set; } = string.Empty;

View File

@@ -1,5 +1,7 @@
using HandyControl.Controls;
using Prism.Events;
using System.Collections.ObjectModel;
using YY.Admin.Core;
using YY.Admin.Core.Events;
using YY.Admin.Core.Extension;
using YY.Admin.Core.Helper;
using YY.Admin.Services.Service;
@@ -10,6 +12,16 @@ namespace YY.Admin.ViewModels.SysManage;
public class DataDictionaryManagementViewModel : BaseViewModel
{
private readonly IJeecgDictSyncService _dictSyncService;
private SubscriptionToken? _dictChangedToken;
public ObservableCollection<DictTreeNode> TreeNodes { get; } = [];
private DictTreeNode? _selectedTreeNode;
public DictTreeNode? SelectedTreeNode
{
get => _selectedTreeNode;
set => SetProperty(ref _selectedTreeNode, value);
}
private PaginationDataGridViewModel<JeecgDictItemOutput> _paginationDataGridViewModel;
public PaginationDataGridViewModel<JeecgDictItemOutput> PaginationDataGridViewModel
@@ -33,7 +45,6 @@ public class DataDictionaryManagementViewModel : BaseViewModel
public DelegateCommand SearchCommand { get; }
public DelegateCommand ResetCommand { get; }
public DelegateCommand SyncCommand { get; }
public DataDictionaryManagementViewModel(
IJeecgDictSyncService dictSyncService,
@@ -46,13 +57,17 @@ public class DataDictionaryManagementViewModel : BaseViewModel
SearchCommand = new DelegateCommand(async () => await SearchAsync());
ResetCommand = new DelegateCommand(async () => await ResetAsync());
SyncCommand = new DelegateCommand(async () => await SyncAsync());
_dictChangedToken = _eventAggregator
.GetEvent<DictChangedEvent>()
.Subscribe(async _ => await OnDictChangedAsync(), ThreadOption.UIThread);
_ = InitializeAsync();
}
private async Task InitializeAsync()
{
await LoadDictTreeAsync();
await UIHelper.WaitForRenderAsync();
await PaginationDataGridViewModel.LoadDataAsync();
}
@@ -74,21 +89,54 @@ public class DataDictionaryManagementViewModel : BaseViewModel
private async Task ResetAsync()
{
Input = new PageJeecgDictItemInput();
SelectedTreeNode = null;
await UIHelper.WaitForRenderAsync();
await SearchAsync();
}
private async Task SyncAsync()
public async Task OnDictTreeSelectedAsync(DictTreeNode? node)
{
var count = await _dictSyncService.SyncFromJeecgAsync();
if (count > 0)
{
Growl.Success($"同步完成,共处理 {count} 条数据字典项");
}
else
{
Growl.Warning("未同步到数据字典,请确认后端可访问");
}
SelectedTreeNode = node;
Input.DictCode = node?.DictCode;
await SearchAsync();
}
private async Task LoadDictTreeAsync()
{
var groups = await _dictSyncService.GetDictGroupsAsync();
TreeNodes.Clear();
foreach (var group in groups)
{
TreeNodes.Add(new DictTreeNode(group.Key, group.Value));
}
}
private async Task OnDictChangedAsync()
{
await LoadDictTreeAsync();
await PaginationDataGridViewModel.LoadDataAsync();
}
protected override void CleanUp()
{
base.CleanUp();
if (_dictChangedToken != null)
{
_eventAggregator.GetEvent<DictChangedEvent>().Unsubscribe(_dictChangedToken);
_dictChangedToken = null;
}
}
public class DictTreeNode
{
public string DictCode { get; }
public string DictName { get; }
public string DisplayName => $"[{DictCode}] {DictName}";
public DictTreeNode(string dictCode, string dictName)
{
DictCode = dictCode;
DictName = dictName;
}
}
}