436 lines
14 KiB
JavaScript
436 lines
14 KiB
JavaScript
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;//投放喜鹊锁
|
||
// 初始化函數
|
||
$(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}`)
|
||
// 处理当前喜鹊进度状态值
|
||
console.log(res.data.serverCurXiqueNum);
|
||
console.log(res.data.serverMaxXiqueNum);
|
||
var curXiqueNums = res.data.serverCurXiqueNum / res.data.serverMaxXiqueNum * 100;
|
||
console.log(curXiqueNums);
|
||
$('.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('網絡錯誤,請退出重進')
|
||
}
|
||
})
|
||
}
|
||
// 获取房间接口
|
||
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();
|
||
}
|
||
})
|
||
// 房间榜单接口
|
||
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')}`);
|
||
})
|
||
// 非前三
|
||
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>情緣值:${unitProcessing(res.score, 10000, 1, 'w')}</b>
|
||
</div>
|
||
</li>
|
||
`
|
||
})
|
||
$('.page3 ul').append(str);
|
||
// 处理自己榜单
|
||
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('網絡錯誤,請退出重進')
|
||
}
|
||
})
|
||
}
|
||
// 首页任务切换
|
||
$('.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')
|
||
}
|
||
})
|
||
// 七夕榜单tab切换
|
||
$('.page4 .page4Tab div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
if (i == 1) {
|
||
$('.page4 .page4Tab').removeClass('page4Tab2');
|
||
} else {
|
||
$('.page4 .page4Tab').addClass('page4Tab2');
|
||
}
|
||
})
|
||
// 七夕榜单日榜总榜切换
|
||
$('.page4 .dayAll div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
if (i == 1) {
|
||
$('.page4 .dayAll').removeClass('dayAll2');
|
||
} else {
|
||
$('.page4 .dayAll').addClass('dayAll2');
|
||
}
|
||
})
|
||
// 日榜切换日期
|
||
$('.page4 .timeList div').click(function () {
|
||
var i = $(this).index() + 1;
|
||
$(this).addClass('active').siblings().removeClass('active');
|
||
})
|
||
// 关闭活动结束按钮
|
||
$('.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);
|
||
}
|
||
}
|
||
}
|
||
}) |