// import { APP_BASE } from "./env.js"
export function showToast(message) {
alert(message);
}
// 联通产品活动新增判断首次加载页面弹窗
export function showAlertlt(message, contentColor) {
var $overlay = $('
');
var $dialog = $(
'' +
'
' +
'
" +
message +
"
" +
'
" +
"
"
);
$("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 = $('');
var $dialog = $(
'' +
"
" +
title +
"
" +
'
' +
message +
"
" +
'
' +
'
' +
(buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
"
" +
"
" +
"
"
);
$("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 = $('');
var $dialog = $(
'' +
// '
' + title + '
' +
'
' +
message +
"
" +
'
' +
'
' +
(buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
"
" +
"
" +
"
"
);
$("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 = $('');
var $dialog = $(
'' +
"
" +
title +
"
" +
'
' +
message +
"
" +
'
' +
'
' +
(buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
"
" +
"
" +
"
"
);
$("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 = $('');
var $loading = $(
'"
);
$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);
}
}