Files
peko-h5/view/peko/activity/billiard/js/index.js
2024-02-28 19:57:47 +08:00

253 lines
8.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 roomUid = 77620;
var round = null;//輪次
var countupTime = null;//倒計時
var endTime = null;
// 初始化函數
$(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
// },
// 如果需要分頁器
pagination: {
el: '.swiper-pagination',
},
})
getRank();
}, 100)
})
// tab切換
$('.tabBox div').click(function () {
var i = $(this).index() + 1;
$('.tabBox div').removeClass('tabAct1').removeClass('tabAct2').removeClass('tabAct3').removeClass('tabAct4');
$(`.tabBox .tab${i}`).addClass(`tabAct${i}`);
$('.page1,.page2,.page3,.page4').hide();
$(`.page${i}`).show();
if (i == 1) {
round = i;
getRank();
}
})
// 前三跳轉
$('.page1 .top div').on('click', '.tx', function () {
var uid = $(this).attr('uid');
// 跳轉個人資料頁
if (browser.ios) {
window.webkit.messageHandlers.openPersonPage.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openPersonPage(uid);
}
} else {
console.log('web');
}
})
// 非前三跳轉
$('.page1 ul').on('click', 'li .tx', function () {
var uid = $(this).attr('uid');
// 跳轉個人資料頁
if (browser.ios) {
window.webkit.messageHandlers.openPersonPage.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openPersonPage(uid);
}
} else {
console.log('web');
}
})
// 獲取任務接口
function getRank () {
$('ul li').remove();
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/act/2024Snooker/room/getRank',
data: { round },
success (res) {
if (res.code === 200) {
// 當前頁面展示
$('.tabBox div').removeClass('tabAct1').removeClass('tabAct2').removeClass('tabAct3');
$(`.tabBox .tab${res.data.rankType}`).addClass(`tabAct${res.data.rankType}`);
$('.page1,.page2,.page3').hide();
$(`.page${res.data.rankType}`).show();
// 處理倒計時
if (res.data.rankType == 1) {
if (round == null) {
endTime = res.data.roundList[0].endTime
}
if (endTime - res.timestamp > 0) {
countup(endTime - res.timestamp);
} else {
$('.time').hide();
}
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: '虛位以待',
erbanNo: "虛位以待",
score: "0"
})
top3.push(...arr)
}
top3.forEach((res, i) => {
$(`.top .no${i + 1} .tx`).attr('src', res.avatar);
$(`.top .no${i + 1} .tx`).attr('uid', res.uid);
$(`.top .no${i + 1} p`).text(res.nick);
$(`.top .no${i + 1} span`).text(`ID:${res.erbanNo}`);
$(`.top .no${i + 1} .score b`).text(res.score);
});
// 處理非前三
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${res.ranking}</div>
<img uid=${res.uid} src="${res.avatar}" alt="" class="tx">
<div class="user">
<p>${res.nick}</p>
<span>ID:${res.erbanNo}</span>
</div>
<div class="score">勝場次數: ${res.score}</div>
</li>
`
})
$('ul').append(str);
// 處理自己
$('.my .tx').attr('src', res.data.meRank.avatar);
$('.my .tx').attr('uid', res.data.meRank.uid);
$('.my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.my p').text(res.data.meRank.nick);
$('.my .score').text(`勝場次數: ${res.data.meRank.score}`);
}
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 人氣榜倒計時
function countup (leftTime) {
clearTimeout(countupTime)
//獲取當前時間
// var now = nowTime;
var d = 0;
var h = 0;
var m = 0;
var s = 0;
//定義變量 d,h,m,s保存倒計時的時間
var d, h, m, s;
//遞歸每秒調⽤countTime⽅法顯⽰動態時間效果
if (leftTime > 0) {
d = getzf(Math.floor(leftTime / 1000 / 60 / 60 / 24));
h = getzf(Math.floor(leftTime / 1000 / 60 / 60));
m = getzf(Math.floor(leftTime / 1000 / 60 % 60));
s = getzf(Math.floor(leftTime / 1000 % 60));
//將倒計時賦值
$('.time .sp1').text(h);
$('.time .sp2').text(m);
$('.time .sp3').text(s);
} else {
$('.time').hide();
}
if (leftTime > 0) {
leftTime = leftTime - 1000;
}
countupTime = setTimeout(function () {
countup(leftTime);
}, 1000);
}
//補0操作
function getzf (num) {
if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}
// 頁面2跳轉房間
$('.page2 .page2GoToRoom,.page3 .page2GoToRoom,.page4 .page2GoToRoom').click(function () {
if (browser.ios) {
window.webkit.messageHandlers.openRoom.postMessage(roomUid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoom(roomUid);
}
}
})
// 規則切換
$('.rule .rule_in .tab div').click(function () {
var i = $(this).index() + 1;
$('.rule .rule_in .tab').removeClass('tab1').removeClass('tab2')
$('.rule .rule_in .tab').addClass(`tab${i}`)
$('.rule .rule_in .box img').attr('src', `./images/rule${i}.png`)
return false;
})
// 打開規則
$('.header .rule_icon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
// 關閉規則
$('.rule').click(function () {
$(this).hide();
bodyScroolFun(false);
})