730 lines
26 KiB
JavaScript
730 lines
26 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
let env = EnvCheck();
|
||
if (env == 'test') {
|
||
new VConsole();
|
||
}
|
||
// 封装layer消息提醒框
|
||
let layerIndex
|
||
const showLoading = (content = '加载中...') => {
|
||
layer.open({
|
||
type: 2,
|
||
shadeClose: false,
|
||
content,
|
||
success (e) {
|
||
layerIndex = $(e).attr('index')
|
||
}
|
||
})
|
||
}
|
||
const hideLoading = (index) => {
|
||
layer.close(index)
|
||
}
|
||
const toastMsg = (content = '操作完成', time = 2) => {
|
||
layer.open({
|
||
content,
|
||
time,
|
||
skin: 'msg'
|
||
})
|
||
}
|
||
var leftArr = ['3.6rem', '2.5rem', '1.4rem', '0.3rem', '0.3rem', '0.3rem', '1.4rem', '2.5rem', '2.5rem', '2.5rem', '1.4rem', '0.3rem', '0.3rem', '0.3rem', '0.3rem', '1.4rem', '2.5rem', '2.5rem', '3.6rem', '4.7rem', '4.7rem', '5.8rem', '6.9rem', '6.9rem', '6.9rem', '5.8rem', '5.8rem', '5.8rem', '6.9rem', '6.9rem', '6.9rem', '5.8rem', '4.7rem', '3.6rem'];
|
||
var bottArr = ['0.9rem', '0.9rem', '0.9rem', '0.9rem', '2.0rem', '3.1rem', '3.1rem', '3.1rem', '4.3rem', '5.6rem', '5.6rem', '5.6rem', '6.7rem', '7.8rem', '9.1rem', '9.1rem', '9.1rem', '7.8rem', '7.8rem', '7.8rem', '9.1rem', '9.1rem', '9.1rem', '7.8rem', '6.7rem', '6.7rem', '5.6rem', '4.3rem', '4.3rem', '3.1rem', '2.0rem', '2.0rem', '2.0rem', '2.0rem'];
|
||
var curDate; //当天日期;
|
||
var rankType = 1; //排行榜类型(1=送礼日榜,2=送礼总榜,3=收礼日榜,4=收礼总榜);
|
||
var data = null;//默认日榜;
|
||
var isEndTime = null;//判断是否活动结束;
|
||
var roomUid = null;//房间uid;
|
||
var type = 'a';//a:送礼b:收礼;
|
||
var type2 = 'a';//a:日榜b:总榜;
|
||
var page = 1;//页码
|
||
var drawPageSizeLack = true;//记录滑动锁
|
||
var poolType = null;//宝箱等级
|
||
var mapPos = null;//当前格子下标
|
||
var drawLock = true;//抽奖的锁
|
||
var candyNum = 0;//糖果卷
|
||
// 初始化函数
|
||
$(function () {
|
||
getInfoFromClient()
|
||
setTimeout(function () {
|
||
// 页面全屏
|
||
if (browser.app) {
|
||
if (browser.android) {
|
||
window.androidJsObj.initShowNav(false)
|
||
} else {
|
||
window.webkit.messageHandlers.initShowNav.postMessage(0)
|
||
}
|
||
};
|
||
// 顶部返回事件
|
||
$('.back').click(() => {
|
||
if (browser.android) {
|
||
window.androidJsObj.closeWebView()
|
||
} else {
|
||
window.webkit.messageHandlers.closeWebView.postMessage(null)
|
||
}
|
||
})
|
||
// 礼物轮播
|
||
var mySwiper = new Swiper('.swiper', {
|
||
// direction: "vertical",
|
||
loop: true,
|
||
autoplay: {
|
||
delay: 3500,//
|
||
disableOnInteraction: false
|
||
}
|
||
})
|
||
getTaskConfig();
|
||
getRecommendRoom();
|
||
getConfig();
|
||
}, 100)
|
||
})
|
||
// 获取房间Uid接口
|
||
function getRecommendRoom () {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/home/tab/home/one',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
roomUid = res.data;
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 抽奖配置接口
|
||
function getConfig () {
|
||
// showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/act/2023Halloween/draw/getConfig',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
// 处理糖果数量
|
||
$('.myCandy').text('我的糖果券:' + res.data.candyNum);
|
||
candyNum = res.data.candyNum;
|
||
// 当前格子下标
|
||
mapPos = res.data.mapPos;
|
||
$('.page1 .road .gui').css({
|
||
left: leftArr[res.data.mapPos],
|
||
bottom: bottArr[res.data.mapPos],
|
||
})
|
||
// 判断活动结束时间
|
||
if (res.timestamp > res.data.endTime) {
|
||
isEndTime = true;
|
||
$('.endActivity').show();
|
||
}
|
||
// 判断等级处理
|
||
poolType = res.data.boxLevel;
|
||
if (res.data.boxLevel == 0) {
|
||
$('.page1 .mc').show();
|
||
} else if (res.data.boxLevel == 1) {
|
||
$('.page1 .boxs1').addClass('boxOpen1');
|
||
$('.page1 .road .boxImg').attr('src', './images/box1.png');
|
||
} else if (res.data.boxLevel == 2) {
|
||
$('.page1 .boxs1').addClass('boxOpen1');
|
||
$('.page1 .boxs2').addClass('boxOpen2');
|
||
$('.page1 .road .boxImg').attr('src', './images/box2.png');
|
||
} else if (res.data.boxLevel == 3) {
|
||
$('.page1 .boxs1').addClass('boxOpen1');
|
||
$('.page1 .boxs2').addClass('boxOpen2');
|
||
$('.page1 .boxs3').addClass('boxOpen3');
|
||
$('.page1 .road .boxImg').attr('src', './images/box3.png');
|
||
}
|
||
// 特效移动
|
||
$('.page1 .road .gui').css({
|
||
left: leftArr[mapPos],
|
||
bottom: bottArr[mapPos],
|
||
})
|
||
// 判断当前位置是否处于宝箱点位
|
||
if (mapPos == 4 || mapPos == 8 || mapPos == 13 || mapPos == 18 || mapPos == 22 || mapPos == 26 || mapPos == 30) {
|
||
$(`.page1 .road .boxImgs${mapPos}`).attr('src', `./images/boxOpen${poolType}.png`)
|
||
} else {
|
||
$(`.page1 .road .boxImg`).attr('src', `./images/box${poolType}.png`);
|
||
}
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 任务配置接口
|
||
function getTaskConfig () {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/act/2023Halloween/task/getConfig',
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
// 处理每日任务
|
||
res.data.dailyTaskList.forEach((res, i) => {
|
||
$(`.page2 .task${i + 1} .but`).attr('click', res.status);
|
||
$(`.page2 .task${i + 1} .but`).text(res.status == 0 ? '去完成' : '已完成');
|
||
res.status == 1 ? $(`.page2 .task${i + 1} .but`).addClass('butActive') : $(`.page2 .task${i + 1} .but`).removeClass('butActive');
|
||
if (i == 0) {
|
||
$('.page2 .task1 p').text(`登录活动页(${res.cur}/${res.need})`);
|
||
}
|
||
if (i == 1) {
|
||
$('.page2 .task2 .line').css('width', `${(res.cur / res.need * 100) >= 100 ? 100 : (res.cur / res.need * 100)}%`);
|
||
$('.page2 .task2 .line').text(`${res.cur}/${res.need}`);
|
||
}
|
||
});
|
||
// 处理循环任务
|
||
res.data.loopTaskList.forEach((res, i) => {
|
||
$(`.page2 .task${i + 3} b i`).text(`${res.loop}张`);
|
||
$(`.page2 .task${i + 3} .but`).attr('click', res.status);
|
||
$(`.page2 .task${i + 3} .but`).text(res.status == 0 ? '去完成' : '已完成');
|
||
res.status == 1 ? $(`.page2 .task${i + 3} .but`).addClass(`butActive`) : $(`.page2 .task${i + 3} .but`).removeClass(`butActive`);
|
||
})
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 任务按钮2
|
||
$('.page2 .task2 .but').click(function () {
|
||
var bool = $(this).attr('click') == 0 ? false : true;
|
||
console.log(bool);
|
||
if (bool) {
|
||
return
|
||
}
|
||
if (browser.ios) {
|
||
window.webkit.messageHandlers.openRoom.postMessage(roomUid);
|
||
} else if (browser.android) {
|
||
if (androidJsObj && typeof androidJsObj === 'object') {
|
||
window.androidJsObj.openRoom(roomUid);
|
||
}
|
||
}
|
||
})
|
||
// 任务按钮3
|
||
$('.page2 .task3 .but').click(function () {
|
||
var bool = $(this).attr('click') == 0 ? false : true;
|
||
console.log(bool);
|
||
if (bool) {
|
||
return
|
||
}
|
||
if (browser.ios) {
|
||
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: 0 }))
|
||
} else if (browser.android) {
|
||
if (androidJsObj && typeof androidJsObj === 'object') {
|
||
window.androidJsObj.openRoomForGiftId(roomUid, 0);
|
||
}
|
||
}
|
||
})
|
||
// 任务按钮4
|
||
$('.page2 .task4 .but').click(function () {
|
||
var bool = $(this).attr('click') == 0 ? false : true;
|
||
console.log(bool);
|
||
if (bool) {
|
||
return
|
||
}
|
||
if (browser.ios) {
|
||
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: 0 }))
|
||
} else if (browser.android) {
|
||
if (androidJsObj && typeof androidJsObj === 'object') {
|
||
window.androidJsObj.openRoomForGiftId(roomUid, 0);
|
||
}
|
||
}
|
||
})
|
||
// 点击宝箱按钮
|
||
$('.page1 .boxs').click(function () {
|
||
var i = $(this).index() - 6;
|
||
if (i == 1) {
|
||
$('.box_pub .box_pub_in .p1').text('活动期间送出万圣福袋*1');
|
||
$('.box_pub .box_pub_in .p3').text('活动期间收到万圣福袋*5');
|
||
} else if (i == 2) {
|
||
$('.box_pub .box_pub_in .p1').text('活动期间送出万圣福袋*10');
|
||
$('.box_pub .box_pub_in .p3').text('活动期间收到万圣福袋*20');
|
||
} else {
|
||
$('.box_pub .box_pub_in .p1').text('活动期间送出万圣福袋*20');
|
||
$('.box_pub .box_pub_in .p3').text('活动期间收到万圣福袋*30');
|
||
}
|
||
$('.box_pub .box_pub_in .box_pub_ul li').removeClass('li1').removeClass('li2').removeClass('li3');
|
||
$('.box_pub .box_pub_in .box_pub_ul li').addClass(`li${i}`);
|
||
$('.box_pub .box_pub_in .box_pub_Title').attr('src', `./images/box_pub_Title${i}.png`)
|
||
$('.box_pub').show();
|
||
bodyScroolFun(true);
|
||
})
|
||
// 去完成宝箱解锁任务按钮
|
||
$('.page1 .mc .mc_in .but').click(function () {
|
||
if (browser.ios) {
|
||
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: 0 }))
|
||
} else if (browser.android) {
|
||
if (androidJsObj && typeof androidJsObj === 'object') {
|
||
window.androidJsObj.openRoomForGiftId(roomUid, 0);
|
||
}
|
||
}
|
||
})
|
||
// tab切换
|
||
$('.tab div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
$('.page1,.page2,.page3').hide();
|
||
if (i == 1) {
|
||
$('.page1').show();
|
||
getConfig();
|
||
} else {
|
||
getRank(rankType, data);
|
||
$('.page3').show();
|
||
}
|
||
})
|
||
// 地图任务tab切换
|
||
$('.switch div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
$('.page1,.page2,.page3').hide();
|
||
if (i == 1) {
|
||
$('.page1').show();
|
||
getConfig();
|
||
} else {
|
||
$('.page2').show();
|
||
getConfig();
|
||
getTaskConfig();
|
||
}
|
||
})
|
||
// 尖叫惊喜榜单切换
|
||
$('.page3 .listTab div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
$('.page3 .listTitle').attr('src', `./images/listTitle${i}.png`);
|
||
$('.listRule .listRule_in .listRuletitle').attr('src', `./images/listRuletitle${i}.png`);
|
||
$('.listRule .listRule_in .box img').attr('src', `./images/listRuleText${i}.png`);
|
||
$(this).addClass('active').siblings().removeClass('active');
|
||
if (i == 1) {
|
||
type = 'a';
|
||
rankType = type2 == "a" ? 1 : 2;
|
||
} else {
|
||
type = 'b';
|
||
rankType = type2 == "a" ? 3 : 4;
|
||
}
|
||
getRank(rankType, data);
|
||
})
|
||
// 日榜总榜切换
|
||
$('.page3 .dayTab div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
$(this).addClass('active').siblings().removeClass('active');
|
||
if (i == 1) {
|
||
type2 = 'a';
|
||
rankType = type == "a" ? 1 : 3;
|
||
$('.page3 .time').show();
|
||
} else {
|
||
type2 = 'b';
|
||
rankType = type == "a" ? 2 : 4;
|
||
$('.page3 .time').hide();
|
||
}
|
||
getRank(rankType, data);
|
||
})
|
||
// 日榜切换日期
|
||
$('.page3 .time div').click(function () {
|
||
var datas = $(this).attr('data');
|
||
$(this).addClass('active').siblings().removeClass('active');
|
||
rankType = type == "a" ? 1 : 3;//排行榜类型(1=甜蜜日榜,2=甜蜜总榜,3=爱意日榜,4=爱意总榜)
|
||
data = datas;
|
||
getRank(rankType, data);
|
||
})
|
||
// 榜单接口
|
||
function getRank (rankType, date) {//排行榜类型rankType(1=送礼日榜,2=送礼总榜,3=收礼日榜,4=收礼总榜)
|
||
$('.page3 .lists li').remove();
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/act/2023Halloween/rank/getRank',
|
||
data: { rankType, date },
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
// 设置当天日期
|
||
curDate = res.data.curDate;
|
||
// 处理日期
|
||
if (res.data.dateList) {
|
||
res.data.dateList.forEach((res, i) => {
|
||
$('.page3 .time div').eq(i).text(`${res[5]}${res[6]}.${res[8]}${res[9]}`);
|
||
$('.page3 .time div').eq(i).attr('data', res);
|
||
if (res == curDate && date == null) {
|
||
$('.page3 .time div').removeClass('active')
|
||
$('.page3 .time div').eq(i).addClass('active');
|
||
}
|
||
})
|
||
}
|
||
// 处理自己榜单
|
||
$('.page3 .my .li .tx').attr('src', res.data.meRank.avatar);
|
||
$('.page3 .my .li .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
|
||
$('.page3 .my .li .nick').text(res.data.meRank.nick);
|
||
$('.page3 .my .li .score').text(`${rankType == 1 || rankType == 2 ? "尖叫值:" : "惊喜值:"}${unitProcessing(res.data.meRank.score, 10000, 1, 'w')}`);
|
||
// 处理前三
|
||
var top3 = res.data.rankList.slice(0, 3);
|
||
var notTop3 = res.data.rankList.slice(3);
|
||
if (top3.length < 3) {
|
||
let arr = new Array(3 - top3.length).fill({
|
||
avatar: './images/logo.png',
|
||
nick: '虚位以待',
|
||
score: "0"
|
||
})
|
||
top3.push(...arr)
|
||
}
|
||
top3.forEach((res, index) => {
|
||
$(`.page3 .topBox .no${index + 1} .tx`).attr('src', res.avatar);
|
||
$(`.page3 .topBox .no${index + 1} p`).text(res.nick);
|
||
$(`.page3 .topBox .no${index + 1} b`).text(`${rankType == 1 || rankType == 2 ? "尖叫值:" : "惊喜值:"}${unitProcessing(res.score, 10000, 1, 'w')}`);
|
||
})
|
||
// 非前三
|
||
var str = '';
|
||
notTop3.forEach((res, i) => {
|
||
str += `
|
||
<li>
|
||
<div class="num">${res.ranking}</div>
|
||
<img src="${res.avatar}" alt="" class="tx">
|
||
<div class="nick">${res.nick}</div>
|
||
<div class="score">${rankType == 1 || rankType == 2 ? "尖叫值:" : "惊喜值:"}${unitProcessing(res.score, 10000, 1, 'w')}</div>
|
||
</li>
|
||
`
|
||
})
|
||
$('.page3 .lists').append(str);
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 打开活动规则
|
||
$('.header .rule_icon').click(function () {
|
||
$('.rule').show();
|
||
bodyScroolFun(true);
|
||
})
|
||
// 关闭活动规则
|
||
$('.rule').click(function () {
|
||
$('.rule').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 打开榜单规则
|
||
$('.page3 .rule_icon').click(function () {
|
||
$('.listRule').show();
|
||
bodyScroolFun(true);
|
||
})
|
||
// 关闭榜单规则
|
||
$('.listRule').click(function () {
|
||
$('.listRule').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 关闭初中高宝箱弹窗
|
||
$('.box_pub').click(function () {
|
||
$('.box_pub').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 关闭恭喜获得弹窗
|
||
$('.gx .gx_in .but').click(function () {
|
||
drawLock = true;
|
||
$('.gx').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 关闭糟糕弹窗
|
||
$('.zg').click(function () {
|
||
drawLock = true;
|
||
$('.zg').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 关闭宝箱记录弹窗
|
||
$('.record_box').click(function () {
|
||
$('.record_box').hide();
|
||
bodyScroolFun(false);
|
||
})
|
||
// 打开宝箱记录
|
||
$('.page1 .diceBox .diceLeftBut').click(function () {
|
||
page = 1;
|
||
$('.record_box .record_box_in ul li').remove();
|
||
pageRecord(page);
|
||
})
|
||
// 获取房间Uid接口
|
||
function pageRecord (page) {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/act/2023Halloween/draw/pageRecord',
|
||
data: { page, size: 20 },
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
if (res.data.length == 0) {
|
||
drawPageSizeLack = false;
|
||
hideLoading(layerIndex)
|
||
$('.record_box').show();
|
||
return;
|
||
}
|
||
var str = '';
|
||
res.data.forEach((res, i) => {
|
||
str += `
|
||
<li>
|
||
<div class="left">
|
||
<p>${dateFormat(res.createTime, 'yyyy/MM/dd')}</p>
|
||
<b>${dateFormat(res.createTime, 'hh:mm:ss')}</b>
|
||
</div>
|
||
<div class="right">${res.rewardDesc}</div>
|
||
</li>
|
||
`
|
||
})
|
||
$('.record_box .record_box_in ul ').append(str);
|
||
drawPageSizeLack = true;
|
||
$('.record_box').show();
|
||
bodyScroolFun(true);
|
||
} else {
|
||
drawPageSizeLack = true;
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
drawPageSizeLack = true;
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
//检测抽奖记录是否到达底部
|
||
$(".duihuanBg .dividerecordsBg_in .ul").scroll(function () {
|
||
var divHeight = $(this).height();
|
||
var nScrollHeight = $(this)[0].scrollHeight;
|
||
var nScrollTop = $(this)[0].scrollTop;
|
||
if (nScrollTop + divHeight + 50 >= nScrollHeight) {
|
||
console.log("到达底部了");
|
||
if (drawPageSizeLack) {
|
||
drawPageSizeLack = false;
|
||
page++;
|
||
pageRecord(page);
|
||
}
|
||
}
|
||
});
|
||
// 骰子动画定义
|
||
let player = new SVGA.Player('.diceSvga');
|
||
let parser = new SVGA.Parser('.diceSvga');
|
||
parser.load(`./images/sz.svga`, function (videoItem) {
|
||
player.loops = 1;
|
||
player.clearsAfterStop = false;
|
||
player.setVideoItem(videoItem);
|
||
player.startAnimation();
|
||
player.setContentMode('AspectFill');
|
||
})
|
||
// 骰子动画函数
|
||
function diceSvga () {
|
||
$('.page1 .diceBox .diceSvga').show();
|
||
$('.page1 .diceBox .dice').hide();
|
||
parser.load(`./images/sz.svga`, function (videoItem) {
|
||
player.loops = 1;
|
||
player.clearsAfterStop = false;
|
||
player.setVideoItem(videoItem);
|
||
player.startAnimation();
|
||
player.setContentMode('AspectFill');
|
||
player.onFinished(() => {
|
||
$('.page1 .diceBox .dice').show();
|
||
$('.page1 .diceBox .diceSvga').hide();
|
||
})
|
||
})
|
||
}
|
||
// 摇骰子按钮
|
||
$('.page1 .diceBox .dice').click(function () {
|
||
if (drawLock) {
|
||
if (candyNum < 1) {
|
||
toastMsg('糖果券不足')
|
||
return
|
||
}
|
||
draw(poolType, 1);
|
||
}
|
||
})
|
||
// 全部投入
|
||
$('.page1 .diceBox .diceRightBut').click(function () {
|
||
if (drawLock) {
|
||
if (candyNum < 1) {
|
||
toastMsg('糖果券不足')
|
||
return
|
||
}
|
||
draw(poolType, null);
|
||
}
|
||
})
|
||
// 活动结束按钮
|
||
$('.endActivity .endActivity_in .but').click(function () {
|
||
$('.endActivity').hide();
|
||
bodyScroolFun(false);
|
||
$('.page1,.page2,.page3').hide();
|
||
getRank(rankType, data);
|
||
$('.page3').show();
|
||
})
|
||
// 宝箱开奖动画定义
|
||
let boxBig1 = new SVGA.Player('.boxImgSvga_in1');
|
||
let boxBigParser1 = new SVGA.Parser('.boxImgSvga_in1');
|
||
boxBigParser1.load(`./images/boxBig1.svga`, function (videoItem) {
|
||
boxBig1.loops = 1;
|
||
boxBig1.clearsAfterStop = false;
|
||
boxBig1.setVideoItem(videoItem);
|
||
boxBig1.startAnimation();
|
||
boxBig1.setContentMode('AspectFill');
|
||
})
|
||
// 宝箱开奖动画函数
|
||
function boxBigSvga1 () {
|
||
$('.boxImgSvgaA').show();
|
||
boxBigParser1.load(`./images/boxBig1.svga`, function (videoItem) {
|
||
boxBig1.loops = 1;
|
||
boxBig1.clearsAfterStop = false;
|
||
boxBig1.setVideoItem(videoItem);
|
||
boxBig1.startAnimation();
|
||
boxBig1.setContentMode('AspectFill');
|
||
boxBig1.onFinished(() => {
|
||
$('.boxImgSvgaA').hide();
|
||
$('.gx').show();
|
||
})
|
||
})
|
||
}
|
||
// 宝箱开奖动画定义
|
||
let boxBig2 = new SVGA.Player('.boxImgSvga_in2');
|
||
let boxBigParser2 = new SVGA.Parser('.boxImgSvga_in2');
|
||
boxBigParser2.load(`./images/boxBig2.svga`, function (videoItem) {
|
||
boxBig2.loops = 1;
|
||
boxBig2.clearsAfterStop = false;
|
||
boxBig2.setVideoItem(videoItem);
|
||
boxBig2.startAnimation();
|
||
boxBig2.setContentMode('AspectFill');
|
||
})
|
||
// 宝箱开奖动画函数
|
||
function boxBigSvga2 () {
|
||
$('.boxImgSvgaB').show();
|
||
boxBigParser2.load(`./images/boxBig2.svga`, function (videoItem) {
|
||
boxBig2.loops = 1;
|
||
boxBig2.clearsAfterStop = false;
|
||
boxBig2.setVideoItem(videoItem);
|
||
boxBig2.startAnimation();
|
||
boxBig2.setContentMode('AspectFill');
|
||
boxBig2.onFinished(() => {
|
||
$('.boxImgSvgaB').hide();
|
||
$('.gx').show();
|
||
})
|
||
})
|
||
}
|
||
// 宝箱开奖动画定义
|
||
let boxBig3 = new SVGA.Player('.boxImgSvga_in3');
|
||
let boxBigParser3 = new SVGA.Parser('.boxImgSvga_in3');
|
||
boxBigParser2.load(`./images/boxBig3.svga`, function (videoItem) {
|
||
boxBig3.loops = 1;
|
||
boxBig3.clearsAfterStop = false;
|
||
boxBig3.setVideoItem(videoItem);
|
||
boxBig3.startAnimation();
|
||
boxBig3.setContentMode('AspectFill');
|
||
})
|
||
// 宝箱开奖动画函数
|
||
function boxBigSvga3 () {
|
||
$('.boxImgSvgaC').show();
|
||
boxBigParser2.load(`./images/boxBig3.svga`, function (videoItem) {
|
||
boxBig3.loops = 1;
|
||
boxBig3.clearsAfterStop = false;
|
||
boxBig3.setVideoItem(videoItem);
|
||
boxBig3.startAnimation();
|
||
boxBig3.setContentMode('AspectFill');
|
||
boxBig3.onFinished(() => {
|
||
$('.boxImgSvgaC').hide();
|
||
$('.gx').show();
|
||
})
|
||
})
|
||
}
|
||
// 抽奖接口
|
||
function draw (poolType, num) {
|
||
drawLock = false;
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GEt',
|
||
url: urlPrefix + '/act/2023Halloween/draw/draw',
|
||
data: { poolType, num },
|
||
success (res) {
|
||
if (res.code === 200) {
|
||
// 判断是否全部投入或单次投入
|
||
if (num != null) {
|
||
diceSvga();
|
||
setTimeout(function () {
|
||
res.data.step.forEach((res, index) => {
|
||
console.log(res);
|
||
setTimeout(function () {
|
||
$('.page1 .road .gui').css({
|
||
left: leftArr[res],
|
||
bottom: bottArr[res],
|
||
})
|
||
}, (index + 1) * 300)
|
||
});
|
||
drawOut(res, res.data.step.length + 1, poolType);
|
||
}, 1600);
|
||
} else {
|
||
drawOut(res, 0, poolType);
|
||
}
|
||
// 设置步数
|
||
$('.page1 .diceBox .dice').attr('src', `./images/dice${res.data.step.length}.png`);
|
||
} else if (res.code == 4000) {
|
||
toastMsg(res.message);
|
||
getConfig();
|
||
drawLock = true;
|
||
} else {
|
||
drawLock = true;
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error (err) {
|
||
drawLock = true;
|
||
hideLoading(layerIndex)
|
||
toastMsg('网络错误,请退出重进')
|
||
}
|
||
})
|
||
}
|
||
// 中奖或未中奖渲染
|
||
function drawOut (res, time, poolType) {
|
||
//判断是否中奖
|
||
if (res.data.hasReward) {
|
||
// 渲染中奖列表<p>xxx头饰*1天</p>
|
||
var str = '';
|
||
$('.gx .gx_in .gxBox li').remove();
|
||
res.data.rewardList.forEach((res, i) => {
|
||
// 1头饰;2铭牌;3气泡;4座驾;5礼物;
|
||
str += `
|
||
<li>
|
||
<img src="${res.pic}" alt="" class="gift ${res.type == 1 ? 'ts' : res.type == 2 ? 'mp' : res.type == 3 ? 'qp' : res.type == 4 ? 'zj' : 'lw'}">
|
||
<p>${res.desc}</p>
|
||
</li>
|
||
`
|
||
})
|
||
$('.gx .gx_in .gxBox').append(str);
|
||
setTimeout(function () {
|
||
poolType == 1 ? boxBigSvga1() : poolType == 2 ? boxBigSvga2() : boxBigSvga3();
|
||
$(`.page1 .road .boxImgs${res.data.step[res.data.step.length - 1]}`).attr('src', `./images/boxOpen${poolType}.png`);
|
||
getConfig();
|
||
// drawLock = true;
|
||
}, time * 300)
|
||
} else {
|
||
setTimeout(function () {
|
||
$('.zg').show();
|
||
// drawLock = true;
|
||
getConfig();
|
||
}, time * 300)
|
||
}
|
||
bodyScroolFun(true);
|
||
}
|
||
//返回页面 重新请求接口
|
||
var hiddenProperty = 'hidden' in document ? 'hidden' :
|
||
'webkitHidden' in document ? 'webkitHidden' :
|
||
'mozHidden' in document ? 'mozHidden' : null;
|
||
|
||
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
|
||
var onVisibilityChange = function () {
|
||
if (!document[hiddenProperty]) {
|
||
getConfig();
|
||
getTaskConfig();
|
||
}
|
||
}
|
||
document.addEventListener(visibilityChangeEvent, onVisibilityChange); |