You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
9.1 KiB

2 years ago
  1. /**
  2. * 函數名稱
  3. * 目的彈出帶一個按鈕的提示窗口並執行方法
  4. * @param {String} msg 提示訊息
  5. * @param {String} title 提示窗口的標題success....
  6. * @param {String} Position提示窗口的位置
  7. * @param {String} type :提示方式success InfoWarningError四種
  8. * @param {String} msg :提示框中顯示的訊息
  9. * @param {String} title :提示框顯示的其他html內容
  10. * @param {String} showDuration :显示时间
  11. * @param {String} hideDuration :隐藏时间
  12. * @param {String} timeOut :超时
  13. * @param {String} extendedTimeOut :延长超时
  14. * @param {String} showEasing :
  15. * @param {String} hideEasing :
  16. * @param {String} showMethod :顯示的方式
  17. * @param {String} hideMethod :隱藏的方式
  18. * @param {String} addClear :是否添加清除
  19. * @param {String} closeButton :是否添加closeButton
  20. * @param {String} debug :
  21. * @param {String} newestOnTop :
  22. * @param {String} progressBar :是否添加進度顯示
  23. * @param {String} positionClass :位置
  24. * @param {String} preventDuplicates:是否防止重复
  25. * @param {Function} func :執行方法
  26. */
  27. function getMsgBox(type, msg, title, showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, ResetButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk, fnCl) {
  28. var title = title || i18next.t("common.Tips") || '<span data-i18n="common.Tips"></span>';
  29. toastr.options = {
  30. closeButton: closeButton,
  31. ResetButton: ResetButton,
  32. debug: debug,
  33. newestOnTop: newestOnTop,
  34. progressBar: progressBar,
  35. positionClass: positionClass || 'toast-top-center',
  36. preventDuplicates: preventDuplicates,
  37. onclick: null
  38. };
  39. if (addBehaviorOnToastClick) {
  40. toastr.options.onclick = BehaviorFunc;
  41. }
  42. if (showDuration) {
  43. toastr.options.showDuration = showDuration;
  44. }
  45. if (toastr.options.ResetButton && toastr.options.closeButton) {
  46. msg = '<div>' + msg + '</div><div style="float:right"><button type="button" id="okBtn" class="btn btn-success" data-i18n="common.Confirm">確認</button><button type="button" id="surpriseBtn" class="btn btn-primary" style="margin: 0 8px 0 8px" data-i18n="common.Cancel">取消</button></div>';
  47. }
  48. else if (!toastr.options.ResetButton && toastr.options.closeButton) {//只存在確認按鈕
  49. msg += '<div style="float:right"><button type="button" id="okBtn" class="btn btn-info" data-i18n="common.Confirm">確認</button></div>';
  50. }
  51. if (hideDuration) {
  52. toastr.options.hideDuration = hideDuration;
  53. }
  54. if (timeOut) {
  55. toastr.options.timeOut = timeOut;
  56. //setTimeout(BehaviorFunc, timeOut)
  57. }
  58. if (extendedTimeOut) {
  59. toastr.options.extendedTimeOut = extendedTimeOut;
  60. }
  61. if (showEasing) {
  62. toastr.options.showEasing = showEasing;
  63. }
  64. if (hideEasing) {
  65. toastr.options.hideEasing = hideEasing;
  66. }
  67. if (showMethod) {
  68. toastr.options.showMethod = showMethod;
  69. }
  70. if (hideMethod) {
  71. toastr.options.hideMethod = hideMethod;
  72. }
  73. if (addClear) {//是否清空之前樣式
  74. toastr.options.tapToDismiss = false;
  75. }
  76. var $toast = toastr[type](msg, title);
  77. if (($toast) && $toast.find('#okBtn').length) {
  78. $toast.delegate('#okBtn', 'click',
  79. function () {
  80. toastr.clear();
  81. $(".toast-close-button").click();
  82. if (fnOk) {//如果方法存在就執行
  83. var func = fnOk;
  84. func();
  85. }
  86. return true;
  87. }
  88. );
  89. transLang($('#okBtn'));
  90. }
  91. if (($toast) && $toast.find('#surpriseBtn').length) {
  92. $toast.delegate('#surpriseBtn', 'click',
  93. function () {
  94. toastr.clear();
  95. $(".toast-close-button").click();
  96. if (fnCl) {//如果方法存在就執行
  97. var func = fnCl;
  98. func();
  99. }
  100. return false;
  101. }
  102. );
  103. }
  104. }
  105. /**
  106. * 函數名稱
  107. * 目的彈出提示窗口並執行方法
  108. * @param {String} msg 提示訊息
  109. * @param {String} type 提示窗口的標題success....
  110. * @param {Function} func 執行方法
  111. * @param {String} position提示窗口的位置
  112. */
  113. function msgAndGo(msg, type, func, position) {
  114. var title, showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk, fnCl;
  115. showDuration = "300";
  116. hideDuration = "1000";
  117. timeOut = '0';
  118. extendedTimeOut = '0';
  119. showEasing = "swing";
  120. hideEasing = "linear";
  121. showMethod = "fadeIn";
  122. hideMethod = "fadeOut";
  123. addClear = true;
  124. closeButton = true;
  125. debug = false;
  126. newestOnTop = true;
  127. progressBar = false;
  128. positionClass = position;
  129. preventDuplicates = false;
  130. addBehaviorOnToastClick = true;
  131. BehaviorFunc = func;
  132. fnOk = null;
  133. fnCl = null;
  134. ResetButton = false;
  135. type = type || 'success';
  136. getMsgBox(type, msg, title, showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, ResetButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk, fnCl);
  137. }
  138. var
  139. /**
  140. * 函數名稱
  141. * 目的顯示提示訊息替代ALERT功能
  142. * @param {String} msg 提示訊息
  143. * @param {String} type 提示窗口的標題success....
  144. * @param {String} position提示窗口的位置
  145. * @param {String} title 標題
  146. */
  147. showMsg = function (msg, type, position, title) {
  148. var showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk;
  149. showDuration = "300";
  150. hideDuration = "1000";
  151. timeOut = "3000";
  152. extendedTimeOut = "1000";
  153. showEasing = "swing";
  154. hideEasing = "linear";
  155. showMethod = "fadeIn";
  156. hideMethod = "fadeOut";
  157. addClear = false;
  158. closeButton = false;
  159. debug = false;
  160. newestOnTop = true;
  161. progressBar = false;
  162. positionClass = position;
  163. preventDuplicates = true;
  164. addBehaviorOnToastClick = true;
  165. BehaviorFunc = null;
  166. fnOk = null;
  167. fnCl = null;
  168. ResetButton = false;
  169. type = type || 'info';
  170. getMsgBox(type, msg, title, showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, ResetButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk, fnCl);
  171. },
  172. /**
  173. * 函數名稱
  174. * 目的顯示提示訊息替代ALERT功能
  175. * @param {String} msg 提示訊息
  176. * @param {String} url 轉向地址
  177. * @param {String} param 參數
  178. * @param {String} type 提示窗口的標題success....
  179. * @param {String} position提示窗口的位置
  180. */
  181. showMsgAndGo = function (msg, url, param, type, position) {
  182. if (url != "") {//如果有提供跳轉畫面的url就執行跳轉頁面的動作
  183. msgAndGo(msg, type, function () { parent.openPageTab(url, param) }, position);
  184. }
  185. },
  186. /**
  187. * 函數名稱
  188. * 目的顯示提示訊息替代ALERT功能
  189. * @param {String} msg 提示訊息
  190. * @param {String} param 參數
  191. * @param {String} type 提示窗口的標題success....
  192. * @param {String} position提示窗口的位置
  193. */
  194. showTips = function (msg, type, position, title) {
  195. var showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk;
  196. showDuration = "300";
  197. hideDuration = "1000";
  198. timeOut = '0';
  199. extendedTimeOut = '0';
  200. showEasing = "swing";
  201. hideEasing = "swing";
  202. showMethod = "fadeIn";
  203. hideMethod = "fadeOut";
  204. addClear = true;
  205. closeButton = false;
  206. debug = false;
  207. newestOnTop = false;
  208. progressBar = false;
  209. positionClass = 'toast-edit-center';
  210. preventDuplicates = false;
  211. addBehaviorOnToastClick = false;
  212. BehaviorFunc = null;
  213. fnOk = null;
  214. fnCl = null;
  215. ResetButton = false;
  216. type = type || 'info';
  217. getMsgBox(type, msg, title, showDuration, hideDuration, timeOut, extendedTimeOut, showEasing, hideEasing, showMethod, hideMethod, addClear, closeButton, ResetButton, debug, newestOnTop, progressBar, positionClass, preventDuplicates, addBehaviorOnToastClick, BehaviorFunc, fnOk, fnCl);
  218. };