yvanui.msg.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * power
  3. * @author luoyifan
  4. * 2018-11-22 17:32:00
  5. */
  6. 'use strict';
  7. (function ($) {
  8. $.yvan = $.yvan || {};
  9. var loadingLayerHandler;
  10. function alert(title, msg, icon, fn) {
  11. var opts = {
  12. title: '提示',
  13. msg: msg,
  14. icon: icon,
  15. onMove: function (left, top) {
  16. //防止越界
  17. var $w = $(this);
  18. if (left < 0) {
  19. $w.window("move", { left: 0 });
  20. }
  21. if (top < 0) {
  22. $w.window("move", { top: 0 });
  23. }
  24. }
  25. };
  26. if (fn) {
  27. $.extend(opts, {
  28. closable: false,
  29. fn: fn
  30. });
  31. }
  32. var $window = $.messager.alert(opts);
  33. //实时拖动
  34. $window.window('window').draggable({
  35. onStartDrag: function () { },
  36. onDrag: function (e) {
  37. $window.window('move', {
  38. left: e.data.left,
  39. top: e.data.top
  40. });
  41. },
  42. onStopDrag: function (e) {
  43. $window.window('move', {
  44. left: e.data.left,
  45. top: e.data.top
  46. });
  47. }
  48. });
  49. };
  50. $.extend($.yvan, {
  51. //右下角弹出提示窗口
  52. notify: function (option) {
  53. option = $.extend({}, $.yvan.notify.default, option);
  54. toastr.options = {
  55. closeButton: option.showClose,
  56. debug: false,
  57. newestOnTop: false,
  58. progressBar: true,
  59. positionClass: "toast-bottom-right",
  60. preventDuplicates: false,
  61. onclick: option.onClick,
  62. showDuration: "50",
  63. hideDuration: "50",
  64. extendedTimeOut: "1000",
  65. showEasing: "swing",
  66. hideEasing: "linear",
  67. showMethod: "fadeIn",
  68. hideMethod: "fadeOut"
  69. };
  70. if ($.type(option.autoClose) === 'number') {
  71. toastr.options.timeOut = option.autoClose;
  72. } else if (option.autoClose === false) {
  73. toastr.options.timeOut = -1;
  74. } else {
  75. toastr.options.timeOut = 2000;
  76. }
  77. toastr[option.type](option.body, option.title);
  78. },
  79. progress: function (msg) {
  80. var $dom = $(
  81. '<div class="loading-wrap" style="top:0;left:0;bottom:0;right:0;opacity: .6;">' +
  82. '<div class="spinner">' +
  83. ' <div class="spinner-container container1">\n' +
  84. ' <div class="circle1"></div>\n' +
  85. ' <div class="circle2"></div>\n' +
  86. ' <div class="circle3"></div>\n' +
  87. ' <div class="circle4"></div>\n' +
  88. ' </div>\n' +
  89. ' <div class="spinner-container container2">\n' +
  90. ' <div class="circle1"></div>\n' +
  91. ' <div class="circle2"></div>\n' +
  92. ' <div class="circle3"></div>\n' +
  93. ' <div class="circle4"></div>\n' +
  94. ' </div>\n' +
  95. ' <div class="spinner-container container3">\n' +
  96. ' <div class="circle1"></div>\n' +
  97. ' <div class="circle2"></div>\n' +
  98. ' <div class="circle3"></div>\n' +
  99. ' <div class="circle4"></div>\n' +
  100. ' </div>' +
  101. '</div>' +
  102. '</div>'
  103. );
  104. $('body').append($dom);
  105. },
  106. closep: function () {
  107. $('body').find('.loading-wrap').remove();
  108. },
  109. msg: function (m, callback) {
  110. $('body').down('msg').remove();
  111. var $w = $(
  112. //'<div xtype="msg" class="layui-layer layui-layer-dialog layui-layer-border layui-layer-msg layui-layer-hui yvan-anim yvan-anim-00" style="z-index: 10000;">' +
  113. '<div xtype="msg" class="yvan-msg yvan-anim yvan-anim-00">' +
  114. ' <div class="yvan-msg-content">' + m + '</div>' +
  115. '</div>');
  116. $('body').append($w);
  117. var iframeWidth = $w.parent().width();
  118. var iframeHeight = $w.parent().height();
  119. var windowWidth = $w.width();
  120. var windowHeight = $w.height();
  121. var setWidth = (iframeWidth - windowWidth) / 2;
  122. var setHeight = (iframeHeight - windowHeight) / 2;
  123. if (iframeHeight < windowHeight || setHeight < 0) {
  124. setHeight = 0;
  125. }
  126. if (iframeWidth < windowWidth || setWidth < 0) {
  127. setWidth = 0;
  128. }
  129. $w.css({ left: setWidth, top: setHeight });
  130. setTimeout(function () { $w.remove(); if ($.type(callback) === 'function') {callback()} }, 3000);
  131. },
  132. error: function (msg, afterDialog) {
  133. alert('错误', msg, 'error', afterDialog);
  134. },
  135. info: function (msg, afterDialog) {
  136. alert('提示', msg, 'info', afterDialog);
  137. },
  138. alert: function (msg, afterDialog) {
  139. alert('提示', msg, '', afterDialog);
  140. },
  141. confirm: function (title, fn) {
  142. $.messager.confirm('询问', title, function (r) {
  143. if ($.type(fn) === 'function') {
  144. if (r) {
  145. fn();
  146. }
  147. } else {
  148. if (r) {
  149. if (fn.hasOwnProperty('yes')) {
  150. fn.yes();
  151. }
  152. } else {
  153. if (fn.hasOwnProperty('no')) {
  154. fn.no();
  155. }
  156. }
  157. }
  158. });
  159. }
  160. });
  161. $.yvan.notify.default = {
  162. type: 'success',
  163. showClose: true,
  164. onClick: function () {
  165. },
  166. body: '请设置 body 内容',
  167. title: '请设置 tital 内容',
  168. autoClose: false
  169. };
  170. })(jQuery);