2026-05-07 17:53:48 +08:00
|
|
|
using Prism.Events;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2026-04-28 10:23:58 +08:00
|
|
|
using YY.Admin.Core;
|
2026-05-07 17:53:48 +08:00
|
|
|
using YY.Admin.Core.Events;
|
2026-04-28 10:23:58 +08:00
|
|
|
using YY.Admin.Core.Extension;
|
|
|
|
|
using YY.Admin.Core.Helper;
|
|
|
|
|
using YY.Admin.Services.Service;
|
|
|
|
|
using YY.Admin.ViewModels.Control;
|
|
|
|
|
|
|
|
|
|
namespace YY.Admin.ViewModels.SysManage;
|
|
|
|
|
|
|
|
|
|
public class DataDictionaryManagementViewModel : BaseViewModel
|
|
|
|
|
{
|
|
|
|
|
private readonly IJeecgDictSyncService _dictSyncService;
|
2026-05-07 17:53:48 +08:00
|
|
|
private SubscriptionToken? _dictChangedToken;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<DictTreeNode> TreeNodes { get; } = [];
|
|
|
|
|
|
|
|
|
|
private DictTreeNode? _selectedTreeNode;
|
|
|
|
|
public DictTreeNode? SelectedTreeNode
|
|
|
|
|
{
|
|
|
|
|
get => _selectedTreeNode;
|
|
|
|
|
set => SetProperty(ref _selectedTreeNode, value);
|
|
|
|
|
}
|
2026-04-28 10:23:58 +08:00
|
|
|
|
|
|
|
|
private PaginationDataGridViewModel<JeecgDictItemOutput> _paginationDataGridViewModel;
|
|
|
|
|
public PaginationDataGridViewModel<JeecgDictItemOutput> PaginationDataGridViewModel
|
|
|
|
|
{
|
|
|
|
|
get => _paginationDataGridViewModel;
|
|
|
|
|
set => SetProperty(ref _paginationDataGridViewModel, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PageJeecgDictItemInput _input;
|
|
|
|
|
public PageJeecgDictItemInput Input
|
|
|
|
|
{
|
|
|
|
|
get => _input;
|
|
|
|
|
set => SetProperty(ref _input, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<KeyValuePair<string, int>> StatusList =>
|
|
|
|
|
Enum.GetValues(typeof(StatusEnum))
|
|
|
|
|
.Cast<StatusEnum>()
|
|
|
|
|
.Select(e => new KeyValuePair<string, int>(e.GetDescription(), (int)e))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
public DelegateCommand SearchCommand { get; }
|
|
|
|
|
public DelegateCommand ResetCommand { get; }
|
|
|
|
|
|
|
|
|
|
public DataDictionaryManagementViewModel(
|
|
|
|
|
IJeecgDictSyncService dictSyncService,
|
|
|
|
|
IContainerExtension container,
|
|
|
|
|
IRegionManager regionManager) : base(container, regionManager)
|
|
|
|
|
{
|
|
|
|
|
_dictSyncService = dictSyncService;
|
|
|
|
|
_paginationDataGridViewModel = new PaginationDataGridViewModel<JeecgDictItemOutput>(FetchAsync);
|
|
|
|
|
_input = new PageJeecgDictItemInput();
|
|
|
|
|
|
|
|
|
|
SearchCommand = new DelegateCommand(async () => await SearchAsync());
|
|
|
|
|
ResetCommand = new DelegateCommand(async () => await ResetAsync());
|
2026-05-07 17:53:48 +08:00
|
|
|
|
|
|
|
|
_dictChangedToken = _eventAggregator
|
|
|
|
|
.GetEvent<DictChangedEvent>()
|
|
|
|
|
.Subscribe(async _ => await OnDictChangedAsync(), ThreadOption.UIThread);
|
2026-04-28 10:23:58 +08:00
|
|
|
|
|
|
|
|
_ = InitializeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task InitializeAsync()
|
|
|
|
|
{
|
2026-05-07 17:53:48 +08:00
|
|
|
await LoadDictTreeAsync();
|
2026-04-28 10:23:58 +08:00
|
|
|
await UIHelper.WaitForRenderAsync();
|
|
|
|
|
await PaginationDataGridViewModel.LoadDataAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<(IEnumerable<JeecgDictItemOutput> data, int totalCount)> FetchAsync()
|
|
|
|
|
{
|
|
|
|
|
Input.Page = PaginationDataGridViewModel.PageIndex;
|
|
|
|
|
Input.PageSize = PaginationDataGridViewModel.DataCountPerPage;
|
|
|
|
|
var result = await _dictSyncService.PageAsync(Input);
|
|
|
|
|
return (result.Items, result.Total);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SearchAsync()
|
|
|
|
|
{
|
|
|
|
|
PaginationDataGridViewModel.PageIndex = 1;
|
|
|
|
|
await PaginationDataGridViewModel.LoadDataAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ResetAsync()
|
|
|
|
|
{
|
|
|
|
|
Input = new PageJeecgDictItemInput();
|
2026-05-07 17:53:48 +08:00
|
|
|
SelectedTreeNode = null;
|
2026-04-28 10:23:58 +08:00
|
|
|
await UIHelper.WaitForRenderAsync();
|
|
|
|
|
await SearchAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 17:53:48 +08:00
|
|
|
public async Task OnDictTreeSelectedAsync(DictTreeNode? node)
|
|
|
|
|
{
|
|
|
|
|
SelectedTreeNode = node;
|
|
|
|
|
Input.DictCode = node?.DictCode;
|
|
|
|
|
await SearchAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadDictTreeAsync()
|
2026-04-28 10:23:58 +08:00
|
|
|
{
|
2026-05-07 17:53:48 +08:00
|
|
|
var groups = await _dictSyncService.GetDictGroupsAsync();
|
|
|
|
|
TreeNodes.Clear();
|
|
|
|
|
foreach (var group in groups)
|
2026-04-28 10:23:58 +08:00
|
|
|
{
|
2026-05-07 17:53:48 +08:00
|
|
|
TreeNodes.Add(new DictTreeNode(group.Key, group.Value));
|
2026-04-28 10:23:58 +08:00
|
|
|
}
|
2026-05-07 17:53:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnDictChangedAsync()
|
|
|
|
|
{
|
|
|
|
|
await LoadDictTreeAsync();
|
|
|
|
|
await PaginationDataGridViewModel.LoadDataAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void CleanUp()
|
|
|
|
|
{
|
|
|
|
|
base.CleanUp();
|
|
|
|
|
if (_dictChangedToken != null)
|
2026-04-28 10:23:58 +08:00
|
|
|
{
|
2026-05-07 17:53:48 +08:00
|
|
|
_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;
|
2026-04-28 10:23:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|