UNPKG

ngx-bit

Version:

A flexible NG-ZORRO helper library

163 lines (155 loc) 7.34 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs'), require('rxjs/operators'), require('ngx-bit'), require('rxjs/internal-compatibility'), require('ngx-bit/operates')) : typeof define === 'function' && define.amd ? define('ngx-bit/swal', ['exports', '@angular/core', '@angular/common', 'rxjs', 'rxjs/operators', 'ngx-bit', 'rxjs/internal-compatibility', 'ngx-bit/operates'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bit'] = global['ngx-bit'] || {}, global['ngx-bit'].swal = {}), global.ng.core, global.ng.common, global.rxjs, global.rxjs.operators, global['ngx-bit'], global.rxjs['internal-compatibility'], global['ngx-bit'].operates)); }(this, (function (exports, core, common, rxjs, operators, ngxBit, internalCompatibility, operates) { 'use strict'; var BitSwalService = /** @class */ (function () { function BitSwalService(bit, location) { this.bit = bit; this.location = location; this.ready = new rxjs.AsyncSubject(); } /** * 创建提示框 * create alert */ BitSwalService.prototype.create = function (option) { return this.ready.pipe(operators.switchMap(function (plugin) { return internalCompatibility.fromPromise(plugin.fire({ heightAuto: false, html: "\n <div class=\"ant-result-title ng-star-inserted\"> " + option.title + " </div>\n <div class=\"ant-result-subtitle ng-star-inserted\"> " + option.content + " </div>\n ", icon: option.type, width: !option.width ? 520 : option.width, confirmButtonText: !option.okText ? 'ok' : option.okText, cancelButtonText: !option.cancelText ? 'cancel' : option.cancelText, buttonsStyling: false, showConfirmButton: option.okShow === undefined ? true : option.cancelShow, showCancelButton: option.cancelShow === undefined ? true : option.cancelShow, customClass: { popup: 'swal2-ant-modal', actions: 'ant-result-extra ng-star-inserted', confirmButton: 'ant-btn ant-btn-primary ' + (!option.okDanger ? '' : 'ant-btn-dangerous'), cancelButton: 'ant-btn' } })); })); }; /** * 新增响应提示框 * Add response prompt box */ BitSwalService.prototype.addAlert = function (res, form, reset) { var _this = this; return !res.error ? this.create({ title: this.bit.l.AddAlertSuccessTitle, content: this.bit.l.AddAlertSuccessContent, type: 'success', okText: this.bit.l.AddAlertSuccessOk, cancelText: this.bit.l.AddAlertSuccessCancel }).pipe(operators.map(function (result) { if (result.value) { form.reset(reset ? reset : undefined); return true; } _this.location.back(); return false; })) : this.create({ title: this.bit.l.AddAlertErrorTitle, content: !res.msg ? this.bit.l.AddAlertErrorContent : res.msg, type: 'error', okText: this.bit.l.AddAlertErrorOk, cancelShow: false }).pipe(operators.map(function (_) { return null; })); }; /** * 修改响应提示框 * Edit response prompt box */ BitSwalService.prototype.editAlert = function (res) { var _this = this; return !res.error ? this.create({ title: this.bit.l.EditAlertSuccessTitle, content: this.bit.l.EditAlertSuccessContent, type: 'success', okText: this.bit.l.EditAlertSuccessOk, cancelText: this.bit.l.EditAlertSuccessCancel }).pipe(operators.map(function (result) { if (result.value) { return true; } _this.location.back(); return false; })) : this.create({ title: this.bit.l.EditAlertErrorTitle, content: (!res.msg ? this.bit.l.EditAlertErrorContent : res.msg), type: 'error', okText: this.bit.l.EditAlertErrorOk, cancelShow: false }).pipe(operators.map(function (_) { return null; })); }; /** * 删除响应提示框 * Delete response prompt box */ BitSwalService.prototype.deleteAlert = function (observable) { return this.create({ title: this.bit.l.DeleteAlertTitle, content: this.bit.l.DeleteAlertContent, type: 'question', okText: this.bit.l.DeleteAlertOk, okDanger: true, cancelText: this.bit.l.DeleteAlertCancel }).pipe(operators.switchMap(function (result) { return !result.value ? rxjs.of() : observable; })); }; return BitSwalService; }()); BitSwalService.decorators = [ { type: core.Injectable } ]; BitSwalService.ctorParameters = function () { return [ { type: ngxBit.BitService }, { type: common.Location } ]; }; var Config = /** @class */ (function () { function Config() { } return Config; }()); Config.decorators = [ { type: core.Injectable } ]; var BitSwalModule = /** @class */ (function () { function BitSwalModule(config, swal, document) { this.document = document; this.url = 'https://cdn.jsdelivr.net/npm/sweetalert2/dist/sweetalert2.all.min.js'; operates.loadScript(document, (config === null || config === void 0 ? void 0 : config.url) || this.url).subscribe(function (_) { swal.ready.next(window['Swal']); swal.ready.complete(); }); } BitSwalModule.forRoot = function (config) { return { ngModule: BitSwalModule, providers: [ { provide: Config, useValue: config }, BitSwalService ] }; }; return BitSwalModule; }()); BitSwalModule.decorators = [ { type: core.NgModule } ]; BitSwalModule.ctorParameters = function () { return [ { type: Config }, { type: BitSwalService }, { type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] } ]; }; /** * Generated bundle index. Do not edit. */ exports.BitSwalModule = BitSwalModule; exports.BitSwalService = BitSwalService; exports.ɵa = Config; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-bit-swal.umd.js.map