123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /**
- * Created by pc on 2016/10/21.
- */
- $.extend({
- modal: {
- /**
- * alert弹窗
- * @param message
- * @param type warning,error,success,info和question
- * @param callback
- */
- alert: function (message, type, callback) {
- if (type == undefined) {
- type = "info";
- }
- swal({
- title: message,
- type: type,
- showConfirmButton: true,
- },
- function(){
- if (callback) {
- callback();
- }
- });
- },
- /**
- * 提示弹窗
- * @param message
- */
- info: function (message) {
- swal(message);
- },
- /**
- * 成功弹窗
- * @param message
- */
- success: function (message) {
- this.notify(message, 'success');
- },
- /**
- * 失败弹窗
- * @param message
- */
- error: function (message) {
- this.notify(message, 'error');
- },
- /**
- * 通知弹窗
- * @param message
- * @param type
- * @param callback
- */
- notify: function (message, type, callback) {
- swal({
- title: message,
- type: type,
- timer: 1500,
- showConfirmButton: false,
- animation: false
- }, function () {
- if (callback) {
- callback();
- }
- // 没callback时候不会关闭,应该是bug
- swal.close();
- });
- },
- /**
- * 确认弹窗
- * @param message
- * @param ok 确认回调函数
- * @param cancel
- */
- confirm: function (message, ok, cancel) {
- swal({
- title: message,
- type: "warning",
- showCancelButton: true,
- cancelButtonText:"取消",
- confirmButtonColor: "#DD6B55",
- confirmButtonText: "确定",
- closeOnConfirm: false,
- animation: false,
- showLoaderOnConfirm: true
- },
- function(){
- ok();
- });
- },
- /**
- * 打开加载
- */
- loading:function () {
- $("<div>", {id:"loading-global", class:"loading-global"}).appendTo('body');
- },
- /**
- * 关闭加载
- */
- unloading:function () {
- $("#loading-global").remove();
- },
- /**
- * 关闭弹窗
- * @param index
- */
- close: function (index) {
- swal.close();
- }
- }
- });
- window.alert = $.modal.alert;
|