Exemplo n.º 1
0
        /// <summary>
        /// 删除数据方法
        /// </summary>
        protected async Task DeleteAsync()
        {
            var ret = false;

            if (OnDeleteAsync != null)
            {
                ret = await OnDeleteAsync(SelectedItems);
            }
            var op = new ToastOption()
            {
                Title = "删除数据"
            };

            op.Category = ret ? ToastCategory.Success : ToastCategory.Error;
            op.Content  = $"删除数据{(ret ? "成功" : "失败")}, {Math.Ceiling(op.Delay / 1000.0)} 秒后自动关闭";

            if (ret)
            {
                // 删除成功 重新查询
                // 由于数据删除导致页码会改变,尤其是最后一页
                // 重新计算页码
                PageIndex = Math.Min(PageIndex, (TotalCount - SelectedItems.Count) / PageItems);
                await QueryAsync();
            }
            Toast?.Show(op);
        }
        /// <summary>
        /// 删除数据方法
        /// </summary>
        protected async Task DeleteAsync()
        {
            var ret = false;

            if (OnDeleteAsync != null)
            {
                ret = await OnDeleteAsync(SelectedItems);
            }
            var option = new ToastOption()
            {
                Title = "删除数据"
            };

            option.Category = ret ? ToastCategory.Success : ToastCategory.Error;
            option.Content  = $"删除数据{(ret ? "成功" : "失败")}, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";

            if (ret)
            {
                SelectedItems.Clear();

                // 删除成功 重新查询
                // 由于数据删除导致页码会改变,尤其是最后一页
                // 重新计算页码
                PageIndex = Math.Max(1, Math.Min(PageIndex, (TotalCount - SelectedItems.Count) / PageItems));

                var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedItems.Count));
                PageItems = Math.Min(PageItems, items.Any() ? items.Min() : PageItems);
                await QueryAsync();
            }
            Toast?.Show(option);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 保存数据
 /// </summary>
 /// <param name="context"></param>
 protected async Task SaveAsync(EditContext context)
 {
     if (UseInjectDataService || OnSaveAsync != null)
     {
         if (await SaveModelAsync(context))
         {
             if (EditMode == EditMode.Popup)
             {
                 await QueryAsync();
             }
             else if (EditMode == EditMode.EditForm)
             {
                 ShowAddForm  = false;
                 ShowEditForm = false;
                 StateHasChanged();
             }
         }
     }
     else
     {
         var option = new ToastOption
         {
             Category = ToastCategory.Error,
             Title    = SaveButtonToastTitle,
             Content  = SaveButtonToastContent
         };
         await Toast.Show(option);
     }
 }
        /// <summary>
        /// 删除数据方法
        /// </summary>
        protected Func <Task> DeleteAsync() => async() =>
        {
            var ret = false;
            if (OnDeleteAsync != null)
            {
                ret = await OnDeleteAsync(SelectedItems);
            }
            else if (UseInjectDataService && DataService != null)
            {
                ret = await DataService.DeleteAsync(SelectedItems);
            }
            var option = new ToastOption()
            {
                Title = DeleteButtonToastTitle
            };
            option.Category = ret ? ToastCategory.Success : ToastCategory.Error;
            option.Content  = string.Format(DeleteButtonToastResultContent, ret ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));

            if (ret)
            {
                // 删除成功 重新查询
                // 由于数据删除导致页码会改变,尤其是最后一页
                // 重新计算页码
                // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UJSL
                PageIndex = Math.Max(1, Math.Min(PageIndex, int.Parse(Math.Ceiling((TotalCount - SelectedItems.Count) * 1d / PageItems).ToString())));
                var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedItems.Count));
                PageItems = Math.Min(PageItems, items.Any() ? items.Min() : PageItems);

                SelectedItems.Clear();
                await QueryAsync();
            }
            Toast.Show(option);
        };
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected async Task <bool> SaveModelAsync(EditContext context)
        {
            var valid = false;

            if (OnSaveAsync != null)
            {
                valid = await OnSaveAsync((TItem)context.Model);
            }
            else
            {
                valid = await GetDataService().SaveAsync((TItem)context.Model);
            }

            if (ShowErrorToast || valid)
            {
                var option = new ToastOption
                {
                    Category = valid ? ToastCategory.Success : ToastCategory.Error,
                    Title    = SaveButtonToastTitle
                };
                option.Content = string.Format(SaveButtonToastResultContent, valid ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
                await Toast.Show(option);
            }

            return(valid);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="context"></param>
        protected async Task Save(EditContext context)
        {
            var valid = false;

            if (OnSaveAsync != null)
            {
                valid = await OnSaveAsync((TItem)context.Model);

                var option = new ToastOption
                {
                    Category = valid ? ToastCategory.Success : ToastCategory.Error,
                    Title    = SaveButtonToastTitle
                };
                option.Content = string.Format(SaveButtonToastResultContent, valid ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
                Toast.Show(option);
                if (valid)
                {
                    DialogOption.Dialog?.Toggle();
                    await QueryAsync();
                }
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = SaveButtonToastTitle,
                    Content  = SaveButtonToastContent
                };
                Toast.Show(option);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 编辑按钮方法
        /// </summary>
        public Task EditAsync()
        {
            if (OnSaveAsync != null)
            {
                if (SelectedItems.Count == 1)
                {
                    EditModel            = SelectedItems[0].Clone();
                    EditModalTitleString = EditModalTitle;

                    ShowEditorDialog();
                }
                else
                {
                    var option = new ToastOption
                    {
                        Category = ToastCategory.Information,
                        Title    = EditButtonToastTitle,
                        Content  = SelectedItems.Count == 0 ? EditButtonToastNotSelectContent : EditButtonToastMoreSelectContent
                    };
                    Toast.Show(option);
                }
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = EditButtonToastTitle,
                    Content  = EditButtonToastNoSaveMethodContent
                };
                Toast.Show(option);
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 新建按钮方法
        /// </summary>
        public async Task AddAsync()
        {
            if (OnSaveAsync != null)
            {
                if (OnAddAsync != null)
                {
                    EditModel = await OnAddAsync();
                }
                else
                {
                    EditModel = new TItem();
                }

                SelectedItems.Clear();
                EditModalTitleString = AddModalTitle;

                ShowEditorDialog();

                StateHasChanged();
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = AddButtonToastTitle,
                    Content  = AddButtonToastContent
                };
                Toast.Show(option);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 编辑按钮方法
        /// </summary>
        public async Task EditAsync()
        {
            if (UseInjectDataService || OnSaveAsync != null)
            {
                if (SelectedItems.Count == 1)
                {
                    await ToggleLoading(true);

                    if (OnEditAsync != null)
                    {
                        await OnEditAsync(SelectedItems[0]);
                    }
                    if (UseInjectDataService && GetDataService() is IEntityFrameworkCoreDataService ef)
                    {
                        EditModel = SelectedItems[0];
                        await ef.EditAsync(EditModel);
                    }
                    else
                    {
                        EditModel = Utility.Clone(SelectedItems[0]);
                    }
                    EditModalTitleString = EditModalTitle;

                    // 显示编辑框
                    if (EditMode == EditMode.Popup)
                    {
                        await ShowEditDialog();
                    }
                    else if (EditMode == EditMode.EditForm)
                    {
                        ShowEditForm = true;
                        ShowAddForm  = false;
                    }
                    await ToggleLoading(false);
                }
                else
                {
                    var option = new ToastOption
                    {
                        Category = ToastCategory.Information,
                        Title    = EditButtonToastTitle,
                        Content  = SelectedItems.Count == 0 ? EditButtonToastNotSelectContent : EditButtonToastMoreSelectContent
                    };
                    await Toast.Show(option);
                }
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = EditButtonToastTitle,
                    Content  = EditButtonToastNoSaveMethodContent
                };
                await Toast.Show(option);
            }
        }
Exemplo n.º 10
0
 private async Task Show(ToastOption option)
 {
     Toasts.Add(option, new RenderFragment(builder =>
     {
         var index = 0;
         builder.OpenComponent <ToastBox>(index++);
         builder.AddAttribute(index++, nameof(ToastBox.Category), option.Category);
         builder.AddAttribute(index++, nameof(ToastBox.Title), option.Title);
         builder.AddAttribute(index++, nameof(ToastBox.Content), option.Content);
         builder.AddAttribute(index++, nameof(ToastBox.IsAutoHide), option.IsAutoHide);
         builder.AddAttribute(index++, nameof(ToastBox.Delay), option.Delay);
         builder.CloseComponent();
     }));
     await InvokeAsync(StateHasChanged);
 }
Exemplo n.º 11
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="context"></param>
        protected void Save(EditContext context)
        {
            var valid  = OnSave?.Invoke((TItem)context.Model) ?? false;
            var option = new ToastOption();

            option.Category = valid ? ToastCategory.Success : ToastCategory.Error;
            option.Title    = "保存数据";
            option.Content  = $"保存数据{(valid ? "成功" : "失败")}, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";
            Toast?.Show(option);
            if (valid)
            {
                EditModal?.Toggle();
                Query();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 新建按钮方法
        /// </summary>
        public async Task AddAsync()
        {
            if (UseInjectDataService || OnSaveAsync != null)
            {
                await ToggleLoading(true);

                if (OnAddAsync != null)
                {
                    EditModel = await OnAddAsync();
                }
                else if (UseInjectDataService)
                {
                    EditModel = new TItem();
                    await GetDataService().AddAsync(EditModel);
                }
                else
                {
                    EditModel = new TItem();
                }

                SelectedItems.Clear();
                EditModalTitleString = AddModalTitle;

                if (EditMode == EditMode.Popup)
                {
                    await ShowEditDialog();
                }
                else if (EditMode == EditMode.EditForm)
                {
                    ShowAddForm  = true;
                    ShowEditForm = false;
                }
                await ToggleLoading(false);

                StateHasChanged();
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = AddButtonToastTitle,
                    Content  = AddButtonToastContent
                };
                await Toast.Show(option);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 编辑按钮方法
 /// </summary>
 public void Edit()
 {
     if (SelectedItems.Count == 1)
     {
         EditModel            = SelectedItems[0].Clone();
         EditModalTitleString = EditModalTitle;
         EditModal?.Toggle();
     }
     else
     {
         var option = new ToastOption();
         option.Category = ToastCategory.Information;
         option.Title    = "编辑数据";
         option.Content  = SelectedItems.Count == 0 ? "请选择要编辑的数据" : "只能选择一项要编辑的数据";
         Toast?.Show(option);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="context"></param>
        protected async Task SaveAsync(EditContext context)
        {
            var valid = false;

            if (UseInjectDataService || OnSaveAsync != null)
            {
                if (EditMode == EditMode.EditForm)
                {
                    ShowAddForm  = false;
                    ShowEditForm = false;
                }

                if (OnSaveAsync != null)
                {
                    valid = await OnSaveAsync((TItem)context.Model);
                }
                else
                {
                    valid = await GetDataService().SaveAsync((TItem)context.Model);
                }
                var option = new ToastOption
                {
                    Category = valid ? ToastCategory.Success : ToastCategory.Error,
                    Title    = SaveButtonToastTitle
                };
                option.Content = string.Format(SaveButtonToastResultContent, valid ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
                Toast.Show(option);
                if (valid && DialogOption.Dialog != null)
                {
                    await DialogOption.Dialog.Close();
                    await QueryAsync();
                }
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = SaveButtonToastTitle,
                    Content  = SaveButtonToastContent
                };
                Toast.Show(option);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 新建按钮方法
        /// </summary>
        public async Task AddAsync()
        {
            if ((UseInjectDataService && DataService != null) || OnSaveAsync != null)
            {
                if (OnAddAsync != null)
                {
                    EditModel = await OnAddAsync();
                }
                else if (DataService != null)
                {
                    EditModel = new TItem();
                    await DataService.Config(EditModel);
                }
                else
                {
                    EditModel = new TItem();
                }

                SelectedItems.Clear();
                EditModalTitleString = AddModalTitle;

                if (EditMode == EditMode.Popup)
                {
                    ShowEditorDialog();
                }
                else if (EditMode == EditMode.EditForm)
                {
                    ShowAddForm  = true;
                    ShowEditForm = false;
                }
                StateHasChanged();
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = AddButtonToastTitle,
                    Content  = AddButtonToastContent
                };
                Toast.Show(option);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 编辑按钮方法
        /// </summary>
        public Task EditAsync()
        {
            if ((UseInjectDataService && DataService != null) || OnSaveAsync != null)
            {
                if (SelectedItems.Count == 1)
                {
                    EditModel            = SelectedItems[0].Clone();
                    EditModalTitleString = EditModalTitle;

                    if (EditMode == EditMode.Popup)
                    {
                        ShowEditorDialog();
                    }
                    else if (EditMode == EditMode.EditForm)
                    {
                        ShowEditForm = true;
                        ShowAddForm  = false;
                    }
                }
                else
                {
                    var option = new ToastOption
                    {
                        Category = ToastCategory.Information,
                        Title    = EditButtonToastTitle,
                        Content  = SelectedItems.Count == 0 ? EditButtonToastNotSelectContent : EditButtonToastMoreSelectContent
                    };
                    Toast.Show(option);
                }
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Error,
                    Title    = EditButtonToastTitle,
                    Content  = EditButtonToastNoSaveMethodContent
                };
                Toast.Show(option);
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 确认删除按钮方法
        /// </summary>
        protected Task <bool> ConfirmDelete()
        {
            var ret = false;

            if (SelectedItems.Count == 0)
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Information,
                    Title    = "删除数据"
                };
                option.Content = $"请选择要删除的数据, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";
                Toast?.Show(option);
            }
            else
            {
                ret = true;
            }
            return(Task.FromResult(ret));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 确认导出按钮方法
        /// </summary>
        protected Task <bool> ConfirmExport()
        {
            var ret = false;

            if (!Items.Any())
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Information,
                    Title    = "导出数据"
                };
                option.Content = $"没有需要导出的数据, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";
                Toast.Show(option);
            }
            else
            {
                ret = true;
            }
            return(Task.FromResult(ret));
        }
Exemplo n.º 19
0
        /// <summary>
        /// 确认删除按钮方法
        /// </summary>
        protected Task <bool> ConfirmDelete()
        {
            var ret = false;

            if (SelectedItems.Count == 0)
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Information,
                    Title    = DeleteButtonToastTitle
                };
                option.Content = string.Format(DeleteButtonToastContent, Math.Ceiling(option.Delay / 1000.0));
                Toast.Show(option);
            }
            else
            {
                ret = true;
            }
            return(Task.FromResult(ret));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 编辑按钮方法
        /// </summary>
        public Task EditAsync()
        {
            if (SelectedItems.Count == 1)
            {
                EditModel            = SelectedItems[0].Clone();
                EditModalTitleString = EditModalTitle;

                ShowEditorDialog();
            }
            else
            {
                var option = new ToastOption
                {
                    Category = ToastCategory.Information,
                    Title    = "编辑数据",
                    Content  = SelectedItems.Count == 0 ? "请选择要编辑的数据" : "只能选择一项要编辑的数据"
                };
                Toast?.Show(option);
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 删除数据方法
        /// </summary>
        protected void Delete()
        {
            var ret = OnDelete?.Invoke(SelectedItems) ?? false;
            var op  = new ToastOption()
            {
                Title = "删除数据"
            };

            op.Category = ret ? ToastCategory.Success : ToastCategory.Error;
            op.Content  = $"删除数据{(ret ? "成功" : "失败")}, {Math.Ceiling(op.Delay / 1000.0)} 秒后自动关闭";

            if (ret)
            {
                // 删除成功 重新查询
                // 由于数据删除导致页码会改变,尤其是最后一页
                // 重新计算页码
                PageIndex = Math.Min(PageIndex, (TotalCount - SelectedItems.Count) / PageItems);
                Query();
            }
            Toast?.Show(op);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 确认删除按钮方法
        /// </summary>
        protected bool ConfirmDelete()
        {
            var ret = false;

            if (SelectedItems.Count == 0)
            {
                var option = new ToastOption();
                option.Category = ToastCategory.Information;
                option.Title    = "删除数据";
                option.Content  = $"请选择要删除的数据, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";
                Toast?.Show(option);
            }
            else
            {
                // 更改确认弹窗的显示内容
                //var content = SelectedItems.Count == 1 ? "确定要删除本条数据吗?" : "确定要删除选中的所有数据吗?";
                //DeleteConfirm?.Show(content: content);
                ret = true;
            }
            return(ret);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 导出数据方法
        /// </summary>
        protected async Task ExportAsync()
        {
            var ret = false;

            _ = Task.Run(async() =>
            {
                if (OnExportAsync != null)
                {
                    ret = await OnExportAsync(Items);
                }
                else
                {
                    // 如果未提供 OnExportAsync 回调委托使用注入服务来尝试解析
                    // TODO: 这里将本页数据作为参数传递给导出服务,服务本身可以利用自身优势获取全部所需数据,如果获取全部数据呢?
                    ret = await ExcelExport.ExportAsync(Items, Columns, JSRuntime);
                }

                var option = new ToastOption()
                {
                    Title = "导出数据"
                };
                option.Category = ret ? ToastCategory.Success : ToastCategory.Error;
                option.Content  = $"导出数据{(ret ? "成功" : "失败")}, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";

                Toast.Show(option);
            });

            var option = new ToastOption()
            {
                Title = "导出数据"
            };

            option.Category = ToastCategory.Information;
            option.Content  = $"正在导出数据,请稍候, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";

            Toast.Show(option);

            await Task.CompletedTask;
        }
Exemplo n.º 24
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="context"></param>
        protected async Task Save(EditContext context)
        {
            var valid = false;

            if (OnSaveAsync != null)
            {
                valid = await OnSaveAsync((TItem)context.Model);
            }
            var option = new ToastOption
            {
                Category = valid ? ToastCategory.Success : ToastCategory.Error,
                Title    = "保存数据"
            };

            option.Content = $"保存数据{(valid ? "成功" : "失败")}, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭";
            Toast?.Show(option);
            if (valid)
            {
                DialogOption.Dialog?.Toggle();
                await QueryAsync();
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// 显示窗口方法
 /// </summary>
 /// <param name="option"></param>
 /// <returns></returns>
 public void Show(ToastOption option)
 {
     Subscribes.AsParallel().ForAll(callback => callback.Invoke(option));
 }
Exemplo n.º 26
0
 private async Task Show(ToastOption option)
 {
     Toasts.Add(option);
     await InvokeAsync(StateHasChanged);
 }