Files
peko-h5/view/peko/activity/act-2023-qx/js/index.js
2023-08-18 19:37:23 +08:00

646 lines
23 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 xiqueNum = 0;//当前剩余喜鹊数量
var roomUid = 0;//房间uid
var giftId = 0;//默认礼物id
var xiqueBut = true;//投放喜鹊锁
var data = null;//默认日榜
var rankType = 1;//排行榜类型1=甜蜜日榜2=甜蜜总榜3=爱意日榜4=爱意总榜)
var curDate;//当天日期
var nextHourTimeStamp;//下一轮结束时间戳
var leftTime;//倒计时暂存
var timeOut2;//储存定时器
// 初始化函數
$(function () {
setTimeout(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();
getConfig();
getRecommendRoom();
}, 100)
})
})
// 初始化接口
function getConfig () {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/act/2023Qixi/xique/getConfig',
data: {},
success (res) {
if (res.code === 200) {
// 处理活动时间
$('.header .titleHeader').text(`活動時間:${dateFormat(res.data.startTime, 'yyyy年MM月dd日')}-${dateFormat(res.data.endTime, 'yyyy年MM月dd日')}`)
// 当前用户喜鹊
xiqueNum = res.data.xiqueNum
$('.page1 .magpieBridge .birdNum b').text(`我的喜鵲: ${res.data.xiqueNum}`)
// 处理当前喜鹊进度状态值
var curXiqueNums = res.data.serverCurXiqueNum / res.data.serverMaxXiqueNum * 100;
$('.page1 .magpieBridge .line .line_in').css('width', curXiqueNums >= 100 ? '100%' : `${curXiqueNums}%`);
// 处理领取喜鹊头饰按钮状态
if (res.data.devotedBtnStatus == 0) {//投入按钮状态0=可投入1=可领取2=不能领取,-1=已领取)
$('.page1 .magpieBridge .buting').hide();
$('.page1 .magpieBridge .buterr').hide();
$('.page1 .magpieBridge .butout').hide();
$('.page1 .magpieBridge .but1').show();
$('.page1 .magpieBridge .but10').show();
} else if (res.data.devotedBtnStatus == 1) {//投入按钮状态0=可投入1=可领取2=不能领取,-1=已领取)
$('.page1 .magpieBridge .buting').show();
$('.page1 .magpieBridge .but1').hide();
$('.page1 .magpieBridge .but10').hide();
} else if (res.data.devotedBtnStatus = 2) {
$('.page1 .magpieBridge .buterr').show();
$('.page1 .magpieBridge .but1').hide();
$('.page1 .magpieBridge .but10').hide();
} else if (res.data.devotedBtnStatus < 0) {
$('.page1 .magpieBridge .butout').show();
$('.page1 .magpieBridge .but1').hide();
$('.page1 .magpieBridge .but10').hide();
}
// 处理任务状态
res.data.dailyTaskList.forEach((res, i) => {
$(`.page1 .task .box1 .task${i + 1} .p2`).text(`獎勵:喜鵲*${res.xiqueNum}`)
if (res.btnStatus == 1) {//已完成
$(`.page1 .task .box1 .task${i + 1} .but`).addClass('out');
$(`.page1 .task .box1 .task${i + 1} .but`).text('已完成');
$(`.page1 .task .box1 .task${i + 1} .but`).attr('click', 0);
}
if (i == 1) {
$(`.page1 .task .box1 .task2 .p1`).text(`任意房間發送彈幕(${res.cur}/${res.need})`)
}
if (i == 2) {
var percentage = res.cur / res.need * 100;
$('.page1 .task .box1 .task3 .line .line_in').css('width', percentage >= 100 ? '100%' : `${percentage}%`);
}
});
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 获取房间Uid接口
function getRecommendRoom () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/tab/home/one',
data: { pub_ticket: pubInfo.ticket, pub_uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
roomUid = res.data;
hideLoading(layerIndex)
} else {
hideLoading(layerIndex)
toastMsg(res.message)
}
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 定情信物礼物轮播
function swiperFun () {
var mySwiper = new Swiper('.swiper', {
direction: "vertical",
loop: true,
autoplay: {
delay: 2000,//3秒切换一次
disableOnInteraction: false
}
})
}
// 总tab切换
$('.tabs div').click(function () {
var i = $(this).index() + 1;
$('.tabs').removeClass('tab1').removeClass('tab2').removeClass('tab3').removeClass('tab4');
$('.tabs').addClass(`tab${i}`);
$('.page1').hide();
$('.page2').hide();
$('.page3').hide();
$('.page4').hide();
$(`.page${i}`).show();
if (i == 3) {
getRoomRank();
}
if (i == 4) {
data == null;
rankType = 1;
getRank(data, rankType);
getCpRank();
}
})
// 房间榜单接口
function getRoomRank () {
$('.page3 ul li').remove();
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/act/2023Qixi/roomRank/getRank',
data: {},
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) => {
$(`.page3 .no${index + 1} .tx`).attr('src', res.avatar);
$(`.page3 .no${index + 1} p`).text(res.nick);
$(`.page3 .no${index + 1} b`).text(`情緣值:${unitProcessing(res.score, 10000, 1, 'w')}`);
$(`.page3 .no${index + 1} .txBg`).attr('uid', res.uid);
})
// 跳转前三房间
$('.page3 .no .txBg').click(function () {
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);
}
}
})
// 非前三
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${res.ranking}</div>
<img src="${res.avatar}" alt="" class="tx" uid=${res.uid}>
<div class="name">${res.nick}</div>
<div class="score">
<img src="./images/loveIcon.png" alt="" class="loveIcon">
<b>情緣值:${unitProcessing(res.score, 10000, 1, 'w')}</b>
</div>
</li>
`
})
$('.page3 ul').append(str);
// 跳转非前三房间
$('.page3 ul li .tx').click(function () {
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);
}
}
})
// 处理自己榜单
var meRank = res.data.meRank;
$('.page3 .my .num').text(meRank.ranking == 0 ? '未上榜' : meRank.ranking);
$('.page3 .my .tx').attr('src', meRank.avatar);
$('.page3 .my .name').text(meRank.nick);
$('.page3 .my .score b').text(`情緣值:${unitProcessing(meRank.score, 10000, 1, 'w')}`);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 获取情缘榜接口
function getRank (date, rankType) {
$('.page4 ul li').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023Qixi/rank/getRank',
data: { date, rankType },
success (res) {
if (res.code === 200) {
// 设置当天日期
curDate = res.data.curDate;
// 处理日期
if (res.data.dateList) {
res.data.dateList.forEach((res, i) => {
$('.page4 .timeList div').eq(i).text(`${res[6]}.${res[8]}${res[9]}`);
$('.page4 .timeList div').eq(i).attr('data', res);
if (res == curDate && date == null) {
$('.page4 .timeList div').removeClass('active')
$('.page4 .timeList div').eq(i).addClass('active');
}
})
}
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) => {
$(`.page4 .no${index + 1} .tx`).attr('src', res.avatar);
$(`.page4 .no${index + 1} p`).text(res.nick);
if (rankType == 1 || rankType == 2) {
$(`.page4 .no${index + 1} b`).text(`甜蜜值:${unitProcessing(res.score, 10000, 1, 'w')}`);
} else {
$(`.page4 .no${index + 1} b`).text(`心动值:${unitProcessing(res.score, 10000, 1, 'w')}`);
}
})
// 非前三
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${res.ranking}</div>
<img src="${res.avatar}" alt="" class="tx">
<div class="name">${res.nick}</div>
<div class="score">
<img src="./images/loveIcon.png" alt="" class="loveIcon">
<b>${rankType == 1 || rankType == 2 ? "甜蜜值:" : '心动值:'}${unitProcessing(res.score, 10000, 1, 'w')}</b>
</div>
</li>
`
})
$('.page4 ul').append(str);
// 处理自己榜单
var meRank = res.data.meRank;
$('.page4 .my .num').text(meRank.ranking == 0 ? '未上榜' : meRank.ranking);
$('.page4 .my .tx').attr('src', meRank.avatar);
$('.page4 .my .name').text(meRank.nick);
if (rankType == 1 || rankType == 2) {
$('.page4 .my .score b').text(`甜蜜值:${unitProcessing(meRank.score, 10000, 1, 'w')}`);
} else {
$('.page4 .my .score b').text(`心动值:${unitProcessing(meRank.score, 10000, 1, 'w')}`);
}
hideLoading(layerIndex)
} else {
hideLoading(layerIndex)
toastMsg(res.message)
}
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 首页任务切换
$('.page1 .task .tab div').click(function () {
var i = $(this).index() + 1;
if (i == 1) {
$('.page1 .task').removeClass('tasks2');
} else {
$('.page1 .task').addClass('tasks2');
}
})
// 打开活动规则
$('.header .rule').click(function () {
bodyScroolFun(true);
$('.rule_pub').show();
})
// 关闭活动规则
$('.rule_pub').click(function () {
bodyScroolFun(false);
$('.rule_pub').hide();
})
// 打开房间榜活动规则
$('.page3 .rule').click(function () {
bodyScroolFun(true);
$('.page3 .roomRule').show();
})
// 关闭房间榜活动规则
$('.roomRule').click(function () {
bodyScroolFun(false);
$('.roomRule').hide();
})
// 打开房间榜活动规则
$('.page4 .rule').click(function () {
bodyScroolFun(true);
$('.page4 .sweet').show();
})
// 关闭房间榜活动规则
$('.sweet').click(function () {
bodyScroolFun(false);
$('.sweet').hide();
})
// 祈愿树tab切换
$('.page2 .blessingTreeBoomt .tab div').click(function () {
var i = $(this).index() + 1;
if (i == 1) {
$('.page2 .blessingTreeBoomt').removeClass('blessingTreeBoomt2')
} else {
$('.page2 .blessingTreeBoomt').addClass('blessingTreeBoomt2')
}
})
// 获取CP榜单接口
function getCpRank () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023Qixi/rank/getCpRank',
data: { pub_ticket: pubInfo.ticket, pub_uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
if (res.data.senderNick) {
$('.page4 .loveList .txL').attr('src', res.data.senderAvatar);
$('.page4 .loveList .txR').attr('src', res.data.receiverAvatar);
$('.page4 .loveList .leftName').text(res.data.senderNick);
$('.page4 .loveList .rightName').text(res.data.receiverNick);
} else {
$('.page4 .loveList .txL').attr('src', './images/logo.png');
$('.page4 .loveList .txR').attr('src', './images/logo.png');
$('.page4 .loveList .leftName').text('虚位以待');
$('.page4 .loveList .rightName').text('虚位以待');
}
if (res.data.nextHourTimeStamp) {
nextHourTimeStamp = res.data.nextHourTimeStamp;
leftTime = nextHourTimeStamp - res.timestamp;
// leftTime = 1691654400000;
countup(leftTime);
} else {
$('.page4 .loveList .times').hide();
}
hideLoading(layerIndex)
} else {
hideLoading(layerIndex)
toastMsg(res.message)
}
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 倒计时
function countup () {
clearTimeout(timeOut2)
//获取当前时间
// var now = nowTime;
var d = 0;
var h = 0;
var m = 0;
var s = 0;
//定义变量 d,h,m,s保存倒计时的时间
var d, h, m, s;
if (leftTime >= 0) {
d = getzf(Math.floor(leftTime / 1000 / 60 / 60 / 24));
h = getzf(Math.floor(leftTime / 1000 / 60 / 60 % 24));
m = getzf(Math.floor(leftTime / 1000 / 60 % 60));
s = getzf(Math.floor(leftTime / 1000 % 60));
//将倒计时赋值到div中
$('.page4 .loveList .times span').eq(0).text(h);
$('.page4 .loveList .times span').eq(1).text(m);
leftTime = leftTime - 1000;
//递归每秒调⽤countTime⽅法显⽰动态时间效果
} else {
getCpRank();
// location.reload();
return
}
timeOut2 = setTimeout(countup, 1000);
}
//补0操作
function getzf (num) {
if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}
// 七夕榜单tab切换
var type = 'a';//a:甜蜜b:心动
$('.page4 .page4Tab div').click(function () {
$('.page4 .dayAll').removeClass('dayAll2');
var i = $(this).index() + 1;
if (i == 1) {
rankType = 1;//排行榜类型1=甜蜜日榜2=甜蜜总榜3=爱意日榜4=爱意总榜)
data = null;
getRank(data, rankType);
$('.page4 .page4Tab').removeClass('page4Tab2');
type = 'a';
} else {
rankType = 3;
data = null;
getRank(data, rankType);
$('.page4 .page4Tab').addClass('page4Tab2');
type = 'b';
}
})
// 七夕榜单日榜总榜切换
$('.page4 .dayAll div').click(function () {
var i = $(this).index() + 1;
if (i == 1) {
$('.page4 .dayAll').removeClass('dayAll2');
rankType = type == "a" ? 1 : 3;//排行榜类型1=甜蜜日榜2=甜蜜总榜3=爱意日榜4=爱意总榜)
data = null;
getRank(data, rankType);
$('.page4 .timeList').show();
} else {
$('.page4 .dayAll').addClass('dayAll2');
rankType = type == "a" ? 2 : 4;//排行榜类型1=甜蜜日榜2=甜蜜总榜3=爱意日榜4=爱意总榜)
data = null;
getRank(data, rankType);
$('.page4 .timeList').hide();
}
})
// 日榜切换日期
$('.page4 .timeList 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(data, rankType);
})
// 关闭活动结束按钮
$('.endActivity .endActivity_in .but').click(function () {
$('.endActivity').hide();
bodyScroolFun(false);
})
//领取全服喜鹊奖励
function getXiqueReward () {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/act/2023Qixi/xique/getXiqueReward',
data: {},
success (res) {
if (res.code === 200) {
getConfig();
toastMsg('领取成功');
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 领取喜鹊奖励按钮
$('.page1 .magpieBridge .buting').click(function () {
getXiqueReward();
})
// 领取喜鹊未参与按钮
$('.page1 .magpieBridge .buterr').click(function () {
toastMsg('您未参加搭建鹊桥活动,无法领取');
})
// 投放喜鹊接口
function devotedXique (num) {
// showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/act/2023Qixi/xique/devotedXique',
data: { num },
success (res) {
if (res.code === 200) {
getConfig();
toastMsg('投放成功')
xiqueBut = true;
} else {
toastMsg(res.message)
xiqueBut = true;
}
hideLoading(layerIndex)
xiqueBut = true;
},
error (err) {
xiqueBut = true;
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 播放喜鹊svg
function svgaFun () {
player1 = new SVGA.Player('.xique');
parser1 = new SVGA.Parser('.xique');
parser1.load('./images/xique.svga', function (videoItem) {
player1.loops = 1
player1.clearsAfterStop = false;
player1.setVideoItem(videoItem);
player1.startAnimation();
player1.setContentMode('AspectFill')
player1.onFinished(() => {
// $('.svga').hide()
})
})
}
// 投放按钮
$('.page1 .magpieBridge .but1,.page1 .magpieBridge .but10').click(function () {
var clas = $(this).attr('class')
if (clas == 'but1') {
if (xiqueNum < 1) {
toastMsg('喜鹊数量不足,参加任务获得吧~')
return
}
if (xiqueBut) {
xiqueBut = false;
svgaFun();
setTimeout(function () {
devotedXique(1);
}, 2000)
}
} else {
if (xiqueNum < 10) {
toastMsg('喜鹊数量不足,参加任务获得吧~')
return
}
if (xiqueBut) {
xiqueBut = false;
svgaFun();
setTimeout(function () {
devotedXique(10);
}, 2000)
}
// devotedXique(10);
}
})
// 去完成任务2按钮
$('.page1 .task .box1 .task2 .but').click(function () {
var click = $(this).attr('click');
if (click != 0) {
if (browser.ios) {
window.webkit.messageHandlers.openRoom.postMessage(roomUid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoom(roomUid);
}
}
}
})
// 去完成任务3按钮
$('.page1 .task .box1 .task3 .but').click(function () {
var click = $(this).attr('click');
if (click != 0) {
if (browser.ios) {
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: giftId }))
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoomForGiftId(roomUid, giftId);
}
}
}
})