This commit is contained in:
Zhanghu
2026-01-13 13:50:27 +08:00
commit a9efcd55a7
72 changed files with 8430 additions and 0 deletions

View File

@@ -0,0 +1,234 @@
@page "/batch"
@rendermode @(new InteractiveServerRenderMode())
@inject Services.ApiClientService ApiClient
@inject IJSRuntime JSRuntime
<PageTitle>批量操作 - DRS9 信息发布系统</PageTitle>
<h3 class="mb-4">批量操作</h3>
<div class="row">
<!-- 批量分配内容 -->
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<i class="bi bi-grid"></i> 批量分配内容
</div>
<div class="card-body">
<p class="text-muted">将内容批量分配给多个设备或设备组</p>
<div class="mb-3">
<label class="form-label">选择设备组</label>
<select class="form-select" @bind="@_batchAssignGroupId">
<option value="0">选择设备组...</option>
@if (_groups != null)
{
@foreach (var group in _groups)
{
<option value="@group.Id">@group.Name</option>
}
}
</select>
</div>
<div class="mb-3">
<label class="form-label">选择内容</label>
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
@if (_applications != null)
{
@foreach (var app in _applications)
{
<div class="form-check">
<input type="checkbox" class="form-check-input"
id="batch-app-@app.Id"
@bind="@_selectedAppIds[app.Id]" />
<label class="form-check-label" for="batch-app-@app.Id">
@app.Name (@app.Type)
</label>
</div>
}
}
</div>
</div>
<button class="btn btn-primary w-100" @onclick="ExecuteBatchAssign">
<i class="bi bi-check-lg"></i> 执行分配
</button>
</div>
</div>
</div>
<!-- 批量推送 -->
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<i class="bi bi-send"></i> 批量推送命令
</div>
<div class="card-body">
<p class="text-muted">向多个设备发送控制命令</p>
<div class="mb-3">
<label class="form-label">选择设备</label>
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
@if (_devices != null)
{
@foreach (var device in _devices)
{
<div class="form-check">
<input type="checkbox" class="form-check-input"
id="batch-device-@device.Id"
@bind="@_selectedDeviceIds[device.Id]" />
<label class="form-check-label" for="batch-device-@device.Id">
@device.DeviceName
</label>
</div>
}
}
</div>
</div>
<div class="mb-3">
<label class="form-label">推送命令</label>
<select class="form-select" @bind="@_batchCommand">
<option value="refresh">刷新内容</option>
<option value="restart">重启应用</option>
<option value="screenshot">获取截图</option>
<option value="clear_cache">清除缓存</option>
</select>
</div>
<button class="btn btn-success w-100" @onclick="ExecuteBatchPush">
<i class="bi bi-send"></i> 发送命令
</button>
</div>
</div>
</div>
<!-- 批量启用/禁用 -->
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header">
<i class="bi bi-power"></i> 批量启用/禁用
</div>
<div class="card-body">
<p class="text-muted">批量启用或禁用多个设备</p>
<div class="mb-3">
<label class="form-label">选择设备</label>
<div class="border rounded p-2" style="max-height: 150px; overflow-y: auto;">
@if (_devices != null)
{
@foreach (var device in _devices)
{
<div class="form-check">
<input type="checkbox" class="form-check-input"
id="toggle-device-@device.Id"
@bind="@_toggleDeviceIds[device.Id]" />
<label class="form-check-label" for="toggle-device-@device.Id">
@device.DeviceName
</label>
</div>
}
}
</div>
</div>
<div class="btn-group w-100" role="group">
<button class="btn btn-success flex-grow-1" @onclick="@(() => ExecuteBatchToggle(true))">
<i class="bi bi-check-circle"></i> 批量启用
</button>
<button class="btn btn-danger flex-grow-1" @onclick="@(() => ExecuteBatchToggle(false))">
<i class="bi bi-x-circle"></i> 批量禁用
</button>
</div>
</div>
</div>
</div>
</div>
@code {
private List<DeviceDto> _devices = new();
private List<ApplicationDto> _applications = new();
private List<DeviceGroupDto> _groups = new();
private Dictionary<int, bool> _selectedAppIds = new();
private Dictionary<int, bool> _selectedDeviceIds = new();
private Dictionary<int, bool> _toggleDeviceIds = new();
private int _batchAssignGroupId = 0;
private string _batchCommand = "refresh";
protected override async Task OnInitializedAsync()
{
await LoadData();
}
private async Task LoadData()
{
var devicesTask = ApiClient.GetDevicesAsync();
var appsTask = ApiClient.GetApplicationsAsync();
var groupsTask = ApiClient.GetDeviceGroupsAsync();
_devices = await devicesTask;
_applications = await appsTask;
_groups = await groupsTask;
_selectedAppIds = _applications.ToDictionary(a => a.Id, _ => false);
_selectedDeviceIds = _devices.ToDictionary(d => d.Id, _ => false);
_toggleDeviceIds = _devices.ToDictionary(d => d.Id, _ => false);
}
private async Task ExecuteBatchAssign()
{
var selectedApps = _selectedAppIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
if (_batchAssignGroupId > 0)
{
var groupDevices = _devices.Where(d => d.DeviceGroupId == _batchAssignGroupId).Select(d => d.Id).ToList();
if (groupDevices.Count == 0 || selectedApps.Count == 0)
{
await JSRuntime.InvokeVoidAsync("alert", "请选择设备和内容");
return;
}
await ApiClient.BatchAssignContentAsync(new BatchAssignContentRequest
{
DeviceIds = groupDevices,
ApplicationIds = selectedApps
});
await JSRuntime.InvokeVoidAsync("alert", "批量分配完成");
}
else
{
await JSRuntime.InvokeVoidAsync("alert", "请选择设备组");
}
}
private async Task ExecuteBatchPush()
{
var selectedDevices = _selectedDeviceIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
if (selectedDevices.Count == 0)
{
await JSRuntime.InvokeVoidAsync("alert", "请选择设备");
return;
}
await ApiClient.BatchPushAsync(new BatchPushRequest
{
DeviceIds = selectedDevices,
MessageType = _batchCommand
});
await JSRuntime.InvokeVoidAsync("alert", "命令推送完成");
}
private async Task ExecuteBatchToggle(bool enable)
{
var selectedDevices = _toggleDeviceIds.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
if (selectedDevices.Count == 0)
{
await JSRuntime.InvokeVoidAsync("alert", "请选择设备");
return;
}
await ApiClient.BatchToggleDevicesAsync(new BatchToggleDevicesRequest
{
DeviceIds = selectedDevices,
IsEnabled = enable
});
await JSRuntime.InvokeVoidAsync("alert", $"批量{(enable ? "启用" : "禁用")}完成");
await LoadData();
}
}