475 lines
18 KiB
JavaScript
475 lines
18 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
|
let browser = checkVersion()
|
|
let env = EnvCheck();
|
|
if (env == 'test') {
|
|
new VConsole();
|
|
}
|
|
var langReplace;
|
|
var localLang;
|
|
// 封裝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 page = 1;
|
|
var isLock = true;
|
|
var magnifyingGlass = 0;
|
|
var listType = 1;
|
|
var gameType = true;
|
|
// 初始化函數
|
|
$(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)
|
|
}
|
|
})
|
|
swiperFun();
|
|
getInfo();
|
|
}, 100)
|
|
})
|
|
// 禮物輪播
|
|
function swiperFun() {
|
|
var mySwiper = new Swiper('.swiper', {
|
|
direction: "vertical",
|
|
loop: true,
|
|
autoplay: {
|
|
delay: 3000,//
|
|
disableOnInteraction: false
|
|
}
|
|
})
|
|
}
|
|
// 活動信息接口
|
|
function getInfo() {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/activity/info',
|
|
data: { activityCode: 'ACT_2024_CHILDREN_DAY' },
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/activity/currency',
|
|
data: { redisKey: 'act_user_task_extra_data' },
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
magnifyingGlass = res.data
|
|
$('.game .magnifyingGlass b').text(magnifyingGlass);
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
// 打開榜單
|
|
$('.game .list_icon').click(function () {
|
|
listFun(listType)
|
|
$('.list_pub').show();
|
|
bodyScroolFun(true);
|
|
})
|
|
// 榜單切換
|
|
$('.list_pub .list_pub_in .tab div').click(function () {
|
|
var i = $(this).index() + 1;
|
|
listType = i;
|
|
$(this).addClass('act').siblings().removeClass('act');
|
|
listFun(listType)
|
|
return false;
|
|
})
|
|
// 活動信息接口
|
|
function listFun(type) {
|
|
var str = '';
|
|
$('.list_pub .list_pub_in ul li').remove();
|
|
showLoading()
|
|
if (type == 1) {
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/allrank/geth5',
|
|
data: {
|
|
uid: pubInfo.uid,
|
|
type: 5,
|
|
datetype: 3,
|
|
pageNum: 1,
|
|
pageSize: 999999999,
|
|
},
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
var listTo3 = res.data.rankVoList.slice(0, 3);
|
|
var notListTo3 = res.data.rankVoList.slice(3);
|
|
if (listTo3.length < 3) {
|
|
let arr = new Array(3 - listTo3.length).fill({
|
|
avatar: './images/logo.png',
|
|
nick: '虛位以待',
|
|
totalNum: "0"
|
|
})
|
|
listTo3.push(...arr)
|
|
}
|
|
// 處理前三
|
|
listTo3.forEach((res, i) => {
|
|
if (res.score > 10000) {
|
|
res.score = ((Math.floor(res.totalNum / 1000)) / 10).toFixed(1) + 'W'
|
|
}
|
|
$(`.list_pub .list_pub_in .top${i + 1} .tx`).attr("src", res.avatar);
|
|
$(`.list_pub .list_pub_in .top${i + 1} .name`).text(res.nick);
|
|
$(`.list_pub .list_pub_in .top${i + 1} .score`).text('搜捕值:' + res.totalNum);
|
|
});
|
|
notListTo3.forEach((res, i) => {
|
|
if (res.score > 10000) {
|
|
res.score = ((Math.floor(res.score / 1000)) / 10).toFixed(1) + 'W'
|
|
}
|
|
str += `
|
|
<li>
|
|
<div class="num">${i + 4}</div>
|
|
<img src="${res.avatar}" alt="" class="tx">
|
|
<div class="name">${res.nick}</div>
|
|
<div class="score">搜捕值:${res.totalNum}</div>
|
|
</li>
|
|
`
|
|
})
|
|
$('.list_pub .list_pub_in ul').append(str);
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
|
|
} else {
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/act/special/gift/getRank',
|
|
data: {
|
|
pageSize: 999999999,
|
|
rankType: type == 2 ? 4 : 2,
|
|
},
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
var listTo3 = res.data.rankList.slice(0, 3);
|
|
var notListTo3 = res.data.rankList.slice(3);
|
|
if (listTo3.length < 3) {
|
|
let arr = new Array(3 - listTo3.length).fill({
|
|
avatar: './images/logo.png',
|
|
nick: '虛位以待',
|
|
score: "0"
|
|
})
|
|
listTo3.push(...arr)
|
|
}
|
|
// 處理前三
|
|
listTo3.forEach((res, i) => {
|
|
if (res.score > 10000) {
|
|
res.score = ((Math.floor(res.score / 1000)) / 10).toFixed(1) + 'W'
|
|
}
|
|
$(`.list_pub .list_pub_in .top${i + 1} .tx`).attr("src", res.avatar);
|
|
$(`.list_pub .list_pub_in .top${i + 1} .name`).text(res.nick);
|
|
$(`.list_pub .list_pub_in .top${i + 1} .score`).text(`${type == 2 ? '童趣值:' : "童年值:"}`+res.score);
|
|
});
|
|
notListTo3.forEach((res,i) => {
|
|
if (res.score > 10000) {
|
|
res.score = ((Math.floor(res.score / 1000)) / 10).toFixed(1) + 'W'
|
|
}
|
|
str += `
|
|
<li>
|
|
<div class="num">${i + 4}</div>
|
|
<img src="${res.avatar}" alt="" class="tx">
|
|
<div class="name">${res.nick}</div>
|
|
<div class="score">${type == 2 ? '童趣值:' : "童年值:" }${res.score}</div>
|
|
</li>
|
|
`
|
|
})
|
|
$('.list_pub .list_pub_in ul').append(str);
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
}
|
|
// 關閉榜單
|
|
$('.list_pub').click(function () {
|
|
$('.list_pub').hide();
|
|
bodyScroolFun(false);
|
|
})
|
|
// 打開任務
|
|
$('.game .toast_icon').click(function () {
|
|
getTask();
|
|
})
|
|
// 活動信息接口
|
|
function getTask() {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/act/children/task',
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
res.data.isLoginTask ? $('.toast_pub .toast_pub_in .toasts1 .but').addClass('act') : $('.toast_pub .toast_pub_in .toasts1 .but').removeClass('act');
|
|
res.data.isLoginTask ? $('.toast_pub .toast_pub_in .toasts1 .but').text('已完成') : $('.toast_pub .toast_pub_in .toasts1 .but').text('未完成');
|
|
$('.toast_pub .toast_pub_in .toasts2 p').text(`關註一位新的好友(${res.data.userFollowCount}/3)`);
|
|
res.data.isUserFollowTask ? $('.toast_pub .toast_pub_in .toasts2 .but').addClass('act') : $('.toast_pub .toast_pub_in .toasts2 .but').removeClass('act');
|
|
res.data.isUserFollowTask ? $('.toast_pub .toast_pub_in .toasts2 .but').text('已完成') : $('.toast_pub .toast_pub_in .toasts2 .but').text('未完成');
|
|
$('.toast_pub .toast_pub_in .toasts3 p').text(`房間停留10mins~(${res.data.keepTimeCount}/3)`);
|
|
res.data.isKeepTimeTask ? $('.toast_pub .toast_pub_in .toasts3 .but').addClass('act') : $('.toast_pub .toast_pub_in .toasts3 .but').removeClass('act');
|
|
res.data.isKeepTimeTask ? $('.toast_pub .toast_pub_in .toasts3 .but').text('已完成') : $('.toast_pub .toast_pub_in .toasts3 .but').text('未完成');
|
|
$('.toast_pub .toast_pub_in .toasts4 i').text(`今日已獲得:${res.data.limitGiftCount}`);
|
|
res.data.isLimitGiftFor61Task ? $('.toast_pub .toast_pub_in .toasts4 .but').addClass('act') : $('.toast_pub .toast_pub_in .toasts4 .but').removeClass('act');
|
|
res.data.isLimitGiftFor61Task ? $('.toast_pub .toast_pub_in .toasts4 .but').text('已完成') : $('.toast_pub .toast_pub_in .toasts4 .but').text('未完成');
|
|
$('.toast_pub .toast_pub_in .toasts5 i').text(`今日已獲得:${res.data.joinGreedyFor1000Count}`);
|
|
res.data.isJoinGreedyFor1000Task ? $('.toast_pub .toast_pub_in .toasts5 .but').addClass('act') : $('.toast_pub .toast_pub_in .toasts5 .but').removeClass('act');
|
|
res.data.isJoinGreedyFor1000Task ? $('.toast_pub .toast_pub_in .toasts5 .but').text('已完成') : $('.toast_pub .toast_pub_in .toasts5 .but').text('未完成');
|
|
$('.toast_pub').show();
|
|
bodyScroolFun(true);
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
// 關閉任務
|
|
$('.toast_pub .toast_pub_in .close').click(function () {
|
|
$('.toast_pub').hide();
|
|
bodyScroolFun(false);
|
|
})
|
|
// 關閉結果彈窗
|
|
$('.game .result .view').click(function () {
|
|
$('.result,.result2').hide();
|
|
var roomUid = $(this).attr('uid');
|
|
if (gameType) {
|
|
// 跳转房间
|
|
if (browser.ios) {
|
|
window.webkit.messageHandlers.openRoom.postMessage(roomUid);
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
window.androidJsObj.openRoom(roomUid);
|
|
}
|
|
}
|
|
}
|
|
// 打开主页
|
|
if (browser.ios) {
|
|
window.webkit.messageHandlers.openPersonPage.postMessage(roomUid);
|
|
setTimeout(function () { lock = true; }, 200)
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
window.androidJsObj.openPersonPage(roomUid);
|
|
}
|
|
}
|
|
})
|
|
$('.game .result2 .view').click(function () {
|
|
$('.result,.result2').hide();
|
|
})
|
|
$('.game .result,.game .result2').click(function () {
|
|
$('.result,.result2').hide();
|
|
})
|
|
// 關閉記錄彈窗
|
|
$('.records_pub').click(function () {
|
|
$('.records_pub').hide();
|
|
bodyScroolFun(false);
|
|
})
|
|
// 切換規則按鈕
|
|
$('.rule .rule_in .tab div').click(function () {
|
|
var i = $(this).index() + 1;
|
|
$(this).addClass('act').siblings().removeClass('act')
|
|
$('.rule .rule_in .imgBox img').hide();
|
|
$(`.rule .rule_in .imgBox .img${i}`).show();
|
|
return false;
|
|
})
|
|
// 打開規則
|
|
$('.header .rule_icon').click(function () {
|
|
$('.rule').show();
|
|
bodyScroolFun(true);
|
|
})
|
|
// 關閉規則
|
|
$('.rule').click(function () {
|
|
$('.rule').hide();
|
|
bodyScroolFun(false);
|
|
})
|
|
// 記錄接口
|
|
function record(page) {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/activity/task/user/record/page',
|
|
data: { activityCode: 'ACT_2024_CHILDREN_DAY', componentCode: 'TONG_QU_LE_YUAN', pageNum: page, pageSize: 10 },
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
var str = '';
|
|
if (res.data.records.length == 0 && page == 1) {
|
|
str += `<li class="null"><div>暫無</div><div>暫無</div></li>`
|
|
isLock = false;
|
|
} else {
|
|
res.data.records.forEach(res => {
|
|
str += `
|
|
<li>
|
|
<div>
|
|
<p>${dateFormat(res.createTime, 'yyyy/MM/dd')}</p>
|
|
<b>${dateFormat(res.createTime, 'hh/mm/ss')}</b>
|
|
</div>
|
|
<div>
|
|
<p>${res.rewardName}</p>
|
|
<i>${res.rewardNum}${rewardTypeFun(res.rewardType).unit}</i>
|
|
</div>
|
|
</li>`
|
|
})
|
|
if (res.data.records.length == 0) {
|
|
isLock = false;
|
|
} else {
|
|
isLock = true;
|
|
}
|
|
}
|
|
$('.records_pub .records_pub_in ul').append(str);
|
|
$('.records_pub').show();
|
|
bodyScroolFun(true);
|
|
} else {
|
|
isLock = true;
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
isLock = true;
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
// 兌換記錄滾動
|
|
$('.records_pub .records_pub_in ul').scroll(function () {
|
|
let scrollTop = $(this).scrollTop()
|
|
let scrollHeight = $('.records_pub .records_pub_in ul')[0].scrollHeight
|
|
let ulHeight = $(this).innerHeight()
|
|
if (scrollTop + ulHeight + 100 >= scrollHeight) {
|
|
if (isLock) {
|
|
// 請求下一頁
|
|
page = page + 1;
|
|
record(page)
|
|
isLock = false;
|
|
}
|
|
}
|
|
})
|
|
// 打開記錄
|
|
$('.game .records').click(function () {
|
|
$('.records_pub .records_pub_in ul li').remove();
|
|
page = 1;
|
|
record(page);
|
|
})
|
|
// 關閉記錄
|
|
$('.records_pub').click(function () {
|
|
$('.records_pub').hide();
|
|
bodyScroolFun(false);
|
|
})
|
|
// 逮捕按鈕
|
|
$('.game .buts,.game .but,.game .result .playAgain,.game .result2 .playAgain').click(function () {
|
|
$('.game .result2,.game .result1').hide();
|
|
draw();
|
|
})
|
|
// 活動信息接口
|
|
function draw() {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'get',
|
|
url: urlPrefix + '/act/children/draw',
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
if (res.data.isWin) {
|
|
// 中獎
|
|
$('.game .result .tx_left').attr('src', res.data.avatar);
|
|
$('.game .result .tx_right').attr('src', res.data.anchorAvatar);
|
|
$('.game .result .tx_right').attr('uid', res.data.anchorRoomUid);
|
|
$('.game .result .view').attr('uid', res.data.anchorRoomUid);
|
|
gameType = res.data.isOnline;
|
|
gameType ? $('.game .result .view').attr('src', './images/view2.png') : $('.game .result .view').attr('src', './images/view.png');
|
|
$('.game .result .name_left').text('我');
|
|
$('.game .result .name_Right').text(res.data.anchorNick);
|
|
$('.game .result .id_right').text("ID:" + res.data.anchorErBanNo);
|
|
$('.game .result .giftBoxs img').attr("src", res.data.rewardIcon);
|
|
$('.game .result .giftName').text(res.data.rewardName);
|
|
$('.game .result').show();
|
|
} else {
|
|
// 非中獎
|
|
$('.game .result2 .tx_left').attr('src', res.data.avatar);
|
|
$('.game .result2 .name_left').text('我');
|
|
$('.game .result2 .giftBoxs img').attr("src", res.data.rewardIcon);
|
|
$('.game .result2 .giftName').text(res.data.rewardName);
|
|
$('.game .result2').show();
|
|
}
|
|
getInfo();
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error(err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
// 跳轉主播房間
|
|
$('.game .result .tx_right').click(function () {
|
|
var roomUid = $(this).attr('uid');
|
|
if (browser.ios) {
|
|
window.webkit.messageHandlers.openRoom.postMessage(roomUid);
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
window.androidJsObj.openRoom(roomUid);
|
|
}
|
|
}
|
|
})
|