@page "/applications" @rendermode @(new InteractiveServerRenderMode()) @inject Services.ApiClientService ApiClient @inject IJSRuntime JSRuntime 内容管理 - DRS9 信息发布系统

内容管理

内容列表
@if (_applications == null) {
} else if (_applications.Count == 0) {

暂无内容,点击上方按钮添加

} else {
@foreach (var app in _applications) {
@app.Name

@app.Type

@app.Description

}
}
@if (_showModal) { } @code { private List _applications = new(); private ApplicationDto? _editingApp; private string _appName = ""; private string _appType = ""; private string _appContentUrl = ""; private string _appDescription = ""; private bool _showModal = false; private string _errorMessage = ""; protected override async Task OnInitializedAsync() { _applications = await ApiClient.GetApplicationsAsync(); } private void ShowAddModal() { _editingApp = null; _appName = ""; _appType = ""; _appContentUrl = ""; _appDescription = ""; _errorMessage = ""; _showModal = true; } private void EditApp(ApplicationDto app) { _editingApp = app; _appName = app.Name; _appType = app.Type; _appContentUrl = app.ContentUrl; _appDescription = app.Description ?? ""; _errorMessage = ""; _showModal = true; } private void CloseModal() { _showModal = false; _editingApp = null; _errorMessage = ""; } private async Task SaveApp() { // Validate inputs if (string.IsNullOrWhiteSpace(_appName)) { _errorMessage = "请输入内容名称"; return; } if (string.IsNullOrWhiteSpace(_appType)) { _errorMessage = "请选择内容类型"; return; } if (string.IsNullOrWhiteSpace(_appContentUrl)) { _errorMessage = "请输入内容 URL"; return; } bool success; if (_editingApp == null) { success = await ApiClient.CreateApplicationAsync(new ApplicationCreateRequest { Name = _appName, Type = _appType, ContentUrl = _appContentUrl, Description = _appDescription }); } else { success = await ApiClient.UpdateApplicationAsync(_editingApp.Id, new ApplicationUpdateRequest { Name = _appName, Description = _appDescription, ContentUrl = _appContentUrl }); } if (success) { CloseModal(); _applications = await ApiClient.GetApplicationsAsync(); await JSRuntime.InvokeVoidAsync("alert", "保存成功"); } else { _errorMessage = "保存失败,请检查输入数据或稍后重试"; } } private async Task DeleteApp(ApplicationDto app) { if (await JSRuntime.InvokeAsync("confirm", $"确定要删除内容 '{app.Name}' 吗?")) { var success = await ApiClient.DeleteApplicationAsync(app.Id); if (success) { _applications = await ApiClient.GetApplicationsAsync(); await JSRuntime.InvokeVoidAsync("alert", "删除成功"); } else { await JSRuntime.InvokeVoidAsync("alert", "删除失败"); } } } private string GetAppTypeClass(string type) => type switch { "Dashboard" => "dashboard", "WebRotator" => "web", "Image" => "image", "Video" => "video", _ => "" }; private string GetAppIcon(string type) => type switch { "Dashboard" => "bi-bar-chart", "WebRotator" => "bi-arrow-repeat", "Image" => "bi-image", "Video" => "bi-play-circle", _ => "bi-file-earmark" }; }