From 3b72a6a1423f33d440e07c9c9bcfa838cb13531d Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 16 Jul 2021 15:13:46 +0800 Subject: [PATCH] Switch to SweetAlert2 --- .../SweetAlert/SweetalertScriptContributor.cs | 2 +- .../sweetalert/abp-sweetalert.js | 24 +++++++++---------- npm/packs/sweetalert/abp.resourcemapping.js | 2 +- npm/packs/sweetalert/package.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/SweetAlert/SweetalertScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/SweetAlert/SweetalertScriptContributor.cs index eefc2e21a8..a947417809 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/SweetAlert/SweetalertScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/SweetAlert/SweetalertScriptContributor.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.SweetAlert { public override void ConfigureBundle(BundleConfigurationContext context) { - context.Files.AddIfNotContains("/libs/sweetalert/sweetalert.min.js"); + context.Files.AddIfNotContains("/libs/sweetalert2/sweetalert2.all.min.js"); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert/abp-sweetalert.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert/abp-sweetalert.js index 0ed8460966..f5b44fee44 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert/abp-sweetalert.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert/abp-sweetalert.js @@ -1,6 +1,6 @@ var abp = abp || {}; (function ($) { - if (!sweetAlert || !$) { + if (!Swal || !$) { return; } @@ -27,7 +27,8 @@ confirm: { icon: 'warning', title: 'Are you sure?', - buttons: ['Cancel', 'Yes'] + showCancelButton: true, + reverseButtons: true } } }; @@ -51,7 +52,7 @@ ); return $.Deferred(function ($dfd) { - sweetAlert(opts).then(function () { + Swal.fire(opts).then(function () { $dfd.resolve(); }); }); @@ -73,7 +74,7 @@ return showMessage('error', message, title); }; - abp.message.confirm = function (message, titleOrCallback, callback, closeOnEsc) { + abp.message.confirm = function (message, titleOrCallback, callback) { var userOpts = { text: message @@ -86,8 +87,6 @@ userOpts.title = titleOrCallback; }; - userOpts.closeOnEsc = closeOnEsc; - var opts = $.extend( {}, abp.libs.sweetAlert.config['default'], @@ -96,10 +95,10 @@ ); return $.Deferred(function ($dfd) { - sweetAlert(opts).then(function (isConfirmed) { - callback && callback(isConfirmed); - $dfd.resolve(isConfirmed); - }); + Swal.fire(opts).then(result => { + callback && callback(result.value); + $dfd.resolve(result.value); + }) }); }; @@ -107,7 +106,8 @@ var l = abp.localization.getResource('AbpUi'); abp.libs.sweetAlert.config.confirm.title = l('AreYouSure'); - abp.libs.sweetAlert.config.confirm.buttons = [l('Cancel'), l('Yes')]; + abp.libs.sweetAlert.config.confirm.showCancelButton = true; + abp.libs.sweetAlert.config.confirm.reverseButtons = true; }); -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/npm/packs/sweetalert/abp.resourcemapping.js b/npm/packs/sweetalert/abp.resourcemapping.js index d258586f2a..9f20bc29de 100644 --- a/npm/packs/sweetalert/abp.resourcemapping.js +++ b/npm/packs/sweetalert/abp.resourcemapping.js @@ -1,5 +1,5 @@ module.exports = { mappings: { - "@node_modules/sweetalert/dist/*.*": "@libs/sweetalert/" + "@node_modules/sweetalert2/dist/*.*": "@libs/sweetalert2/" } } \ No newline at end of file diff --git a/npm/packs/sweetalert/package.json b/npm/packs/sweetalert/package.json index 12ba1349dd..91eb865722 100644 --- a/npm/packs/sweetalert/package.json +++ b/npm/packs/sweetalert/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@abp/core": "~4.4.0-rc.2", - "sweetalert": "^2.1.2" + "sweetalert2": "^11.0.18" }, "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431" }