123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- // import { APP_BASE } from "./env.js"
- export function showToast(message) {
- alert(message);
- }
- // 联通产品活动新增判断首次加载页面弹窗
- export function showAlertlt(message, contentColor) {
- var $overlay = $('<div class="overlaycsr"></div>');
- var $dialog = $(
- '<div class="dialog-alertsrc">' +
- '<div class="guanbi btn"></div>' +
- '<div class="content" style="color:' +
- contentColor +';"' +
- ">" +
- message +
- "</div>" +
- '<div class="actions">' +
- ' <div class="btn img_btn"></div>' +
- "</div>" +
- "</div>"
- );
- $("body").css("overflow", "hidden");
- $overlay.appendTo($(document.body));
- $dialog.appendTo($(document.body));
- $dialog.close = function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- };
- var def = $.Deferred();
- $dialog.find(".btn").on("click", function () {
- $dialog.close();
- def.resolve($dialog);
- });
- return def;
- }
- export function showAlert(message, hideButton, buttonLabel, hideTitle) {
- var title = "";
- if (hideTitle == undefined || hideTitle == false) {
- title = "温馨提示";
- }
- var $overlay = $('<div class="overlay overlay-alert"></div>');
- var $dialog = $(
- '<div class="dialog-alert">' +
- "<h1>" +
- title +
- "</h1>" +
- '<div class="content">' +
- message +
- "</div>" +
- '<div class="actions">' +
- ' <div class="btn">' +
- (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
- "</div>" +
- "</div>" +
- "</div>"
- );
- $("body").css("overflow", "hidden");
- $overlay.appendTo($(document.body));
- $dialog.appendTo($(document.body));
- if (hideButton == true) {
- $dialog.find(".btn").remove();
- }
- $dialog.close = function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- };
- var def = $.Deferred();
- $dialog.find(".btn").on("click", function () {
- $dialog.close();
- def.resolve($dialog);
- });
- return def;
- }
- //去除温馨提示百度
- export function showAlertarxe(message, hideButton, buttonLabel, hideTitle) {
- var title = "";
- if (hideTitle == undefined || hideTitle == false) {
- title = "温馨提示";
- }
- var $overlay = $('<div class="overlay overlay-alert"></div>');
- var $dialog = $(
- '<div class="dialog-alert">' +
- // '<h1>' + title + '</h1>' +
- '<div class="content">' +
- message +
- "</div>" +
- '<div class="actions">' +
- ' <div class="btn btnsr">' +
- (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
- "</div>" +
- "</div>" +
- "</div>"
- );
- $("body").css("overflow", "hidden");
- $overlay.appendTo($(document.body));
- $dialog.appendTo($(document.body));
- if (hideButton == true) {
- $dialog.find(".btn").remove();
- }
- $dialog.close = function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- };
- var def = $.Deferred();
- $dialog.find(".btn").on("click", function () {
- $dialog.close();
- def.resolve($dialog);
- });
- return def;
- }
- // 关闭后解除重复点击
- export function showAlerts(message, hideButton, buttonLabel, hideTitle) {
- var title = "";
- if (hideTitle == undefined || hideTitle == false) {
- title = "温馨提示";
- }
- var $overlay = $('<div class="overlay overlay-alert"></div>');
- var $dialog = $(
- '<div class="dialog-alert">' +
- "<h1>" +
- title +
- "</h1>" +
- '<div class="content">' +
- message +
- "</div>" +
- '<div class="actions">' +
- ' <div class="btn">' +
- (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
- "</div>" +
- "</div>" +
- "</div>"
- );
- $("body").css("overflow", "hidden");
- $overlay.appendTo($(document.body));
- $dialog.appendTo($(document.body));
- if (hideButton == true) {
- $dialog.find(".btn").remove();
- }
- $dialog.close = function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- };
- var def = $.Deferred();
- $dialog.find(".btn").on("click", function () {
- $dialog.close();
- def.resolve($dialog);
- unlockClick();
- });
- return def;
- }
- export function showLoading(message) {
- if (window.$loading) {
- window.$loading.trigger("close");
- }
- $("body").css("overflow", "hidden");
- var msg = message || "处理中,请稍后...";
- var $overlay = $('<div class="overlay overlay-loading"></div>');
- var $loading = $(
- '<div class="loading">' +
- ' <div class="content">' +
- msg +
- "</div>" +
- "</div>"
- );
- $overlay.appendTo($(document.body));
- $loading.appendTo($(document.body));
- $loading.on("close", function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $loading.remove();
- $loading = null;
- });
- window.$loading = $loading;
- return $loading;
- }
- export function hideLoading($loading) {
- if ($loading) {
- $loading.trigger("close");
- return;
- } else if (window.$loading) {
- window.$loading.trigger("close");
- return;
- }
- }
- /**
- * 防止重复点击
- * @param {} element
- */
- export function lockClick(element) {
- if ($(element || document.body).data("use") == "1") {
- return false;
- }
- $(element || document.body).data("use", "1");
- return true;
- }
- /**
- * 防止重复点击
- * @param {*} element
- */
- export function unlockClick(element) {
- $(element || document.body).data("use", "0");
- }
- /**
- * 保留2位小数,并且在在小数点后补0
- * @param {*} value
- */
- export function returnFloat(value) {
- var value = Math.round(parseFloat(value) * 100) / 100;
- var xsd = value.toString().split(".");
- if (xsd.length == 1) {
- value = value.toString() + ".00";
- return value;
- }
- if (xsd.length > 1) {
- if (xsd[1].length < 2) {
- value = value.toString() + "0";
- }
- return value;
- }
- }
- !(function () {
- /**
- * 计算今天剩余的毫秒
- */
- Date.remainMillis = function () {
- var now = new Date();
- return (
- (23 - now.getHours()) * 60 * 60 * 1000 +
- (59 - now.getMinutes()) * 60 * 1000 +
- (59 - now.getSeconds()) * 1000
- );
- };
- /**
- * 计算本月剩余的天数
- */
- Date.remainMillisMonth = function () {
- var curDate = new Date();
- var curMonth = curDate.getMonth(); //当前月份 需要加1
- curDate.setMonth(curMonth + 1);
- curDate.setDate(0); // 关键
- curDate.getDate(); // 计算的当月总天数
- return curDate.getDate() - new Date().getDate();
- };
- /**
- * 将字符串转换为Date对象
- */
- Date.from = function (dateString) {
- var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
- var str = dateString.replace(/-/g, "/");
- str = str.replace(pattern, "$1/$2/$3 $4:$5:$6");
- return new Date(str);
- };
- // Date.prototype.from = function (dateString) {
- // var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
- // var str = dateString.replace(/-/g, '/');
- // str = str.replace(pattern, '$1/$2/$3 $4:$5:$6')
- // return new Date(str)
- // }
- /**
- * 对Date的扩展,将 Date 转化为指定格式的String
- * 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
- * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
- * 例子:
- * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
- * (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
- * author: meizz
- */
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1,
- "d+": this.getDate(),
- "h+": this.getHours(),
- "m+": this.getMinutes(),
- "s+": this.getSeconds(),
- "q+": Math.floor((this.getMonth() + 3) / 3),
- S: this.getMilliseconds(),
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(
- RegExp.$1,
- (this.getFullYear() + "").substr(4 - RegExp.$1.length)
- );
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt))
- fmt = fmt.replace(
- RegExp.$1,
- RegExp.$1.length == 1
- ? o[k]
- : ("00" + o[k]).substr(("" + o[k]).length)
- );
- return fmt;
- };
- })();
- /**
- * 计算当天剩余毫秒数据
- */
- //export function getTodaySurplusMillis() {
- // var time1 = new Date();
- // var time2 = Date.from(time1.getFullYear() + '-' + (time1.getMonth() + 1) + '-' + time1.getDate() + ' 23:59:59');
- //
- // console.log(time2.getTime() - time1)
- // return time2.getTime() - time1.getTime();
- //}
- export function fixWechatBug() {
- if (navigator.userAgent.indexOf("MicroMessenger") >= 0) {
- //微信6.7.4及以后版本 ios12软键盘顶起页面后隐藏不回弹解决方案
- //打开嵌入的统一认证取号页面前,让原来的页面上下滚动。
- //统一认证的页面关闭以后,删除定时任务 clearInterval(window.capTimer)
- var currentPosition;
- var speed = 1; // 页面滚动距离
- window.capTimer = setInterval(function () {
- currentPosition =
- document.documentElement.scrollTop || document.body.scrollTop;
- currentPosition -= speed;
- window.top.scrollTo(0, currentPosition); //页面向上滚动
- currentPosition += speed; //speed变量
- window.top.scrollTo(0, currentPosition); //页面向下滚动
- }, 200);
- }
- }
|