738 lines
26 KiB
JavaScript
738 lines
26 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
let env = EnvCheck();
|
||
if (env == 'test') {
|
||
new VConsole();
|
||
}
|
||
var formalUrl = 'https://api.hfighting.com'; // 正式环境
|
||
var testUrls = 'http://beta.api.pekolive.com'; // 测试环境
|
||
// 封裝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);
|
||
// }
|
||
// }
|
||
if (env == 'test') {
|
||
window.location.href = `${testUrls}/peko/activity/act-ocean/index.html`
|
||
} else {
|
||
window.location.href = `${formalUrl}/peko/activity/act-ocean/index.html`
|
||
}
|
||
|
||
})
|
||
// 任務按鈕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); |