/** * power * @author luoyifan * 2018-11-22 17:32:00 */ 'use strict'; (function ($) { $.yvan = $.yvan || {}; var loadingLayerHandler; function alert(title, msg, icon, fn) { var opts = { title: '提示', msg: msg, icon: icon, onMove: function (left, top) { //防止越界 var $w = $(this); if (left < 0) { $w.window("move", { left: 0 }); } if (top < 0) { $w.window("move", { top: 0 }); } } }; if (fn) { $.extend(opts, { closable: false, fn: fn }); } var $window = $.messager.alert(opts); //实时拖动 $window.window('window').draggable({ onStartDrag: function () { }, onDrag: function (e) { $window.window('move', { left: e.data.left, top: e.data.top }); }, onStopDrag: function (e) { $window.window('move', { left: e.data.left, top: e.data.top }); } }); }; $.extend($.yvan, { //右下角弹出提示窗口 notify: function (option) { option = $.extend({}, $.yvan.notify.default, option); toastr.options = { closeButton: option.showClose, debug: false, newestOnTop: false, progressBar: true, positionClass: "toast-bottom-right", preventDuplicates: false, onclick: option.onClick, showDuration: "50", hideDuration: "50", extendedTimeOut: "1000", showEasing: "swing", hideEasing: "linear", showMethod: "fadeIn", hideMethod: "fadeOut" }; if ($.type(option.autoClose) === 'number') { toastr.options.timeOut = option.autoClose; } else if (option.autoClose === false) { toastr.options.timeOut = -1; } else { toastr.options.timeOut = 2000; } toastr[option.type](option.body, option.title); }, progress: function (msg) { var $dom = $( '
' + '
' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
\n' + '
' + '
' + '
' ); $('body').append($dom); }, closep: function () { $('body').find('.loading-wrap').remove(); }, msg: function (m, callback) { $('body').down('msg').remove(); var $w = $( //'
' + '
' + '
' + m + '
' + '
'); $('body').append($w); var iframeWidth = $w.parent().width(); var iframeHeight = $w.parent().height(); var windowWidth = $w.width(); var windowHeight = $w.height(); var setWidth = (iframeWidth - windowWidth) / 2; var setHeight = (iframeHeight - windowHeight) / 2; if (iframeHeight < windowHeight || setHeight < 0) { setHeight = 0; } if (iframeWidth < windowWidth || setWidth < 0) { setWidth = 0; } $w.css({ left: setWidth, top: setHeight }); setTimeout(function () { $w.remove(); if ($.type(callback) === 'function') {callback()} }, 3000); }, error: function (msg, afterDialog) { alert('错误', msg, 'error', afterDialog); }, info: function (msg, afterDialog) { alert('提示', msg, 'info', afterDialog); }, alert: function (msg, afterDialog) { alert('提示', msg, '', afterDialog); }, confirm: function (title, fn) { $.messager.confirm('询问', title, function (r) { if ($.type(fn) === 'function') { if (r) { fn(); } } else { if (r) { if (fn.hasOwnProperty('yes')) { fn.yes(); } } else { if (fn.hasOwnProperty('no')) { fn.no(); } } } }); } }); $.yvan.notify.default = { type: 'success', showClose: true, onClick: function () { }, body: '请设置 body 内容', title: '请设置 tital 内容', autoClose: false }; })(jQuery);