97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using HandyControl.Controls;
|
||
using YY.Admin.Core;
|
||
using YY.Admin.Core.Extension;
|
||
using YY.Admin.Core.Helper;
|
||
using YY.Admin.Services.Service;
|
||
using YY.Admin.Services.Service.Tenant;
|
||
using YY.Admin.ViewModels.Control;
|
||
|
||
namespace YY.Admin.ViewModels.SysManage
|
||
{
|
||
public class TenantManagementViewModel : BaseViewModel
|
||
{
|
||
private readonly ISysTenantSyncService _tenantSyncService;
|
||
|
||
private PaginationDataGridViewModel<TenantOutput> _paginationDataGridViewModel;
|
||
public PaginationDataGridViewModel<TenantOutput> PaginationDataGridViewModel
|
||
{
|
||
get => _paginationDataGridViewModel;
|
||
set => SetProperty(ref _paginationDataGridViewModel, value);
|
||
}
|
||
|
||
private PageTenantInput _input;
|
||
public PageTenantInput 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 DelegateCommand SyncCommand { get; }
|
||
|
||
public TenantManagementViewModel(
|
||
ISysTenantSyncService tenantSyncService,
|
||
IContainerExtension container,
|
||
IRegionManager regionManager) : base(container, regionManager)
|
||
{
|
||
_tenantSyncService = tenantSyncService;
|
||
_paginationDataGridViewModel = new PaginationDataGridViewModel<TenantOutput>(FetchTenantsAsync);
|
||
_input = new PageTenantInput();
|
||
|
||
SearchCommand = new DelegateCommand(async () => await SearchAsync());
|
||
ResetCommand = new DelegateCommand(async () => await ResetAsync());
|
||
SyncCommand = new DelegateCommand(async () => await SyncAsync());
|
||
|
||
_ = InitializeAsync();
|
||
}
|
||
|
||
private async Task InitializeAsync()
|
||
{
|
||
await UIHelper.WaitForRenderAsync();
|
||
await PaginationDataGridViewModel.LoadDataAsync();
|
||
}
|
||
|
||
private async Task<(IEnumerable<TenantOutput> data, int totalCount)> FetchTenantsAsync()
|
||
{
|
||
Input.Page = PaginationDataGridViewModel.PageIndex;
|
||
Input.PageSize = PaginationDataGridViewModel.DataCountPerPage;
|
||
var result = await _tenantSyncService.PageAsync(Input);
|
||
return (result.Items, result.Total);
|
||
}
|
||
|
||
private async Task SearchAsync()
|
||
{
|
||
PaginationDataGridViewModel.PageIndex = 1;
|
||
await PaginationDataGridViewModel.LoadDataAsync();
|
||
}
|
||
|
||
private async Task ResetAsync()
|
||
{
|
||
Input = new PageTenantInput();
|
||
await UIHelper.WaitForRenderAsync();
|
||
await SearchAsync();
|
||
}
|
||
|
||
private async Task SyncAsync()
|
||
{
|
||
var count = await _tenantSyncService.SyncFromJeecgAsync();
|
||
if (count > 0)
|
||
{
|
||
Growl.Success($"同步完成,共处理 {count} 条租户数据");
|
||
}
|
||
else
|
||
{
|
||
Growl.Warning("未同步到租户数据,请确认已使用Jeecg账号登录且后端可访问");
|
||
}
|
||
await SearchAsync();
|
||
}
|
||
}
|
||
}
|