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 rankType = 2; // 初始化函數 $(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) } }) }, 100) }) // 接口 function getRank () { showLoading() networkRequest({ type: 'get', url: urlPrefix + '/act/special/gift/getRank', data: { rankType: rankType, page: 1, pageSize: 30 }, success (res) { if (res.code === 200) { // 處理前三 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) => { $(`.page2 .box .topBox .top${index + 1} .tx`).attr('src', res.avatar); $(`.page2 .box .topBox .top${index + 1} .name`).text(res.nick); $(`.page2 .box .topBox .top${index + 1} .score`).text(`${rankType == 2 ? "財氣值:" : "福氣值:"}${unitProcessing(res.score, 10000, 1, 'w')}`); }) // 處理非前三 var str = ''; $('.page2 .box ul li').remove(); notTop3.forEach((res, i) => { str += `
  • ${res.ranking}
    ${res.nick}
    ${rankType == 2 ? "財氣值:" : "福氣值:"}${unitProcessing(res.score, 10000, 1, 'w')}
  • ` }) $('.page2 .box ul').append(str); // 處理自己 $('.page2 .box .my .tx').attr('src', res.data.meRank.avatar); $('.page2 .box .my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking); $('.page2 .box .my .name').text(res.data.meRank.nick); $('.page2 .box .my .score').text(`${rankType == 2 ? "財氣值:" : "福氣值:"}${unitProcessing(res.data.meRank.score, 10000, 1, 'w')}`); } else { toastMsg(res.message) } hideLoading(layerIndex) }, error (err) { hideLoading(layerIndex) toastMsg('網路錯誤,請退出重進') } }) } // tab切換 $('.tab div').click(function () { var i = $(this).index() + 1; $('.page1,.page2').hide(); $(`.page${i}`).show(); $('.tab div').removeClass('tab1').removeClass('tab2'); $(this).addClass(`tab${i}`); if (i == 2) { getRank(); } }) // 榜單切換 $('.page2 .box .listTab div').click(function () { var i = $(this).index() + 1; $('.page2 .box .listTab div').removeClass('listTab1').removeClass('listTab2'); $(this).addClass(`listTab${i}`); if (i == 1) { rankType = 2; } else { rankType = 4; } getRank() }) // 規則切換 $('.rule .rule_in .tabRule div').click(function () { var i = $(this).index() + 1; $(this).addClass('act').siblings().removeClass('act'); $('.rule .rule_in .box1,.rule .rule_in .box2').hide(); $(`.rule .rule_in .box${i}`).show(); return false; }) $('.rule .rule_in .box2 .box2Tab div').click(function () { var i = $(this).index() + 1; $('.rule .rule_in .box2 .box2Tab div').removeClass('act1').removeClass('act2') $(this).addClass(`act${i}`); $('.rule .rule_in .box2 .imgBox img').attr('src', `./images/img${i}.png`) return false; }) // 打開規則 $('.header .rule_icon').click(function () { $('.rule').show(); bodyScroolFun(true); }) // 關閉規則 $('.rule').click(function () { $('.rule').hide(); bodyScroolFun(false); return false; })