compnt.js 9.6 KB

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