compnt.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. export function showToast(message) {
  2. alert(message)
  3. }
  4. // 联通产品活动新增判断首次加载页面弹窗
  5. export function showAlertlt(message) {
  6. var $overlay = $('<div class="overlaycsr"></div>');
  7. var $dialog = $(
  8. '<div class="dialog-alertsrc">' +
  9. '<div class="guanbi btn"></div>' +
  10. '<div class="content">' + message + '</div>' +
  11. '<div class="actions">' +
  12. ' <div class="btn img_btn"></div>' +
  13. '</div>' +
  14. '</div>');
  15. $("body").css("overflow", "hidden");
  16. $overlay.appendTo($(document.body));
  17. $dialog.appendTo($(document.body));
  18. $dialog.close = function() {
  19. $("body").css("overflow", "auto");
  20. $overlay.remove();
  21. $dialog.remove();
  22. $dialog = null;
  23. }
  24. var def = $.Deferred();
  25. $dialog.find('.btn').on('click', function() {
  26. $dialog.close()
  27. def.resolve($dialog);
  28. })
  29. return def;
  30. }
  31. export function showAlert(message, hideButton, buttonLabel, hideTitle) {
  32. var title = '';
  33. if (hideTitle == undefined || hideTitle == false) {
  34. title = '温馨提示';
  35. }
  36. var $overlay = $('<div class="overlay overlay-alert"></div>');
  37. var $dialog = $(
  38. '<div class="dialog-alert">' +
  39. '<h1>' + title + '</h1>' +
  40. '<div class="content">' + message + '</div>' +
  41. '<div class="actions">' +
  42. ' <div class="btn">' + (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) + '</div>' +
  43. '</div>' +
  44. '</div>');
  45. $("body").css("overflow", "hidden");
  46. $overlay.appendTo($(document.body));
  47. $dialog.appendTo($(document.body));
  48. if (hideButton == true) {
  49. $dialog.find('.btn').remove();
  50. }
  51. $dialog.close = function() {
  52. $("body").css("overflow", "auto");
  53. $overlay.remove();
  54. $dialog.remove();
  55. $dialog = null;
  56. }
  57. var def = $.Deferred();
  58. $dialog.find('.btn').on('click', function() {
  59. $dialog.close()
  60. def.resolve($dialog);
  61. })
  62. return def;
  63. }
  64. //去除温馨提示百度
  65. export function showAlertarxe(message, hideButton, buttonLabel, hideTitle) {
  66. var title = '';
  67. if (hideTitle == undefined || hideTitle == false) {
  68. title = '温馨提示';
  69. }
  70. var $overlay = $('<div class="overlay overlay-alert"></div>');
  71. var $dialog = $(
  72. '<div class="dialog-alert">' +
  73. // '<h1>' + title + '</h1>' +
  74. '<div class="content">' + message + '</div>' +
  75. '<div class="actions">' +
  76. ' <div class="btn btnsr">' + (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) + '</div>' +
  77. '</div>' +
  78. '</div>');
  79. $("body").css("overflow", "hidden");
  80. $overlay.appendTo($(document.body));
  81. $dialog.appendTo($(document.body));
  82. if (hideButton == true) {
  83. $dialog.find('.btn').remove();
  84. }
  85. $dialog.close = function() {
  86. $("body").css("overflow", "auto");
  87. $overlay.remove();
  88. $dialog.remove();
  89. $dialog = null;
  90. }
  91. var def = $.Deferred();
  92. $dialog.find('.btn').on('click', function() {
  93. $dialog.close()
  94. def.resolve($dialog);
  95. })
  96. return def;
  97. }
  98. // 关闭后解除重复点击
  99. export function showAlerts(message, hideButton, buttonLabel, hideTitle) {
  100. var title = '';
  101. if (hideTitle == undefined || hideTitle == false) {
  102. title = '温馨提示';
  103. }
  104. var $overlay = $('<div class="overlay overlay-alert"></div>');
  105. var $dialog = $(
  106. '<div class="dialog-alert">' +
  107. '<h1>' + title + '</h1>' +
  108. '<div class="content">' + message + '</div>' +
  109. '<div class="actions">' +
  110. ' <div class="btn">' + (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) + '</div>' +
  111. '</div>' +
  112. '</div>');
  113. $("body").css("overflow", "hidden");
  114. $overlay.appendTo($(document.body));
  115. $dialog.appendTo($(document.body));
  116. if (hideButton == true) {
  117. $dialog.find('.btn').remove();
  118. }
  119. $dialog.close = function() {
  120. $("body").css("overflow", "auto");
  121. $overlay.remove();
  122. $dialog.remove();
  123. $dialog = null;
  124. }
  125. var def = $.Deferred();
  126. $dialog.find('.btn').on('click', function() {
  127. $dialog.close()
  128. def.resolve($dialog);
  129. unlockClick();
  130. })
  131. return def;
  132. }
  133. export function showLoading(message) {
  134. if (window.$loading) {
  135. window.$loading.trigger('close');
  136. }
  137. $("body").css('overflow', 'hidden');
  138. var msg = (message || '处理中,请稍后...');
  139. var $overlay = $('<div class="overlay overlay-loading"></div>');
  140. var $loading = $(
  141. '<div class="loading">' +
  142. ' <div class="content">' + msg + '</div>' +
  143. '</div>');
  144. $overlay.appendTo($(document.body))
  145. $loading.appendTo($(document.body))
  146. $loading.on('close', function() {
  147. $("body").css('overflow', 'auto');
  148. $overlay.remove();
  149. $loading.remove();
  150. $loading = null;
  151. })
  152. window.$loading = $loading;
  153. return $loading;
  154. }
  155. export function hideLoading($loading) {
  156. if ($loading) {
  157. $loading.trigger('close');
  158. return;
  159. } else if (window.$loading) {
  160. window.$loading.trigger('close');
  161. return;
  162. }
  163. }
  164. /**
  165. * 防止重复点击
  166. * @param {} element
  167. */
  168. export function lockClick(element) {
  169. if ($(element || document.body).data('use') == '1') {
  170. return false;
  171. }
  172. $(element || document.body).data('use', '1');
  173. return true;
  174. }
  175. /**
  176. * 防止重复点击
  177. * @param {*} element
  178. */
  179. export function unlockClick(element) {
  180. $(element || document.body).data('use', '0');
  181. }
  182. /**
  183. * 保留2位小数,并且在在小数点后补0
  184. * @param {*} value
  185. */
  186. export function returnFloat(value) {
  187. var value = Math.round(parseFloat(value) * 100) / 100;
  188. var xsd = value.toString().split(".");
  189. if (xsd.length == 1) {
  190. value = value.toString() + ".00";
  191. return value;
  192. }
  193. if (xsd.length > 1) {
  194. if (xsd[1].length < 2) {
  195. value = value.toString() + "0";
  196. }
  197. return value;
  198. }
  199. }
  200. !(function() {
  201. /**
  202. * 计算今天剩余的毫秒
  203. */
  204. Date.remainMillis = function() {
  205. var now = new Date();
  206. return (23 - now.getHours()) * 60 * 60 * 1000 +
  207. (59 - now.getMinutes()) * 60 * 1000 +
  208. (59 - now.getSeconds()) * 1000;
  209. }
  210. /**
  211. * 计算本月剩余的天数
  212. */
  213. Date.remainMillisMonth = function() {
  214. var curDate = new Date();
  215. var curMonth = curDate.getMonth(); //当前月份 需要加1
  216. curDate.setMonth(curMonth + 1);
  217. curDate.setDate(0) // 关键
  218. curDate.getDate(); // 计算的当月总天数
  219. return curDate.getDate() - new Date().getDate()
  220. }
  221. /**
  222. * 将字符串转换为Date对象
  223. */
  224. Date.from = function(dateString) {
  225. var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
  226. var str = dateString.replace(/-/g, '/');
  227. str = str.replace(pattern, '$1/$2/$3 $4:$5:$6')
  228. return new Date(str)
  229. }
  230. // Date.prototype.from = function (dateString) {
  231. // var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
  232. // var str = dateString.replace(/-/g, '/');
  233. // str = str.replace(pattern, '$1/$2/$3 $4:$5:$6')
  234. // return new Date(str)
  235. // }
  236. /**
  237. * 对Date的扩展,将 Date 转化为指定格式的String
  238. * 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  239. * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  240. * 例子:
  241. * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  242. * (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  243. * author: meizz
  244. */
  245. Date.prototype.format = function(fmt) {
  246. var o = {
  247. "M+": this.getMonth() + 1,
  248. "d+": this.getDate(),
  249. "h+": this.getHours(),
  250. "m+": this.getMinutes(),
  251. "s+": this.getSeconds(),
  252. "q+": Math.floor((this.getMonth() + 3) / 3),
  253. "S": this.getMilliseconds()
  254. };
  255. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  256. for (var k in o)
  257. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  258. return fmt;
  259. }
  260. })();
  261. /**
  262. * 计算当天剩余毫秒数据
  263. */
  264. //export function getTodaySurplusMillis() {
  265. // var time1 = new Date();
  266. // var time2 = Date.from(time1.getFullYear() + '-' + (time1.getMonth() + 1) + '-' + time1.getDate() + ' 23:59:59');
  267. //
  268. // console.log(time2.getTime() - time1)
  269. // return time2.getTime() - time1.getTime();
  270. //}
  271. export function fixWechatBug() {
  272. if (navigator.userAgent.indexOf("MicroMessenger") >= 0) {
  273. //微信6.7.4及以后版本 ios12软键盘顶起页面后隐藏不回弹解决方案
  274. //打开嵌入的统一认证取号页面前,让原来的页面上下滚动。
  275. //统一认证的页面关闭以后,删除定时任务 clearInterval(window.capTimer)
  276. var currentPosition;
  277. var speed = 1; // 页面滚动距离
  278. window.capTimer = setInterval(function() {
  279. currentPosition = document.documentElement.scrollTop || document.body.scrollTop;
  280. currentPosition -= speed;
  281. window.top.scrollTo(0, currentPosition); //页面向上滚动
  282. currentPosition += speed; //speed变量
  283. window.top.scrollTo(0, currentPosition); //页面向下滚动
  284. }, 200);
  285. }
  286. }