private async Task <string> PluginClick(string pluginItemName) { var ret = ""; if (pluginItemName == "plugin1") { var op = new SwalOption() { Title = "点击plugin1按钮后弹窗", Content = "点击插件按钮后弹窗并确认后才进行下一步处理", IsConfirm = true }; if (await SwalService.ShowModal(op)) { ret = "<div class='text-danger'>从plugin1返回的数据</div>"; } } if (pluginItemName == "plugin2") { var op = new SwalOption() { Title = "点击plugin2按钮后弹窗", Content = "点击插件按钮后弹窗并确认后才进行下一步处理", IsConfirm = true }; if (await SwalService.ShowModal(op)) { ret = "从plugin2返回的数据"; } } return(ret); }
/// <summary> /// 异步回调方法 /// </summary> /// <param name="service"></param> /// <param name="option"></param> /// <param name="swal">指定弹窗组件 默认为 null 使用 <see cref="BootstrapBlazorRoot"/> 组件内置弹窗组件</param> /// <returns></returns> public static async Task <bool> ShowModal(this SwalService service, SwalOption option, SweetAlert?swal = null) { option.IsModalConfirm = true; await service.Show(option, swal); return(!option.IsModalConfirm || await option.ReturnTask.Task); }
/// <summary> /// OnInitialized 方法 /// </summary> protected override void OnInitialized() { base.OnInitialized(); // 注册 Swal 弹窗事件 SwalService.Register(this, Show); }
private async Task <string?> PluginClick(string pluginItemName) { var ret = ""; if (pluginItemName == "plugin1") { var op = new SwalOption() { Title = Localizer["SwalTitle"], Content = Localizer["SwalContent"] }; if (await SwalService.ShowModal(op)) { ret = Localizer["Ret1"]; } } if (pluginItemName == "plugin2") { var op = new SwalOption() { Title = Localizer["Swal2Title"], Content = Localizer["Swal2Content"] }; if (await SwalService.ShowModal(op)) { ret = Localizer["Ret2"]; } } return(ret); }
/// <summary> /// 下拉框选项点击时调用此方法 /// </summary> private async Task OnItemClick(SelectedItem item) { var ret = true; if (OnBeforeSelectedItemChange != null) { ret = await OnBeforeSelectedItemChange(item); if (ret) { // 返回 True 弹窗提示 var option = new SwalOption() { Category = SwalCategory, Title = SwalTitle, Content = SwalContent }; if (!string.IsNullOrEmpty(SwalFooter)) { option.ShowFooter = true; option.FooterTemplate = builder => builder.AddContent(0, SwalFooter); } ret = await SwalService.ShowModal(option); } else { // 返回 False 直接运行 ret = true; } } if (ret) { await ItemChanged(item); } }
private Task ShowContent() { SwalService.Show(new SwalOption() { Category = SwalCategory.Success, Content = "我是 Content" }); return(Task.CompletedTask); }
private Task OnSwal(SwalCategory cate) { SwalService.Show(new SwalOption() { Category = cate, Title = "Sweet 弹窗" }); return(Task.CompletedTask); }
private Task ShowTitle() { SwalService.Show(new SwalOption() { Category = SwalCategory.Success, Title = "我是 Title" }); return(Task.CompletedTask); }
private async Task ShowModal() { var op = new SwalOption() { Title = "模态对话框示例", Content = "模态对话框内容,不同按钮返回不同值" }; var ret = await SwalService.ShowModal(op); Trace?.Log($"模态弹窗返回值为:{ret}"); }
private async Task ShowFooterComponent() { var op = new SwalOption() { Category = SwalCategory.Error, Title = "Oops...", Content = "Something went wrong!", ShowFooter = true, FooterTemplate = DynamicComponent.CreateComponent <SwalFooter>().Render() }; await SwalService.Show(op); }
/// <summary> /// /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (disposing) { if (DelayToken != null) { DelayToken.Cancel(); DelayToken.Dispose(); DelayToken = null; } SwalService.UnRegister(this); } }
private async Task ShowAutoCloseSwal() { var op = new SwalOption() { Category = SwalCategory.Error, Title = "Oops...", Content = "Something went wrong!", ShowFooter = true, IsAutoHide = true, Delay = 4000, FooterTemplate = BootstrapDynamicComponent.CreateComponent <SwalFooter>().Render() }; await SwalService.Show(op); }
private async Task ShowComponent() { var op = new SwalOption() { BodyTemplate = new RenderFragment(builder => { builder.OpenElement(0, "div"); builder.AddAttribute(1, "class", "text-center"); builder.OpenComponent <Counter>(2); builder.CloseComponent(); builder.CloseElement(); }) }; await SwalService.Show(op); }
public async Task ToggleFan(string tagName) { var open = DataService.IsOpen; var op = new SwalOption() { Title = open ? "关闭风扇" : "打开风扇", Content = open ? "您确定要关闭风扇吗?" : "您确定要打开风扇吗?", Category = SwalCategory.Information }; open = !open; var ret = await SwalService.ShowModal(op); if (ret) { await DataService.UpdateStatus(open); } }
private async Task ShowButtons() { var op = new SwalOption() { Category = SwalCategory.Success, Title = "我是 Title", Content = "我是 Content", ShowClose = false }; op.ButtonTemplate = new RenderFragment(builder => { builder.OpenComponent <Button>(0); builder.AddAttribute(1, nameof(Button.Text), "自定义关闭按钮"); builder.AddAttribute(2, nameof(Button.OnClick), EventCallback.Factory.Create <MouseEventArgs>(this, async() => await op.Close())); builder.CloseComponent(); }); await SwalService.Show(op); }
private Task OnSwal(SwalCategory cate) => SwalService.Show(new SwalOption() { Category = cate, Title = "Sweet 弹窗" });
private Task ShowContent() => SwalService.Show(new SwalOption() { Category = SwalCategory.Success, Content = "我是 Content" });
private Task ShowTitle() => SwalService.Show(new SwalOption() { Category = SwalCategory.Success, Title = "我是 Title" });