Files
peko-h5/view/peko/activity/2023-halloween/js/index.js

738 lines
26 KiB
JavaScript
Raw Normal View History

2023-10-24 10:43:30 +08:00
let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let env = EnvCheck();
if (env == 'test') {
new VConsole();
}
2023-10-24 12:02:46 +08:00
var formalUrl = 'https://api.hfighting.com'; // 正式环境
var testUrls = 'http://beta.api.pekolive.com'; // 测试环境
// 封裝layer消息提醒框
2023-10-24 10:43:30 +08:00
let layerIndex
2023-10-24 12:02:46 +08:00
const showLoading = (content = '加載中...') => {
2023-10-24 10:43:30 +08:00
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'];
2023-10-24 12:02:46 +08:00
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;//抽獎的鎖
2023-10-24 10:43:30 +08:00
var candyNum = 0;//糖果卷
2023-10-24 12:02:46 +08:00
// 初始化函數
2023-10-24 10:43:30 +08:00
$(function () {
getInfoFromClient()
setTimeout(function () {
2023-10-24 12:02:46 +08:00
// 頁面全屏
2023-10-24 10:43:30 +08:00
if (browser.app) {
if (browser.android) {
window.androidJsObj.initShowNav(false)
} else {
window.webkit.messageHandlers.initShowNav.postMessage(0)
}
};
2023-10-24 12:02:46 +08:00
// 頂部返回事件
2023-10-24 10:43:30 +08:00
$('.back').click(() => {
if (browser.android) {
window.androidJsObj.closeWebView()
} else {
window.webkit.messageHandlers.closeWebView.postMessage(null)
}
})
2023-10-24 12:02:46 +08:00
// 禮物輪播
2023-10-24 10:43:30 +08:00
var mySwiper = new Swiper('.swiper', {
// direction: "vertical",
loop: true,
autoplay: {
delay: 3500,//
disableOnInteraction: false
}
})
getTaskConfig();
getRecommendRoom();
getConfig();
}, 100)
})
2023-10-24 12:02:46 +08:00
// 獲取房間Uid接口
2023-10-24 10:43:30 +08:00
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)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
// 抽獎配置接口
2023-10-24 10:43:30 +08:00
function getConfig () {
// showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023Halloween/draw/getConfig',
success (res) {
if (res.code === 200) {
2023-10-24 12:02:46 +08:00
// 處理糖果數量
2023-10-24 10:43:30 +08:00
$('.myCandy').text('我的糖果券:' + res.data.candyNum);
candyNum = res.data.candyNum;
2023-10-24 12:02:46 +08:00
// 當前格子下標
2023-10-24 10:43:30 +08:00
mapPos = res.data.mapPos;
$('.page1 .road .gui').css({
left: leftArr[res.data.mapPos],
bottom: bottArr[res.data.mapPos],
})
2023-10-24 12:02:46 +08:00
// 判斷活動結束時間
2023-10-24 10:43:30 +08:00
if (res.timestamp > res.data.endTime) {
isEndTime = true;
$('.endActivity').show();
}
2023-10-24 12:02:46 +08:00
// 判斷等級處理
2023-10-24 10:43:30 +08:00
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');
}
2023-10-24 12:02:46 +08:00
// 特效移動
2023-10-24 10:43:30 +08:00
$('.page1 .road .gui').css({
left: leftArr[mapPos],
bottom: bottArr[mapPos],
})
2023-10-24 12:02:46 +08:00
// 判斷當前位置是否處於寶箱點位
2023-10-24 10:43:30 +08:00
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)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
// 任務配置接口
2023-10-24 10:43:30 +08:00
function getTaskConfig () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023Halloween/task/getConfig',
success (res) {
if (res.code === 200) {
2023-10-24 12:02:46 +08:00
// 處理每日任務
2023-10-24 10:43:30 +08:00
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) {
2023-10-24 12:02:46 +08:00
$('.page2 .task1 p').text(`登錄活動頁(${res.cur}/${res.need})`);
2023-10-24 10:43:30 +08:00
}
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}`);
}
});
2023-10-24 12:02:46 +08:00
// 處理循環任務
2023-10-24 10:43:30 +08:00
res.data.loopTaskList.forEach((res, i) => {
2023-10-24 12:02:46 +08:00
$(`.page2 .task${i + 3} b i`).text(`${res.loop}`);
2023-10-24 10:43:30 +08:00
$(`.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)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
// 任務按鈕2
2023-10-24 10:43:30 +08:00
$('.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);
}
}
})
2023-10-24 12:02:46 +08:00
// 任務按鈕3
2023-10-24 10:43:30 +08:00
$('.page2 .task3 .but').click(function () {
var bool = $(this).attr('click') == 0 ? false : true;
console.log(bool);
if (bool) {
return
}
2023-10-24 12:02:46 +08:00
// 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);
// }
// }
if (env == 'test') {
window.location.href = `${testUrls}/peko/activity/act-ocean/index.html`
} else {
window.location.href = `${formalUrl}/peko/activity/act-ocean/index.html`
2023-10-24 10:43:30 +08:00
}
2023-10-24 12:02:46 +08:00
2023-10-24 10:43:30 +08:00
})
2023-10-24 12:02:46 +08:00
// 任務按鈕4
2023-10-24 10:43:30 +08:00
$('.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);
}
}
})
2023-10-24 12:02:46 +08:00
// 點擊寶箱按鈕
2023-10-24 10:43:30 +08:00
$('.page1 .boxs').click(function () {
var i = $(this).index() - 6;
if (i == 1) {
2023-10-24 12:02:46 +08:00
$('.box_pub .box_pub_in .p1').text('活動期間送出萬聖福袋*1');
$('.box_pub .box_pub_in .p3').text('活動期間收到萬聖福袋*5');
2023-10-24 10:43:30 +08:00
} else if (i == 2) {
2023-10-24 12:02:46 +08:00
$('.box_pub .box_pub_in .p1').text('活動期間送出萬聖福袋*10');
$('.box_pub .box_pub_in .p3').text('活動期間收到萬聖福袋*20');
2023-10-24 10:43:30 +08:00
} else {
2023-10-24 12:02:46 +08:00
$('.box_pub .box_pub_in .p1').text('活動期間送出萬聖福袋*20');
$('.box_pub .box_pub_in .p3').text('活動期間收到萬聖福袋*30');
2023-10-24 10:43:30 +08:00
}
$('.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);
})
2023-10-24 12:02:46 +08:00
// 去完成寶箱解鎖任務按鈕
2023-10-24 10:43:30 +08:00
$('.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);
}
}
})
2023-10-24 12:02:46 +08:00
// tab切換
2023-10-24 10:43:30 +08:00
$('.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();
}
})
2023-10-24 12:02:46 +08:00
// 地圖任務tab切換
2023-10-24 10:43:30 +08:00
$('.switch div').click(function () {
var i = $(this).index() + 1;
$('.page1,.page2,.page3').hide();
if (i == 1) {
$('.page1').show();
getConfig();
} else {
$('.page2').show();
getConfig();
getTaskConfig();
}
})
2023-10-24 12:02:46 +08:00
// 尖叫驚喜榜單切換
2023-10-24 10:43:30 +08:00
$('.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);
})
2023-10-24 12:02:46 +08:00
// 日榜總榜切換
2023-10-24 10:43:30 +08:00
$('.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);
})
2023-10-24 12:02:46 +08:00
// 日榜切換日期
2023-10-24 10:43:30 +08:00
$('.page3 .time div').click(function () {
var datas = $(this).attr('data');
$(this).addClass('active').siblings().removeClass('active');
2023-10-24 12:02:46 +08:00
rankType = type == "a" ? 1 : 3;//排行榜類型1=甜蜜日榜2=甜蜜總榜3=愛意日榜4=愛意總榜)
2023-10-24 10:43:30 +08:00
data = datas;
getRank(rankType, data);
})
2023-10-24 12:02:46 +08:00
// 榜單接口
function getRank (rankType, date) {//排行榜類型rankType1=送禮日榜2=送禮總榜3=收禮日榜4=收禮總榜)
2023-10-24 10:43:30 +08:00
$('.page3 .lists li').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023Halloween/rank/getRank',
data: { rankType, date },
success (res) {
if (res.code === 200) {
2023-10-24 12:02:46 +08:00
// 設置當天日期
2023-10-24 10:43:30 +08:00
curDate = res.data.curDate;
2023-10-24 12:02:46 +08:00
// 處理日期
2023-10-24 10:43:30 +08:00
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');
}
})
}
2023-10-24 12:02:46 +08:00
// 處理自己榜單
2023-10-24 10:43:30 +08:00
$('.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);
2023-10-24 12:02:46 +08:00
$('.page3 .my .li .score').text(`${rankType == 1 || rankType == 2 ? "尖叫值:" : "驚喜值:"}${unitProcessing(res.data.meRank.score, 10000, 1, 'w')}`);
// 處理前三
2023-10-24 10:43:30 +08:00
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',
2023-10-24 12:02:46 +08:00
nick: '虛位以待',
2023-10-24 10:43:30 +08:00
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);
2023-10-24 12:02:46 +08:00
$(`.page3 .topBox .no${index + 1} b`).text(`${rankType == 1 || rankType == 2 ? "尖叫值:" : "驚喜值:"}${unitProcessing(res.score, 10000, 1, 'w')}`);
2023-10-24 10:43:30 +08:00
})
// 非前三
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>
2023-10-24 12:02:46 +08:00
<div class="score">${rankType == 1 || rankType == 2 ? "尖叫值:" : "驚喜值:"}${unitProcessing(res.score, 10000, 1, 'w')}</div>
2023-10-24 10:43:30 +08:00
</li>
`
})
$('.page3 .lists').append(str);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
// 打開活動規則
2023-10-24 10:43:30 +08:00
$('.header .rule_icon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
2023-10-24 12:02:46 +08:00
// 關閉活動規則
2023-10-24 10:43:30 +08:00
$('.rule').click(function () {
$('.rule').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 打開榜單規則
2023-10-24 10:43:30 +08:00
$('.page3 .rule_icon').click(function () {
$('.listRule').show();
bodyScroolFun(true);
})
2023-10-24 12:02:46 +08:00
// 關閉榜單規則
2023-10-24 10:43:30 +08:00
$('.listRule').click(function () {
$('.listRule').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 關閉初中高寶箱彈窗
2023-10-24 10:43:30 +08:00
$('.box_pub').click(function () {
$('.box_pub').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 關閉恭喜獲得彈窗
2023-10-24 10:43:30 +08:00
$('.gx .gx_in .but').click(function () {
drawLock = true;
$('.gx').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 關閉糟糕彈窗
2023-10-24 10:43:30 +08:00
$('.zg').click(function () {
drawLock = true;
$('.zg').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 關閉寶箱記錄彈窗
2023-10-24 10:43:30 +08:00
$('.record_box').click(function () {
$('.record_box').hide();
bodyScroolFun(false);
})
2023-10-24 12:02:46 +08:00
// 打開寶箱記錄
2023-10-24 10:43:30 +08:00
$('.page1 .diceBox .diceLeftBut').click(function () {
page = 1;
$('.record_box .record_box_in ul li').remove();
pageRecord(page);
})
2023-10-24 12:02:46 +08:00
// 獲取房間Uid接口
2023-10-24 10:43:30 +08:00
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)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
//檢測抽獎記錄是否到達底部
2023-10-24 10:43:30 +08:00
$(".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) {
2023-10-24 12:02:46 +08:00
console.log("到達底部了");
2023-10-24 10:43:30 +08:00
if (drawPageSizeLack) {
drawPageSizeLack = false;
page++;
pageRecord(page);
}
}
});
2023-10-24 12:02:46 +08:00
// 骰子動畫定義
2023-10-24 10:43:30 +08:00
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');
})
2023-10-24 12:02:46 +08:00
// 骰子動畫函數
2023-10-24 10:43:30 +08:00
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();
})
})
}
2023-10-24 12:02:46 +08:00
// 搖骰子按鈕
2023-10-24 10:43:30 +08:00
$('.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);
}
})
2023-10-24 12:02:46 +08:00
// 活動結束按鈕
2023-10-24 10:43:30 +08:00
$('.endActivity .endActivity_in .but').click(function () {
$('.endActivity').hide();
bodyScroolFun(false);
$('.page1,.page2,.page3').hide();
getRank(rankType, data);
$('.page3').show();
})
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫定義
2023-10-24 10:43:30 +08:00
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');
})
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫函數
2023-10-24 10:43:30 +08:00
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();
})
})
}
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫定義
2023-10-24 10:43:30 +08:00
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');
})
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫函數
2023-10-24 10:43:30 +08:00
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();
})
})
}
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫定義
2023-10-24 10:43:30 +08:00
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');
})
2023-10-24 12:02:46 +08:00
// 寶箱開獎動畫函數
2023-10-24 10:43:30 +08:00
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();
})
})
}
2023-10-24 12:02:46 +08:00
// 抽獎接口
2023-10-24 10:43:30 +08:00
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) {
2023-10-24 12:02:46 +08:00
// 判斷是否全部投入或單次投入
2023-10-24 10:43:30 +08:00
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);
}
2023-10-24 12:02:46 +08:00
// 設置步數
2023-10-24 10:43:30 +08:00
$('.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)
2023-10-24 12:02:46 +08:00
toastMsg('網絡錯誤,請退出重進')
2023-10-24 10:43:30 +08:00
}
})
}
2023-10-24 12:02:46 +08:00
// 中獎或未中獎渲染
2023-10-24 10:43:30 +08:00
function drawOut (res, time, poolType) {
2023-10-24 12:02:46 +08:00
//判斷是否中獎
2023-10-24 10:43:30 +08:00
if (res.data.hasReward) {
2023-10-24 12:02:46 +08:00
// 渲染中獎列錶<p>xxx頭飾*1天</p>
2023-10-24 10:43:30 +08:00
var str = '';
$('.gx .gx_in .gxBox li').remove();
res.data.rewardList.forEach((res, i) => {
2023-10-24 12:02:46 +08:00
// 1頭飾2銘牌3氣泡4座駕5禮物
2023-10-24 10:43:30 +08:00
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);
}
2023-10-24 12:02:46 +08:00
//返回頁面 重新請求接口
2023-10-24 10:43:30 +08:00
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);