faim
Version:
Element Plus & Element UI isomorphic UI component library, more than Element.
177 lines (175 loc) • 4.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _sweetalert = _interopRequireDefault(require("sweetalert2"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function success() {
const [titleOrOptions, html, icon] = arguments;
if (!titleOrOptions) {
console.error("Parameter is empty");
return;
}
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return _sweetalert.default.fire({
icon: "success",
toast: true,
timer: 2e3,
didOpen: toast => {
toast.addEventListener("mouseenter", _sweetalert.default.stopTimer);
toast.addEventListener("mouseleave", _sweetalert.default.resumeTimer);
},
position: "top",
showConfirmButton: false,
...options
});
}
function info() {
const [titleOrOptions, html, icon] = arguments;
if (!titleOrOptions) {
console.error("Parameter is empty");
return;
}
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return _sweetalert.default.fire({
icon: "info",
toast: true,
timer: 3e3,
timerProgressBar: true,
didOpen: toast => {
toast.addEventListener("mouseenter", _sweetalert.default.stopTimer);
toast.addEventListener("mouseleave", _sweetalert.default.resumeTimer);
},
showConfirmButton: false,
...options
});
}
function warning() {
const [titleOrOptions, html, icon] = arguments;
if (!titleOrOptions) {
console.error("Parameter is empty");
return;
}
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return _sweetalert.default.fire({
icon: "warning",
backdrop: false,
confirmButtonColor: "#66b1ff",
timer: 5e3,
timerProgressBar: true,
didOpen(toast) {
toast.addEventListener("mouseenter", _sweetalert.default.stopTimer);
toast.addEventListener("mouseleave", _sweetalert.default.resumeTimer);
},
...options
});
}
function error() {
const [titleOrOptions, html, icon] = arguments;
if (!titleOrOptions) {
console.error("Parameter is empty");
return;
}
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return _sweetalert.default.fire({
icon: "error",
allowOutsideClick: false,
confirmButtonColor: "#66b1ff",
...options
});
}
function confirm() {
const [titleOrOptions, html, icon] = arguments;
if (!titleOrOptions) {
console.error("Parameter is empty");
return;
}
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return new Promise((resolve, reject) => {
_sweetalert.default.fire({
icon: "question",
confirmButtonColor: "#66b1ff",
showCancelButton: true,
reverseButtons: true,
allowOutsideClick: false,
...options
}).then(e => {
if (e.isConfirmed) {
resolve(e);
} else {
reject(e);
}
});
});
}
function loading() {
const [titleOrOptions, html, icon] = arguments;
const options = typeof titleOrOptions === "string" ? {
title: titleOrOptions,
...(html && {
html
}),
...(icon && {
icon
})
} : titleOrOptions;
return _sweetalert.default.fire({
showCancelButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
background: "transparent",
width: "unset",
didOpen() {
_sweetalert.default.showLoading();
},
...options
});
}
module.exports = Object.assign(_sweetalert.default, {
success,
warning,
info,
error,
confirm,
loading
});