Department.razor 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. @page "/system/department"
  2. @attribute [ReuseTabsPage(Title = "部门管理")]
  3. <Spin Spinning="Loading">
  4. <Table @ref="Table" AutoHeight TItem="SystemDepartment" @bind-PageSize="Ps"
  5. @bind-PageIndex="Pi" Total="Total" DataSource="DataSource" @bind-SelectedRows="SelectedRows" OnChange="OnChange">
  6. <TitleTemplate>
  7. <Flex Justify="FlexJustify.Start" Gap="@("10")">
  8. <Input Width="300" Placeholder="输入名称" @bind-Value="@Q_Name" />
  9. <Button OnClick="Search">搜索</Button>
  10. <Button OnClick="ResetQuery">重置</Button>
  11. <Button Type="ButtonType.Primary" Color="Color.Green6" OnClick="() => StartEdit(default)">新增</Button>
  12. </Flex>
  13. </TitleTemplate>
  14. <ColumnDefinitions Context="row">
  15. <PropertyColumn Align="ColumnAlign.Center" Property="c=>c.Id" Width="100" Title="ID" />
  16. <PropertyColumn Align="ColumnAlign.Center" Property="c=>c.Name" Title="部门名称" />
  17. <PropertyColumn Align="ColumnAlign.Center" Property="c=>c.Leader" Title="部门领导" />
  18. <PropertyColumn Align="ColumnAlign.Center" Property="c => c.CreateTime" Title="创建时间">
  19. @{
  20. var formattedTime = row.CreateTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "N/A";
  21. }
  22. @formattedTime
  23. </PropertyColumn>
  24. <ActionColumn Title="操作">
  25. <Button Type="ButtonType.Primary" Color="Color.Blue6" OnClick="() => StartEdit(row)">编辑</Button>
  26. <Button Type="ButtonType.Primary" Color="Color.Red6" Danger OnClick="() => Delete(row)">删除</Button>
  27. </ActionColumn>
  28. </ColumnDefinitions>
  29. <PaginationTemplate>
  30. <Pagination Class="@(context.PaginationClass + " my-custom-pagination")"
  31. Total="context.Total"
  32. PageSize="context.PageSize"
  33. Current="context.PageIndex"
  34. ShowSizeChanger
  35. ShowQuickJumper
  36. ShowTotal="ShowTotal"
  37. OnChange="context.HandlePageChange" />
  38. </PaginationTemplate>
  39. </Table>
  40. </Spin>
  41. @inject ModalService ModalService;
  42. @inject ConfirmService ComfirmService;
  43. @inject IMessageService MessageService;
  44. @code {
  45. private void StartEdit(SystemDepartment row)
  46. {
  47. var data = row ?? new();
  48. ModalRef<bool> modalRef = default;
  49. IForm form = default;
  50. modalRef = ModalService.CreateModal<bool>(new()
  51. {
  52. Title = data.Id > 0 ? "编辑" : "新增",
  53. Content =
  54. @<Form @ref="form" Model="data" OnFinish="()=> modalRef.OkAsync(true)" LabelColSpan="6" WrapperColSpan="18">
  55. <FormItem Label="部门名称" Required>
  56. <Input @bind-Value="@data.Name" />
  57. </FormItem>
  58. <FormItem Label="部门领导">
  59. <Input @bind-Value="@data.Leader" />
  60. </FormItem>
  61. <FormItem Label="是否启用" Required>
  62. <Select @bind-Value="@data.Enabled"
  63. TItemValue="bool"
  64. TItem="string"
  65. DefaultActiveFirstOption="false">
  66. <SelectOptions>
  67. <SelectOption TItemValue="bool" TItem="string" Value="true" Label="启用" />
  68. <SelectOption TItemValue="bool" TItem="string" Value="false" Label="禁用" />
  69. </SelectOptions>
  70. </Select>
  71. </FormItem>
  72. </Form>,
  73. OnOk = async (e) =>
  74. {
  75. if (!form.Validate())
  76. {
  77. return;
  78. }
  79. modalRef.SetConfirmLoading(true);
  80. var flag = await InsertOrUpdate(data);
  81. if (flag)
  82. {
  83. MessageService.Success("操作成功");
  84. await modalRef.CloseAsync();
  85. Table.ReloadData(Pi, Ps);
  86. StateHasChanged();
  87. }
  88. else
  89. {
  90. MessageService.Error("操作失败");
  91. }
  92. modalRef.SetConfirmLoading(false);
  93. },
  94. OnCancel = async (e) =>
  95. {
  96. if (form.IsModified && (!await Comfirm("已修改内容,确定退出吗?")))
  97. {
  98. return;
  99. }
  100. await modalRef.CloseAsync();
  101. }
  102. });
  103. }
  104. private async Task<bool> Comfirm(string message)
  105. {
  106. return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
  107. }
  108. }