diff --git a/src/TelegramPanel.Web/Components/Dialogs/BotChannelCategoryDialog.razor b/src/TelegramPanel.Web/Components/Dialogs/BotChannelCategoryDialog.razor new file mode 100644 index 0000000..b67efc4 --- /dev/null +++ b/src/TelegramPanel.Web/Components/Dialogs/BotChannelCategoryDialog.razor @@ -0,0 +1,97 @@ +@namespace TelegramPanel.Web.Components.Dialogs +@inject BotManagementService BotManagement +@inject ISnackbar Snackbar +@using TelegramPanel.Data.Entities + + + + + + + + + + 取消 + + @if (saving) + { + + 保存中... + } + else + { + 保存 + } + + + + +@code +{ + [CascadingParameter] private MudDialogInstance MudDialog { get; set; } = default!; + [Parameter] public int BotId { get; set; } + [Parameter] public BotChannelCategory? Category { get; set; } + + private bool saving; + private string name = ""; + private string description = ""; + + protected override void OnInitialized() + { + // 如果传入了分类,说明是编辑模式 + if (Category != null) + { + name = Category.Name ?? ""; + description = Category.Description ?? ""; + } + } + + private void Cancel() + { + MudDialog.Cancel(); + } + + private async Task Save() + { + if (saving) + return; + + name = (name ?? string.Empty).Trim(); + if (string.IsNullOrWhiteSpace(name)) + { + Snackbar.Add("请输入分类名称", Severity.Warning); + return; + } + + saving = true; + try + { + if (Category == null) + { + // 新增模式:使用现有的 CreateCategoryAsync 方法 + var category = await BotManagement.CreateCategoryAsync(BotId, name, description); + Snackbar.Add("分类创建成功", Severity.Success); + MudDialog.Close(DialogResult.Ok(category)); + } + else + { + // 编辑模式:需要更新方法(暂未实现) + Category.Name = name; + Category.Description = description; + // TODO: 需要实现 UpdateCategoryAsync 方法 + Snackbar.Add("分类更新功能待实现", Severity.Warning); + MudDialog.Close(DialogResult.Ok(Category)); + } + } + catch (Exception ex) + { + Snackbar.Add($"保存失败:{ex.Message}", Severity.Error); + } + finally + { + saving = false; + } + } +} diff --git a/src/TelegramPanel.Web/Components/Pages/BotChannelsHome.razor b/src/TelegramPanel.Web/Components/Pages/BotChannelsHome.razor index 17d9a05..1e50995 100644 --- a/src/TelegramPanel.Web/Components/Pages/BotChannelsHome.razor +++ b/src/TelegramPanel.Web/Components/Pages/BotChannelsHome.razor @@ -32,7 +32,7 @@ - 全部分类 未分类 @@ -42,6 +42,10 @@ } + + @@ -122,28 +126,6 @@ -@if (selectedBotId > 0) -{ - - - 新增分类 - - - - - - - - - - 创建 - - - - - -} - @code { [SupplyParameterFromQuery(Name = "botId")] public int? BotIdQuery { get; set; } @@ -161,9 +143,6 @@ private int filterCategoryId = 0; private string search = ""; - private string newCategoryName = ""; - private string newCategoryDesc = ""; - private IEnumerable filtered => selectedBotId <= 0 ? Enumerable.Empty() : channels.Where(c => @@ -285,33 +264,23 @@ } } - private async Task CreateCategoryAsync() + private async Task OpenCreateCategoryDialog() { if (selectedBotId <= 0) return; - if (string.IsNullOrWhiteSpace(newCategoryName)) + var parameters = new DialogParameters { - Snackbar.Add("请输入分类名称", Severity.Warning); - return; - } + ["BotId"] = selectedBotId + }; + var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true }; + var dialog = DialogService.Show("新建分类", parameters, options); + var result = await dialog.Result; - loading = true; - try + if (!result.Canceled) { - await BotManagement.CreateCategoryAsync(selectedBotId, newCategoryName, newCategoryDesc); - newCategoryName = ""; - newCategoryDesc = ""; + // 重新加载分类列表 await LoadBotData(); - Snackbar.Add("分类已创建", Severity.Success); - } - catch (Exception ex) - { - Snackbar.Add($"创建失败:{ex.Message}", Severity.Error); - } - finally - { - loading = false; } }