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 += `
${dateFormat(res.createTime, 'yyyy/MM/dd')}
${dateFormat(res.createTime, 'hh:mm:ss')}xxx頭飾*1天
var str = ''; $('.gx .gx_in .gxBox li').remove(); res.data.rewardList.forEach((res, i) => { // 1頭飾;2銘牌;3氣泡;4座駕;5禮物; str += `${res.desc}