文件
mashangyoujiu/Public/js/tips.js

228 行
12 KiB
JavaScript
可执行文件

$('body').append(`<div class="showTips" style="min-width: 50px;max-width: 300px;font-size:14px;height: 40px;border-radius: 5px;background: rgba(0,0,0,0.5);color: white;position: fixed;left: 0;right: 0;top: 0;bottom: 0;margin: auto;display: none;text-align: center;line-height: 40px;"></div>`);
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 = $(`<div class="alertMsg" style="display:none;z-index: 1000;top:0px; left:0px;position: fixed;width:100vw;height:100vh;background-color: rgba(0,0,0,${options.bgOpacity}); display: flex;flex-direction: column;justify-content: center;align-items: center;">
<div style="width: 50vw;margin-bottom: 20vw;height:20vw;background-color: ${options.centerBg}; display: flex;flex-direction: column;justify-content: center;align-items: center; border-radius: 1.5vw;">
<div style="max-width: 50vw; font-size: ${options.msgSize};max-height: 20vw;text-align: center;box-sizing:border-box;padding: 3vw;color:${options.msgColor};overflow: hidden;">${tips}</div>
</div>
</div>`);
$("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 = `<div style="position: relative;z-index: 1000;font-weight: ${options.titleWeight};color: ${options.titleColor};text-align: center;font-size: ${options.titleSize};height: 14vw;line-height: 14vw;margin-top: 1vw;">${options.title}</div>`;
}
var str = $(`<div class="alertBtn" style="display:none;z-index: 999;top:0px; left:0px;position: fixed;width:100vw;height:100vh;background-color: rgba(0,0,0,${options.bgOpacity}); display: flex;flex-direction: column;justify-content: center;align-items: center;">
<div style="position: relative;width:84vw ;min-height:28vw;margin-bottom: 20vw;overflow:hidden;background-color: ${options.centerBg};border-radius: 3vw;">
${str}
<div style="position: absolute;z-index:999;top: 0;left: 0;width: 100%;height: 100%;background-color: ${options.centerBg};filter: blur(5px);overflow: hidden;"></div>
<div style="position: relative;z-index:1000;color: ${options.msgColor};width: 74vw;font-size: ${options.tipsSize};line-height:5.5vw;text-align: center;margin-bottom:2vw;padding: 4vw;">${tips}</div>
<div class="alert_close" style="position: relative;z-index:1000;width:100%;height: ${options.btnHeight};line-height: ${options.btnHeight};border-top:0.5px solid ${options.lineColor};color: ${options.btnColor};text-align: center;font-size: ${options.btnSize};font-weight: bold;font-family: Microsoft YaHei;">${options.btnText}</div>
</div>
</div>`);
$("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 = $(`<div class="alert_tips_con" style="display:none;position: fixed;width: 100vw;height: 100vh;top: 0;left: 0;z-index: 999;background-color: rgba(0,0,0,${options.bgOpacity});display: flex;justify-content: center;align-items: center;">
<div style="width: 80vw;border-radius: 3vw;margin-bottom: 20vw;position: relative;overflow:hidden;background-color: ${options.centerBg};">
<div style="position: absolute;z-index:999;top: 0;left: 0;width: 100%;height: 100%;background-color: ${options.centerBg};filter: blur(5px);overflow: hidden;"></div>
<div style="position: relative;text-align: center;z-index:1000;font-size: ${options.titleSize};font-weight: ${options.titleWeight};margin-top: 4vw;color: ${options.titleColor}">${options.title}</div>
<div style="position: relative;text-align: center;z-index:1000;font-size: ${options.detailSize};margin-top: 3vw;color: ${options.detailColor}">${options.detail}</div>
<div style="position: relative;width: 100%;z-index:1000;border-top: 1px solid ${options.lineColor};display: flex;justify-content: space-around;flex-wrap: nowrap;margin-top: 4vw;">
<div class="alert_btn_no" style="flex: 1;text-align: center;line-height: ${options.btnHeight};font-size: ${options.btnSize};color: ${options.cancelColor};border-right: 1px solid ${options.lineColor};">${options.cancelText}</div>
<div class="alert_btn_sure" style="flex: 1;text-align: center;line-height: ${options.btnHeight};font-size: ${options.btnSize};color: ${options.sureColor};">${options.sureText}</div>
</div>
</div>
</div>`);
$("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 = $(`<div class="alert_loading" style="z-index:999;position:fixed;top: 0;left: 0;width: 100vw;height: 100vh;display: flex;justify-content: center;align-items: center;background-color: rgba(0,0,0,${options.bgOpacity});">
<div style="position: relative;width: 50vw;height: 50vw;display: flex; overflow:hidden;flex-direction: column;justify-content: space-between;align-items: center;border-radius: 1.5vw;background-color: ${options.centerBg};">
<div style="position: absolute;z-index:999;top: 0;left: 0;width: 100%;height: 100%;background-color: ${options.centerBg};filter: blur(5px);overflow: hidden;"></div>
<div style="position: relative;z-index:1000;margin-top: 2vw;font-size: ${options.titleSize};color: ${options.titleColor}">${options.title}</div>
<img style="position: relative;z-index:1000;width: 7vw;height: 7vw;margin-bottom: 20vw;" src="${options.loadSrc}" alt="gif">
</div>
</div>`);
$('.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();
}