Files
peko-h5/view/peko/activity/2024-aprilFoolsDay/js/index.js

566 lines
20 KiB
JavaScript
Raw Normal View History

2024-03-20 16:05:54 +08:00
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'
})
}
2024-03-25 15:25:46 +08:00
var page = 1;
var isLock = true;
var timeOut = null;
var countupTime = 0;
2024-03-26 15:45:06 +08:00
var XIAO_CHOU_ROOM = 'XIAO_CHOU_ROOM_1';
2024-03-25 15:25:46 +08:00
var rankType = 1; //排行榜類型1=送禮日榜2=送禮總榜3=收禮日榜4=收禮總榜);
var data = null;//默認日榜;
var type = 'a';//a:送禮b:收禮;
var type2 = 'a';//a:日榜b:總榜;
var curDate; //當天日期;
2024-03-20 16:05:54 +08:00
// 初始化函數
$(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)
}
})
2024-03-25 15:25:46 +08:00
getTime();
getRank();
2024-03-20 16:05:54 +08:00
}, 100)
})
2024-03-26 15:25:09 +08:00
// 獲取任務接口
2024-03-25 15:25:46 +08:00
function getTaskUser () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/activity/task/user',
data: { componentCode: "QI_HUAN_MO_HE" },
success (res) {
if (res.code === 200) {
2024-03-26 15:25:09 +08:00
// 渲染愚人盛典禮物
2024-03-25 15:25:46 +08:00
$('.page1 .box1 .giftBoxs div').remove();
var str = '';
res.data[0].children.forEach((res, i) => {
2024-03-27 14:42:00 +08:00
var img = res.taskIcon.split("|");
2024-03-25 15:25:46 +08:00
str += `
<div class="${res.completed ? 'act' : ''}">
2024-03-27 14:42:00 +08:00
<img src = "${res.completed ? img[1] : img[0]}" alt = "" >
2024-03-25 15:25:46 +08:00
${res.taskName}
</div >
`
});
$('.page1 .box1 .giftBoxs').append(str);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
2024-03-26 15:25:09 +08:00
// 獲取倒計時接口
2024-03-25 15:25:46 +08:00
function getTime () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/act/2024AprilFoolsDay/getTime',
data: { activityCode: "ACT_2024_APRIL_FOOLS_DAY", taskCode: "QI_HUAN_GIFT" },
success (res) {
if (res.code === 200) {
2024-03-26 15:22:57 +08:00
if (res.data) {
countupTime = res.data - res.timestamp;
countup();
}
2024-03-26 17:21:31 +08:00
getTaskUser();
2024-03-25 15:25:46 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// 倒計時
function countup () {
clearTimeout(timeOut)
//獲取當前時間
var d = 0;
var h = 0;
var m = 0;
var s = 0;
//定義變量 d,h,m,s保存倒計時的時間
var d, h, m, s;
if (countupTime >= 0) {
d = getzf(Math.floor(countupTime / 1000 / 60 / 60 / 24));
h = getzf(Math.floor(countupTime / 1000 / 60 / 60 % 24));
m = getzf(Math.floor(countupTime / 1000 / 60 % 60));
s = getzf(Math.floor(countupTime / 1000 % 60));
//將倒計時賦值到div中
$('.page1 .box1 .time .sp1').text(m);
$('.page1 .box1 .time .sp2').text(s);
countupTime = countupTime - 1000;
//遞歸每秒調⽤countTime⽅法顯⽰動態時間效果
} else {
getTime();
return
}
timeOut = setTimeout(countup, 1000);
}
//補0操作
function getzf (num) {
if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}
2024-03-26 15:25:09 +08:00
// tab切換
2024-03-25 15:25:46 +08:00
$('.tabs div').click(function () {
var i = $(this).index() + 1;
$('.tabs div').removeClass('act1').removeClass('act2').removeClass('act3').removeClass('act4');
$(this).addClass(`act${i}`);
$('.page1,.page2,.page3,.page4').hide();
$(`.page${i}`).show();
if (i == 1) {
getRank();
} else if (i == 2) {
getRooms();
} else if (i == 4) {
giftGetRank(rankType, data);
}
})
2024-03-26 15:25:09 +08:00
// 更新房間接口按鈕
2024-03-26 15:22:57 +08:00
$('.page2 .upDate').click(function () {
getRooms();
})
2024-03-25 15:25:46 +08:00
// 獲取奇幻榜接口
function getRank () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/act/2023Halloween/rank/getRank',
2024-03-26 20:48:39 +08:00
data: { rankType: 4, pageSize: 15, },
2024-03-25 15:25:46 +08:00
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, i) => {
$(`.page1 .box2 .top3 .no${i + 1} .tx`).attr('src', res.avatar);
$(`.page1 .box2 .top3 .no${i + 1} .nick`).text(res.nick);
$(`.page1 .box2 .top3 .no${i + 1} .score`).html('奇幻值<br>' + unitProcessing(res.score, 10000, 1, 'w'))
})
// 非前三
var str = '';
$('.page1 .box2 ul li').remove();
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">奇幻值: ${unitProcessing(res.score, 10000, 1, 'w')}</div>
</li>
`
})
$('.page1 .box2 ul').append(str);
2024-03-26 15:25:09 +08:00
// 處理自己榜單
2024-03-25 15:25:46 +08:00
$('.page1 .my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.page1 .my .tx').attr('src', res.data.meRank.avatar);
$('.page1 .my .nick').text(res.data.meRank.nick);
$('.page1 .my .score').text('奇幻值' + unitProcessing(res.data.meRank.score, 10000, 1, 'w'));
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
2024-03-26 15:25:09 +08:00
// 頁面2切換
2024-03-25 15:25:46 +08:00
$('.page2 .tab div').click(function () {
var i = $(this).index() + 1;
$('.page2 .tab div').removeClass('act1').removeClass('act2');
$(this).addClass(`act${i}`);
XIAO_CHOU_ROOM = i == 1 ? 'XIAO_CHOU_ROOM_1' : 'XIAO_CHOU_ROOM_4';
getRooms();
})
2024-03-26 15:25:09 +08:00
// 獲取房間榜接口
2024-03-25 15:25:46 +08:00
function getRooms () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/act/2024AprilFoolsDay/getRooms',
2024-03-26 15:45:06 +08:00
data: { activityCode: "ACT_2024_APRIL_FOOLS_DAY", taskCode: XIAO_CHOU_ROOM },
2024-03-25 15:25:46 +08:00
success (res) {
if (res.code === 200) {
var top = res.data.slice(0, 1);
if (top.length < 3) {
let arr = new Array(1 - top.length).fill({
roomAvatar: './images/logo.png',
roomTitle: '虛位以待',
percentage: 0,
activityValue: 0,
conditionValue: 0,
})
top.push(...arr)
}
console.log(top);
var notTop = res.data.slice(1);
2024-03-26 15:25:09 +08:00
// 第一房間
2024-03-25 15:25:46 +08:00
$('.page2 .topRoom .tx').attr('src', top[0].roomAvatar);
$('.page2 .topRoom .roomName').text(top[0].roomTitle);
$('.page2 .topRoom .score b').text(top[0].percentage + '%');
2024-03-26 20:48:39 +08:00
$('.page2 .topLine div').css('width', top[0].percentage + '%');
2024-03-25 15:25:46 +08:00
$('.page2 .topLine span').text(`${top[0].activityValue}/${top[0].conditionValue}`);
$('.page2 .page2ToRoomBut').attr("uid", top[0].roomUid);
$('.page2 .page2ToRoomBut').attr("src", top[0].isUnderway ? './images/page2ToRoomBut.png' : './images/page2ToRoomBut2.png');
$('.page2 .page2ToRoomBut').attr("isUnderway", top[0].isUnderway);
2024-03-26 15:25:09 +08:00
// 其他房間
2024-03-25 15:25:46 +08:00
$('.page2 ul li').remove();
var str = '';
notTop.forEach(res => {
str += `
<li>
<img src="${res.roomAvatar}" alt="" class="tx">
<div class="live" style="display:${res.isLive ? 'block' : 'none'}">直播中</div>
<div class="roomName">${res.roomTitle}</div>
<div class="score">房間進度值: <b>${res.percentage}%</b></div>
<div class="line_in">
2024-03-26 18:21:57 +08:00
<div style="width:${res.percentage}%"></div>
2024-03-25 15:25:46 +08:00
<span>${res.activityValue}/${res.conditionValue}</span>
</div>
<img style="display:${res.isUnderway ? 'block' : 'none'}" src="./images/go.png" alt="" class="go" uid=${res.roomUid}>
2024-03-26 18:21:57 +08:00
<img style="display:${!res.isUnderway ? 'block' : 'none'}" src="./images/notGo.png" alt="" class="notGo" uid=${res.roomUid}>
2024-03-25 15:25:46 +08:00
</li>
`
})
$('.page2 ul').append(str);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
2024-03-26 15:25:09 +08:00
// 房間最前面的跳轉按鈕
2024-03-25 15:25:46 +08:00
$('.page2 .page2ToRoomBut').click(function () {
var uid = $(this).attr('uid');
var isUnderway = $(this).attr('isUnderway');
if (isUnderway) {
if (browser.ios) {
window.webkit.messageHandlers.openRoom.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoom(uid);
}
}
}
})
2024-03-26 15:25:09 +08:00
// 其他房間跳轉房間按鈕
2024-03-25 15:25:46 +08:00
$('.page2 ul').on('click', ' li .go', function () {
2024-03-26 18:21:57 +08:00
var uid = $(this).attr('uid');
if (browser.ios) {
window.webkit.messageHandlers.openRoom.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoom(uid);
}
}
})
// 其他房間跳轉房間按鈕
$('.page2 ul').on('click', ' li .notGo', function () {
2024-03-25 15:25:46 +08:00
var uid = $(this).attr('uid');
if (browser.ios) {
window.webkit.messageHandlers.openRoom.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoom(uid);
}
}
})
2024-03-26 15:25:09 +08:00
// 頁面4切換
2024-03-25 15:25:46 +08:00
$('.page4 .page4_tab div').click(function () {
var i = $(this).index() + 1;
$('.page4').removeClass('page41').removeClass('page42');
$('.page4').addClass(`page4${i}`);
if (i == 1) {
type = 'a';
rankType = type2 == "a" ? 1 : 2;
} else {
type = 'b';
rankType = type2 == "a" ? 3 : 4;
}
giftGetRank(rankType, data);
})
2024-03-26 15:25:09 +08:00
// 頁面4 日榜/總榜切換
2024-03-25 15:25:46 +08:00
$('.page4 .dayTab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass('act').siblings().removeClass('act')
if (i == 1) {
type2 = 'a';
rankType = type == "a" ? 1 : 3;
$('.page4 .timeTab').show();
} else {
type2 = 'b';
rankType = type == "a" ? 2 : 4;
$('.page4 .timeTab').hide();
}
giftGetRank(rankType, data);
})
2024-03-26 15:25:09 +08:00
// 頁面4 日期切換
2024-03-25 15:25:46 +08:00
$('.page4 .timeTab div').click(function () {
var i = $(this).index() + 1;
var datas = $(this).attr('data');
$(this).addClass('act').siblings().removeClass('act')
rankType = type == "a" ? 1 : 3;//排行榜類型1=甜蜜日榜2=甜蜜總榜3=愛意日榜4=愛意總榜)
data = datas;
giftGetRank(rankType, data);
})
2024-03-26 15:25:09 +08:00
// 獲取愚人榜單接口
2024-03-25 15:25:46 +08:00
function giftGetRank (rankType, date) {
2024-03-20 16:05:54 +08:00
showLoading()
networkRequest({
type: 'get',
2024-03-25 15:25:46 +08:00
url: urlPrefix + '/act/special/gift/getRank',
data: { rankType, date, pageSize: 30 },
2024-03-20 16:05:54 +08:00
success (res) {
if (res.code === 200) {
2024-03-25 15:25:46 +08:00
// 設置當天日期
curDate = res.data.curDate;
// 處理日期
if (res.data.dateList) {
res.data.dateList.forEach((res, i) => {
$('.page4 .timeTab div').eq(i).text(`${res[5]}${res[6]}.${res[8]}${res[9]}`);
$('.page4 .timeTab div').eq(i).attr('data', res);
if (res == curDate && date == null) {
$('.page4 .timeTab div').removeClass('act')
$('.page4 .timeTab div').eq(i).addClass('act');
}
})
}
// 處理前三
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, i) => {
$(`.page4 .top3 .no${i + 1} .tx`).attr('src', res.avatar);
$(`.page4 .top3 .no${i + 1} .nick`).text(res.nick);
2024-03-27 17:59:34 +08:00
$(`.page4 .top3 .no${i + 1} .score`).html(`${rankType == 1 || rankType == 2 ? '愚樂值' : '歡樂值'}<br>` + unitProcessing(res.score, 10000, 1, 'w'))
2024-03-25 15:25:46 +08:00
})
// 非前三
var str = '';
$('.page4 ul li').remove();
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>
2024-03-27 17:59:34 +08:00
<div class="score">${rankType == 1 || rankType == 2 ? '愚樂值' : '歡樂值'}: ${unitProcessing(res.score, 10000, 1, 'w')}</div>
2024-03-25 15:25:46 +08:00
</li>
`
})
$('.page4 ul').append(str);
2024-03-26 15:25:09 +08:00
// 處理自己榜單
2024-03-25 15:25:46 +08:00
$('.page4 .my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.page4 .my .tx').attr('src', res.data.meRank.avatar);
$('.page4 .my .nick').text(res.data.meRank.nick);
2024-03-27 17:59:34 +08:00
$('.page4 .my .score').text(`${rankType == 1 || rankType == 2 ? '愚樂值' : '歡樂值'}` + unitProcessing(res.data.meRank.score, 10000, 1, 'w'));
2024-03-25 15:25:46 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
2024-03-20 16:05:54 +08:00
2024-03-26 15:25:09 +08:00
// 魔盒切換
2024-03-25 15:25:46 +08:00
$('.MagicBoxRule .MagicBoxRule_in .tab div').click(function () {
var i = $(this).index() + 1;
$('.MagicBoxRule .MagicBoxRule_in').removeClass('MagicBoxRule1').removeClass('MagicBoxRule2');
$('.MagicBoxRule .MagicBoxRule_in').addClass(`MagicBoxRule${i}`);
$('.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage1,.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage2').hide();
$(`.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage${i}`).show();
return false;
})
// 獲取魔盒接口
function getRecordPage () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/activity/task/user/record/page',
data: {
componentCode: "QI_HUAN_MO_HE",
activityCode: 'ACT_2024_APRIL_FOOLS_DAY',
pageNum: page,
pageSize: 20,
},
success (res) {
if (res.code === 200) {
var str = ''
if (res.data.records.length == 0) {
str = `
2024-03-26 15:25:09 +08:00
<li class="not">暫無記錄</li>
2024-03-25 15:25:46 +08:00
`
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 class="centen">${res.nick}</div>
<div class="right">
<p>獲得${res.rewardName}</p>
<b>${res.showValue} <img src="./images/diamond.png" alt=""></b>
</div>
</li>
`
})
isLock = true;
}
$('.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage2 ul').append(str);
2024-03-20 16:05:54 +08:00
} else {
toastMsg(res.message)
2024-03-25 15:25:46 +08:00
isLock = true;
2024-03-20 16:05:54 +08:00
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
2024-03-25 15:25:46 +08:00
isLock = true;
2024-03-20 16:05:54 +08:00
}
})
2024-03-25 15:25:46 +08:00
}
2024-03-26 15:25:09 +08:00
// 滾動
2024-03-25 15:25:46 +08:00
$('.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage2 ul').scroll(function () {
let scrollTop = $(this).scrollTop()
let scrollHeight = $('.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage2 ul')[0].scrollHeight
let ulHeight = $(this).innerHeight()
if (scrollTop + ulHeight + 100 >= scrollHeight) {
if (isLock) {
// 請求下一頁
page = page + 1;
getRecordPage();
isLock = false;
}
}
})
2024-03-26 15:25:09 +08:00
// 打開魔盒規則
2024-03-25 15:25:46 +08:00
$('.page1 .box1 .pageBox1Rule_icon').click(function () {
$('.MagicBoxRule .MagicBoxRule_in .MagicBoxRulePage2 ul li').remove();
getRecordPage();
$('.MagicBoxRule').show();
bodyScroolFun(true);
})
2024-03-26 15:25:09 +08:00
// 關閉魔盒規則
2024-03-25 15:25:46 +08:00
$('.MagicBoxRule').click(function () {
$('.MagicBoxRule').hide();
bodyScroolFun(false);
})
2024-03-26 15:25:09 +08:00
// 打開規則
2024-03-25 15:25:46 +08:00
$('.header .rule_icon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
2024-03-26 15:25:09 +08:00
// 關閉規則
2024-03-25 15:25:46 +08:00
$('.rule').click(function () {
$('.rule').hide();
bodyScroolFun(false);
})
2024-03-26 15:25:09 +08:00
// 打開限定禮物規則
2024-03-25 15:25:46 +08:00
$('.header .qualifyGift_icon').click(function () {
$('.limitedGift').show();
bodyScroolFun(true);
})
2024-03-26 15:25:09 +08:00
// 關閉限定禮物規則
2024-03-25 15:25:46 +08:00
$('.limitedGift').click(function () {
$('.limitedGift').hide();
bodyScroolFun(false);
})