Dict.razor 5.1 KB

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