$('body').append(`
`);
function showTips(tips,time,fn) {
$('.showTips').text(tips);
$('.showTips').fadeIn();
setTimeout(function() {
$('.showTips').fadeOut();
if(typeof time=="function"){
time();
}else if(typeof fn=="function"){
fn();
}
}, typeof time=='number'?time:1000)
}
//提示
function alertMsg(msg, time, fn) {
var tips = typeof msg == "string" || typeof msg == "number" ? msg : '提示';
var t = typeof time == "number" && time > 100 ? time : 1500;
var tempObj = typeof time == "object" ? time : {};
var options = {
msgColor: tempObj.msgColor ? tempObj.msgColor : '#666666',
bgOpacity: typeof tempObj.bgOpacity == "number" ? tempObj.bgOpacity : 0.2,
centerBg: tempObj.centerBg ? tempObj.centerBg : 'rgb(241,241,241)',
msgSize: tempObj.msgSize ? tempObj.msgSize : '4vw',
t: tempObj.time == "number" && tempObj.time ? tempObj.time : 1500
}
var str = $(``);
$("body").append(str);
$('.alertMsg').fadeIn();
setTimeout(function () {
$('.alertMsg').fadeOut(function () {
$(".alertMsg").remove();
if (typeof msg == "function") {
msg();
} else if (typeof time == "function") {
time();
} else if (typeof fn == "function") {
fn();
}
});
}, t);
}
//点击确定就关闭的提示
function alertBtn(msg, obj, fn) {
var tempObj = typeof obj == 'object' ? obj : {};
var tips = typeof msg == "string" || typeof msg == "number" ? msg : '提示';
var options = {
msgColor: tempObj.msgColor ? tempObj.msgColor : '#333333',
btnText: tempObj.btnText ? tempObj.btnText : '确定',
btnColor: tempObj.btnColor ? tempObj.btnColor : '#00a0e8',
bgOpacity: typeof tempObj.bgOpacity == "number" ? tempObj.bgOpacity : 0.2,
centerBg: tempObj.centerBg ? tempObj.centerBg : 'rgba(249,249,249,0.9)',
lineColor: tempObj.lineColor ? tempObj.lineColor : '#cccccc',
title: tempObj.title ? tempObj.title : '',
titleWeight: tempObj.titleWeight ? tempObj.titleWeight : 'bold',
titleSize: tempObj.titleSize ? tempObj.titleSize : '4.5vw',
tipsSize: tempObj.tipsSize ? tempObj.tipsSize : '4.1vw',
btnSize: tempObj.btnSize ? tempObj.btnSize : '4.5vw',
titleColor: tempObj.titleColor ? tempObj.titleColor : '#111111',
btnHeight: tempObj.btnHeight ? tempObj.btnHeight : '16vw',
};
var str = '';
if (options.title != '') {
str = `${options.title}
`;
}
var str = $(`
${str}
${tips}
${options.btnText}
`);
$("body").append(str);
$('.alertBtn').fadeIn();
$('body').ready(function () {
$('.alert_close').on('click',function () {
$('.alertBtn').fadeOut(function () {
$(".alertBtn").remove();
if (typeof msg == "function") {
msg();
} else if (typeof obj == "function") {
obj();
} else if (typeof fn == "function") {
fn();
}
});
})
});
}
//确认或取消
function alertSureAndCancel(obj) {
var tempObj = typeof obj == 'object' ? obj : {};
var options = {
title: tempObj.title ? tempObj.title : '温馨提示',
detail: tempObj.detail ? tempObj.detail : '确定进行该操作?',
cancelText: tempObj.cancelText ? tempObj.cancelText : '取消',
sureText: tempObj.sureText ? tempObj.sureText : '确定',
titleColor: tempObj.titleColor ? tempObj.titleColor : '#111111',
titleWeight: tempObj.titleWeight ? tempObj.titleWeight : 'bold',
detailColor: tempObj.detailColor ? tempObj.detailColor : '#000000',
sureColor: tempObj.sureColor ? tempObj.sureColor : '#00a0e8',
cancelColor: tempObj.cancelColor ? tempObj.cancelColor : '#666666',
bgOpacity: typeof tempObj.bgOpacity == "number" ? tempObj.bgOpacity : 0.6,
centerBg: tempObj.centerBg ? tempObj.centerBg : 'rgba(241,241,241,0.9)',
lineColor: tempObj.lineColor ? tempObj.lineColor : '#cccccc',
titleSize: tempObj.titleSize ? tempObj.titleSize : '5vw',
detailSize: tempObj.detailSize ? tempObj.detailSize : '4.5vw',
btnSize: tempObj.btnSize ? tempObj.btnSize : '4.5vw',
btnHeight: tempObj.btnHeight ? tempObj.btnHeight : '12vw',
};
var str = $(`
${options.title}
${options.detail}
${options.cancelText}
${options.sureText}
`);
$("body").append(str);
$('.alert_tips_con').fadeIn();
$('.alert_btn_sure').click(function () {
$('.alert_tips_con').fadeOut(function () {
$('.alert_tips_con').remove();
if (typeof obj.sure == "function") {
tempObj.sure();
}
});
})
$('.alert_btn_no').click(function () {
$('.alert_tips_con').fadeOut(function () {
$('.alert_tips_con').remove();
if (typeof obj.cancel == "function") {
tempObj.cancel();
}
});
})
}
//关闭提示框
function hideSureAndCancel(fn) {
$('.alert_tips_con').fadeOut(function () {
$('.alert_tips_con').remove();
if (typeof fn == "function") {
fn();
}
});
}
//等待
function alertShowLoading(obj, fn) {
var tempObj = typeof obj == "object" ? obj : {};
var options = {
title: tempObj.title ? tempObj.title : '',
titleColor: tempObj.titleColor ? tempObj.titleColor : '#111111',
loadSrc: tempObj.loadSrc ? tempObj.loadSrc : '/Public/vip/images/loading2.gif',
bgOpacity: typeof tempObj.bgOpacity == "number" ? tempObj.bgOpacity : 0.6,
titleSize: tempObj.titleSize ? tempObj.titleSize : '4vw',
centerBg: tempObj.centerBg ? tempObj.centerBg : 'rgba(241,241,241,0.9)'
}
var str = $(`
${options.title}
`);
$('.img').ready(function () {
$("body").append(str);
$('.alert_loading').fadeIn();
if (typeof obj == "function") {
obj();
} else if (typeof fn == "function") {
fn();
}
})
}
//关闭等待提示
function alertHideLoading(fn) {
$('.alert_loading').fadeOut();
$('.alert_loading').remove();
setTimeout(function () {
if (typeof fn == "function") {
fn();
}
}, 10)
}
/**
* 浏览器回退事件监听
*/
function ToUrlSelfFn(tit, se, fn) {
var listenerBackHandler = {
param: {
isRun: false, //防止微信返回立即执行popstate事件
},
listenerBack: function () {
window.addEventListener("popstate", function (e) {
localStorage.viprefrash = 0;//防止页面刷新的时候反复pushstate
if (listenerBackHandler.param.isRun) {
fn();
}
}, false)
},
//初始化返回事件
initBack: function () {
window.addEventListener('pageshow', function () {
listenerBackHandler.param.isRun = false;
setTimeout(function () {
listenerBackHandler.param.isRun = true;
listenerBackHandler.listenerBack();
}, 500); //延迟1秒 防止微信返回立即执行popstate事件
});
}
}
// listenerBackHandler.listenerBack();
listenerBackHandler.initBack();
}