Files
peko-h5/view/peko/activity/act-ocean/js/index.js

1229 lines
42 KiB
JavaScript
Raw Normal View History

2022-09-08 18:22:18 +08:00
let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let env = EnvCheck();
if (env == 'test') {
new VConsole();
}
let lock = false //防止用戶暴力點擊加的鎖
2022-09-08 18:22:18 +08:00
// 封裝layer消息提醒框
2022-09-08 18:22:18 +08:00
let layerIndex
const showLoading = (content = '加載中...') => {
2022-09-08 18:22:18 +08:00
layer.open({
type: 2,
shadeClose: false,
content,
success (e) {
2022-09-08 18:22:18 +08:00
layerIndex = $(e).attr('index')
}
})
}
const hideLoading = (index) => {
layer.close(index)
}
const toastMsg = (content = '操作完成', time = 2) => {
layer.open({
content,
time,
skin: 'msg'
})
}
2023-02-23 10:11:40 +08:00
if (false) { //!browser.app
toastMsg('請在app內打開');
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
$('.wrap').removeClass('no-in-app')
}
// 獲取用戶相關信息
2022-09-08 18:22:18 +08:00
let myFragment
const getUserInfo = (param) => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getUserActInfo',
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
$('.info-bottom .info-wrap .fragment-num span').text(res.data.todayReward);
$('.info-bottom .info-wrap .diamond-num span').text(res.data.diamonds);
$('.info-bottom .avatar img').attr('src', res.data.avatar);
2022-09-08 18:22:18 +08:00
$('.info-bottom').find('.avatar img').attr('src', res.data.avatar)
2022-10-22 20:08:44 +08:00
if (res.data.todayReward.toString().length >= 5) {
res.data.todayReward = (res.data.todayReward / 10000).toFixed(2) + 'w'
2022-09-08 18:22:18 +08:00
}
$('.info-bottom').find('.award span').html(res.data.todayReward)
2022-10-22 20:08:44 +08:00
$('.info-bottom').find('.fragment span').html(res.data.diamonds)
myFragment = res.data.diamonds
} else {
2022-09-08 18:22:18 +08:00
return toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
2022-09-08 18:22:18 +08:00
}
})
}
// 獲取用戶碎片信息
2022-09-08 18:22:18 +08:00
const getUserPieceNum = () => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getUserActInfo',
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
$('.info-bottom').find('.fragment span').html(res.data.diamonds)
myFragment = res.data.diamonds;
} else {
2022-09-08 18:22:18 +08:00
return toastMsg(res.message)
}
lock = !lock
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 獲取遊戲模式 1普通模式 2禮物模式
let modelType
const getGameMode = () => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getTimeConfig',
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
modelType = res.data.modelType
getNewestAct()
2022-10-22 20:08:44 +08:00
} else {
return toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
2022-09-08 18:22:18 +08:00
}
})
}
let userComeinTime //用戶進入遊戲界面時間後端返回的timestamp
let startTime, drawStageStartTime, showResultStageStartTime, endTime //4個時間戳判斷落於哪個界面
2022-09-08 18:22:18 +08:00
let timer2
let roundId
let roundIdArr = []
let arrTime = [], arrTime2 = [], arrTime3 = []
const getNewestAct = () => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getNewestAct',
timeout: 8000,
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
if ($.isEmptyObject(res.data) || res.data.status === 4) {
return showLoading('服務器正在維護中...')
2022-10-22 20:08:44 +08:00
} else {
console.log(res.timestamp > res.data.endTime);
if (res.timestamp >= res.data.endTime) { //請求的還是上一輪的數據,重新請求
console.log('請求的還是上一輪的數據,必須重新請求');
2022-09-08 18:22:18 +08:00
showLoading()
timer2 = setTimeout(() => {
getNewestAct()
}, 600);
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
clearTimeout(timer2)
hideLoading(layerIndex)
roundId = res.data.roundId
$('.game-area .roundId').html(roundId)
getListItem(roundId, modelType)
2022-09-08 18:22:18 +08:00
// 進行下一輪時arrTime重新置為空數組不然在下一輪開始的時候也會執行location.reload()
2022-10-22 20:08:44 +08:00
if (roundIdArr.length < 2) {
2022-09-08 18:22:18 +08:00
roundIdArr = [roundId, roundId]
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
roundIdArr[0] = roundIdArr[1]
roundIdArr[1] = roundId
2022-10-22 20:08:44 +08:00
if (roundIdArr[0] != roundIdArr[1]) {
2022-09-08 18:22:18 +08:00
arrTime = []
arrTime2 = []
arrTime3 = []
}
}
userComeinTime = res.timestamp
2022-10-22 20:08:44 +08:00
2022-09-08 18:22:18 +08:00
startTime = res.data.startTime
drawStageStartTime = res.data.drawStageStartTime
showResultStageStartTime = res.data.showResultStageStartTime
endTime = res.data.endTime
2022-10-22 20:08:44 +08:00
console.log('獲取5個時間戳的值-----', 'timestamp:', userComeinTime, 'startTime:', startTime, 'drawStageStartTime:', drawStageStartTime, 'showResultStageStartTime:', showResultStageStartTime, 'endTime:', endTime);
2022-09-08 18:22:18 +08:00
showView()
}
}
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
return toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
},
complete: function (XMLHttpRequest, status) {
if (status == 'timeout') {
XMLHttpRequest.abort()// 超时后中断请求
toastMsg('网络开小差,请退出重进,开奖结果可通过【游戏记录】/【往轮结果】查看~')
}
2022-09-08 18:22:18 +08:00
}
})
}
//不為3繼續請求 為3拿數據 為4彈窗
2022-10-22 20:08:44 +08:00
let status
// 顯示哪個界面
2022-09-08 18:22:18 +08:00
let $countDown
//區分倒計時到0時的區別處理的字段處於第二階段時isStatus2為真,處於第三階段時isStatus3為真
2022-09-08 18:22:18 +08:00
let isStatus2
let isStatus3
let isSelectTab = false
let mySelect
let fragmentNum
let reg = /^[0-9]*$/
const showView = () => {
2022-10-22 20:08:44 +08:00
if (startTime <= userComeinTime && userComeinTime < drawStageStartTime) {
// 第一階段
console.log('進入第一階段');
2022-09-08 18:22:18 +08:00
isSelectTab = false
$('.select-time').show().siblings().hide()
$('.roundId').show()
2022-09-08 18:22:18 +08:00
$countDown = $('.select-time .count-down .count-down-num')
2022-10-22 20:08:44 +08:00
mySelect = sessionStorage.getItem("mySelect")
if (reg.test(mySelect)) {
2022-09-08 18:22:18 +08:00
$('.btn-wrap div').eq(mySelect).addClass('active').siblings().removeClass('active')
fragmentNum = parseInt($('.btn-wrap div').eq(mySelect).html())
isSelectTab = true
2022-10-22 20:08:44 +08:00
} else {
$('.btn-wrap div').eq(0).addClass('active').siblings().removeClass('active')
fragmentNum = parseInt($('.btn-wrap div').eq(0).html())
2022-09-08 18:22:18 +08:00
isSelectTab = true
}
$('.award-wrap').html('').show()
2022-12-09 19:35:35 +08:00
// $('.award-info .desc').html('')
getPreviousResults(10, roundId)
2022-09-08 18:22:18 +08:00
showCountDown(userComeinTime, startTime, drawStageStartTime)
getUserInfo()
2022-10-22 20:08:44 +08:00
} else if (drawStageStartTime <= userComeinTime && userComeinTime < showResultStageStartTime) {
// 第二階段
console.log('進入第二階段');
sessionStorage.removeItem("mySelect")
2022-09-08 18:22:18 +08:00
$('.wait-time').show().siblings().hide()
$('.roundId').show()
2022-09-08 18:22:18 +08:00
$countDown = $('.wait-time .count-down .count-down-num')
clearTimeout(timer2s) //清除第一階段的2s氣泡定時器
2022-09-08 18:22:18 +08:00
time2sIndex = 0
isStatus2 = true //處於第二階段的標識
2022-09-08 18:22:18 +08:00
console.log('isStatus2的值------------', isStatus2);
// $('.btn-wrap').find('div').removeClass('active')
getPreviousResults(10, roundId)
2022-09-08 18:22:18 +08:00
showCountDown(userComeinTime, drawStageStartTime, showResultStageStartTime)
judgeStatus()
getUserInfo()
// 播放5s動畫
let player = new SVGA.Player('.wait-time');
let parser = new SVGA.Parser('.wait-time');
2023-02-23 10:11:40 +08:00
parser.load('./images/wait.svga', function (videoItem) {
2022-10-22 20:08:44 +08:00
// player.loops = 2;
player.clearsAfterStop = false;
player.setVideoItem(videoItem);
player.startAnimation();
})
2022-09-08 18:22:18 +08:00
2022-10-22 20:08:44 +08:00
} else if (showResultStageStartTime <= userComeinTime && userComeinTime < endTime) {
// 第三階段
console.log('進入第三階段');
2022-09-08 18:22:18 +08:00
$('.draw-time').show().siblings().hide()
$('.roundId').show()
2022-09-08 18:22:18 +08:00
$countDown = $('.draw-time .count-down .count-down-num')
isStatus3 = true //處於第三階段的標識
2022-09-08 18:22:18 +08:00
console.log('isStatus3的值------------', isStatus3);
showCountDown(userComeinTime, showResultStageStartTime, endTime)
judgeStatus()
getUserInfo()
// getPreviousResults(10, roundId)
2022-09-08 18:22:18 +08:00
}
}
// 顯示倒計時
2022-09-08 18:22:18 +08:00
let countDownTime
let deltaT
let timer
let delayTime
let interval
const showCountDown = (timestamp, startTime, endTime) => {
2022-10-22 20:08:44 +08:00
deltaT = ((endTime - startTime) - (timestamp - startTime)) / 1000 //12.361
if (deltaT >= 1) {
2022-09-08 18:22:18 +08:00
interval = 1
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
interval = 0
}
2022-10-22 20:08:44 +08:00
console.log('deltaT----------', deltaT);
countDownTime = Math.floor(deltaT) //12.361 => 12
delayTime = deltaT - countDownTime //請求接口的延遲時間
2022-09-08 18:22:18 +08:00
$countDown.html(countDownTime)
timer = setInterval(() => {
2022-10-22 20:08:44 +08:00
if (browser.ios) {
if (!isStatus3 && !isStatus2) {
// 處理第一階段
2022-10-22 20:08:44 +08:00
if (arrTime.length < 2) {
2022-09-08 18:22:18 +08:00
arrTime = [new Date().getTime(), new Date().getTime()]
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
arrTime[0] = arrTime[1]
arrTime[1] = new Date().getTime()
2022-10-22 20:08:44 +08:00
if ((arrTime[1] - arrTime[0]) / 1000 > 1.5) {
2022-09-08 18:22:18 +08:00
window.location.reload()
}
}
2022-10-22 20:08:44 +08:00
} else if (isStatus2) {
// 第二階段也要處理
2022-10-22 20:08:44 +08:00
if (arrTime2.length < 2) {
2022-09-08 18:22:18 +08:00
arrTime2 = [new Date().getTime(), new Date().getTime()]
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
arrTime2[0] = arrTime2[1]
arrTime2[1] = new Date().getTime()
2022-10-22 20:08:44 +08:00
if ((arrTime2[1] - arrTime2[0]) / 1000 > 1.5) {
2022-09-08 18:22:18 +08:00
window.location.reload()
}
}
2022-10-22 20:08:44 +08:00
} else if (isStatus3) {
// 第三階段也要處理
2022-10-22 20:08:44 +08:00
if (arrTime3.length < 2) {
2022-09-08 18:22:18 +08:00
arrTime3 = [new Date().getTime(), new Date().getTime()]
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
arrTime3[0] = arrTime3[1]
arrTime3[1] = new Date().getTime()
2022-10-22 20:08:44 +08:00
if ((arrTime3[1] - arrTime3[0]) / 1000 > 1.5) {
2022-09-08 18:22:18 +08:00
window.location.reload()
}
}
}
}
countDownTime--
2022-10-22 20:08:44 +08:00
if (countDownTime <= 0) {
$countDown.html(0)
2022-09-08 18:22:18 +08:00
clearInterval(timer)
2022-10-22 20:08:44 +08:00
if (isStatus2) { // 倒計時為0時處於第二階段的處理
if (status) {
2022-09-08 18:22:18 +08:00
// hideLoading(layerIndex)
setTimeout(() => {
getNewestAct()
}, delayTime * 1000)
isStatus2 = false
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
showLoading()
// toastMsg('服務器繁忙,請稍等')
2022-10-22 20:08:44 +08:00
console.log('status的值-----------', status);
2022-09-08 18:22:18 +08:00
judgeStatus()
}
2022-10-22 20:08:44 +08:00
} else if (isStatus3) { //倒計時為0時處於第三階段的處理
2022-09-08 18:22:18 +08:00
setTimeout(() => {
getNewestAct()
// getListItem(roundId)
}, delayTime * 1000)
// getNewestAct()
// getListItem()
isStatus3 = false
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
setTimeout(() => {
getNewestAct()
}, delayTime * 1000)
}
2022-10-22 20:08:44 +08:00
2022-09-08 18:22:18 +08:00
// else {
// setTimeout(() => {
// getNewestAct()
// }, delayTime * 1000)
// }
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
$countDown.html(countDownTime)
}
}, interval * 1000)
}
//判斷status的狀態
2022-09-08 18:22:18 +08:00
let timer4
let drawInfo
let img //第三階段的中獎動物img
2022-09-08 18:22:18 +08:00
const judgeStatus = () => {
console.log('進入二階段時輪詢查看結果是否已經出了');
2022-09-08 18:22:18 +08:00
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getNewestAct',
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
console.log('res.data的值------------', res.data);
if ($.isEmptyObject(res.data) || res.data.status === 4) {
2022-09-08 18:22:18 +08:00
console.log('程序崩了!!!');
return showLoading('服務器正在維護中...')
2022-10-22 20:08:44 +08:00
} else if (res.data.status === 3) {
2022-09-08 18:22:18 +08:00
clearTimeout(timer4)
status = true
2022-10-22 20:08:44 +08:00
if (isStatus2 && countDownTime <= 0) {
2022-09-08 18:22:18 +08:00
showCountDown(userComeinTime, drawStageStartTime, showResultStageStartTime)
}
// hideLoading(layerIndex)
2022-10-22 20:08:44 +08:00
console.log('status為3時返回的數據--------------', res.data);
2022-09-08 18:22:18 +08:00
drawInfo = res.data
img = res.data.drawImageUrl
2022-10-22 20:08:44 +08:00
if (isStatus3) {
getPreviousResults(10, roundId)
2022-09-08 18:22:18 +08:00
}
renderDrawInfo()
2022-10-22 20:08:44 +08:00
} else {
timer4 = setTimeout(() => {
judgeStatus()
}, 1000)
2022-09-08 18:22:18 +08:00
}
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
2022-09-08 18:22:18 +08:00
}
})
}
// 渲染開獎信息
2022-09-08 18:22:18 +08:00
let topThreeArr = []
const renderDrawInfo = () => {
$('.draw-time .current-tip .current-result').html(drawInfo.drawName)
2022-09-08 18:22:18 +08:00
$('.draw-pic img').attr('src', drawInfo.drawImageUrl)
2022-12-09 19:35:35 +08:00
// if (isStatus3) {
// if (drawInfo.userDrawResult.drawStatus === 1) {
// $('.award-info .desc').html('恭喜你,猜中了!')
// // if (modelType === 1) {
// // $('.award-wrap').html(`獲得 <span class="award-total">${drawInfo.userDrawResult.prizeDiamonds} </span>鉆石`)
// // } else {
// // $('.award-wrap').html(`獲得 <span class="award-name">${drawInfo.userDrawResult.prizeName} </span>(<span class="awrad-price">${drawInfo.userDrawResult.prizePrice}</span>鉆)*<span class="award-num">${drawInfo.userDrawResult.prizeCount}</span>個 累計<span class="award-total">${drawInfo.userDrawResult.prizeDiamonds}</span>鉆石`)
// // }
// } else if (drawInfo.userDrawResult.drawStatus === 2) {
// $('.award-info .desc').html('很遺憾,本輪未猜中')
// $('.award-wrap').hide()
// } else if (drawInfo.userDrawResult.drawStatus === 3) {
// $('.award-info .desc').html('本輪未參與')
// $('.award-wrap').hide()
// }
// }
$('.put-wrap .list .item').remove()
// 渲染投入列表
let list = ''
drawInfo.userDrawResult.drawRecords.map(res => {
list += `
<div class="item">
<p><img src="${res.imgUrl}" class="gift" alt=""></p>
<div>
2023-02-23 10:11:40 +08:00
<img src="./images/diamond.png" class="diamond" alt="">
2022-12-09 19:35:35 +08:00
<span class="in">${res.costPieceNum}</span>
</div>
</div>
`
});
$('.put-wrap .list').append(list)
$('.award-info .award-wrap').html(drawInfo.userDrawResult.prizeDiamonds)
2022-09-08 18:22:18 +08:00
// 渲染前三名
topThreeArr = drawInfo.rankUserList
let str = ''
2022-10-22 20:08:44 +08:00
if (topThreeArr.length === 0) {
$('.topthree-desc').html('本輪無人猜中')
2022-12-09 19:35:35 +08:00
$('.top-three-list').css('display', 'none')
$('.top-three').css('line-height', '4rem')
// $('.top-three-list p img').attr('src', './images/default-hui.png')
2022-10-22 20:08:44 +08:00
} else {
2022-12-09 19:35:35 +08:00
$('.topthree-desc').html('本輪MVP')
$('.top-three-list').css('display', 'block')
$('.top-three').css('line-height', '0rem')
if (topThreeArr.length < 3) {
let arr = new Array(3 - topThreeArr.length).fill({
avatar: './images/default-hui.png',
nick: '虚位以待',
uid: null,
num: 0
})
topThreeArr.push(...arr)
};
2022-10-22 20:08:44 +08:00
topThreeArr.map((item, index) => {
2022-12-09 19:35:35 +08:00
$(`.top-three-list .no${index + 1} .tx`).attr('uid', item.uid)
$(`.top-three-list .no${index + 1} .tx`).attr('src', item.avatar)
$(`.top-three-list .no${index + 1} .nick`).html(item.nick)
$(`.top-three-list .no${index + 1} .num span`).html(item.prizeDiamonds)
2022-09-08 18:22:18 +08:00
})
}
2022-12-09 19:35:35 +08:00
2022-09-08 18:22:18 +08:00
}
// 獲取每一輪抽獎的相關配置
2022-09-08 18:22:18 +08:00
let listItem = []
const getListItem = (roundId, type) => {
2022-09-08 18:22:18 +08:00
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/listItem',
data: {
roundId,
type
2022-09-08 18:22:18 +08:00
},
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
2022-09-08 18:22:18 +08:00
listItem = res.data
renderListItem()
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
2022-09-08 18:22:18 +08:00
}
})
}
// 2s氣泡定時器
2022-09-08 18:22:18 +08:00
let timer2s
2022-10-22 20:08:44 +08:00
let time2sIndex = 0
2022-09-08 18:22:18 +08:00
const setTimeout2s = () => {
2022-10-22 20:08:44 +08:00
clearTimeout(timer2s)
2022-09-08 18:22:18 +08:00
$('.bubble-2s').eq(time2sIndex).fadeIn(50)
2022-10-22 20:08:44 +08:00
timer2s = setTimeout(function () {
2022-09-08 18:22:18 +08:00
$('.bubble-2s').eq(time2sIndex).fadeOut(50)
2022-10-22 20:08:44 +08:00
if (time2sIndex >= listItem.length - 1) {
2022-09-08 18:22:18 +08:00
time2sIndex = 0
2022-10-22 20:08:44 +08:00
} else {
2022-09-08 18:22:18 +08:00
time2sIndex++;
}
setTimeout2s()
}, 2000)
}
// 渲染每一輪抽獎的選項
2022-09-08 18:22:18 +08:00
const renderListItem = () => {
let str = ''
2022-10-22 20:08:44 +08:00
if (modelType === 1) {
listItem.map((item) => {
str += `
<li data-total-num={"number":"${item.costPieceNum}","id":"${item.id}"}>
<img src="${item.imgUrl}" alt="">
<div class="multiple">x${item.multiple}</div>
<div class="name general">${item.name}</div>
<div class="bubble-2s">
<p class="first-line">點擊選取</p>
<p class="second-line"> <span>${item.multiple}</span> </p>
</div>
<div class="select-num">${item.costPieceNum === 0 ? '' : '+ ' + item.costPieceNum}</div>
</li>
`
})
2022-10-22 20:08:44 +08:00
} else {
listItem.map((item) => {
str += `
<li data-total-num={"number":"${item.costPieceNum}","id":"${item.id}"}>
<img src="${item.imgUrl}" alt="">
<div class="multiple">x${item.multiple}</div>
2022-10-22 20:08:44 +08:00
<div class="name">${item.name} <p class="gift-price">${item.price ? `(${item.price}鉆石)` : ''}</p></div>
<div class="bubble-2s">
<p class="first-line">點擊選取</p>
<p class="second-line"> <span>${item.multiple}</span> </p>
</div>
<div class="select-num">${item.costPieceNum === 0 ? '' : '+ ' + item.costPieceNum}</div>
</li>
`
})
}
2022-09-08 18:22:18 +08:00
$('.game-area').find('ul').html(str)
setTimeout2s()
}
// 獲取往輪遊戲結果
2022-09-08 18:22:18 +08:00
let previousResults = []
const getPreviousResults = (count, roundId) => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/listLuckySeaActInfo',
2022-10-22 20:08:44 +08:00
data: {
2022-09-08 18:22:18 +08:00
count,
roundId
},
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
2022-09-08 18:22:18 +08:00
previousResults = res.data
renderPreviousResults()
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
2022-09-08 18:22:18 +08:00
}
})
}
// 渲染往輪遊戲結果
2022-09-08 18:22:18 +08:00
const renderPreviousResults = () => {
2022-10-22 20:08:44 +08:00
2022-09-08 18:22:18 +08:00
let str = ''
2022-10-22 20:08:44 +08:00
if (previousResults.length < 5) {
2022-09-08 18:22:18 +08:00
let len = 5 - previousResults.length
let arr = new Array(len).fill(1)
previousResults.push(...arr)
}
2022-10-22 20:08:44 +08:00
if (isStatus3) {
if (img) {
2022-09-08 18:22:18 +08:00
previousResults.pop()
previousResults.unshift({
drawImageUrl: img
})
console.log(previousResults);
}
2022-10-22 20:08:44 +08:00
2022-09-08 18:22:18 +08:00
}
previousResults.map((item) => {
str += `
<p><img src="${item.drawImageUrl}" alt=""></p>
`
})
$('.result-list').html(str)
}
// 發送用戶抽獎數量
const sendUserDrawInfo = (itemId, num, tais) => {
showLoading();
2022-09-08 18:22:18 +08:00
networkRequest({
type: 'POST',
url: urlPrefix + '/act/luckySea/draw',
// contentType: 'application/json',
// data: `[ {
// "itemId":${itemId},
// "num":${num}
// }]`,
data: { itemId, num },
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
tais.data('total-num').number = parseInt(tais.data('total-num').number) + fragmentNum
tais
.stop(true, true)
.animate({ scale: 1.1 }, 200)
.animate({ scale: 1 }, 200, function () {
if (lock) {
tais.find('.select-num').html('+' + tais.data('total-num').number).hide().fadeIn(200)
}
setTimeout(() => {
// getUserInfo()
getUserPieceNum()
// getListItem(roundId)
}, 100)
})
hideLoading(layerIndex)
} else if (31005) {
lock = !lock
2022-10-22 20:08:44 +08:00
toastMsg(res.message)
hideLoading(layerIndex)
}
2022-10-22 20:08:44 +08:00
else {
lock = !lock
2022-09-08 18:22:18 +08:00
toastMsg(res.message)
hideLoading(layerIndex)
2022-09-08 18:22:18 +08:00
}
},
error (err) {
lock = !lock
toastMsg('網絡錯誤,請退出重進')
hideLoading(layerIndex)
2022-09-08 18:22:18 +08:00
}
})
}
/******************************************** 今日排名相關 ********************************************/
// 榜單類型1是鉆石榜2是歐皇榜
let type = 1
let pageSize = 20
// 鉆石榜單
let pageD = 1
let myInfoD = []
let rankListD = []
// 歐皇榜單
let pageN = 1
let myInfoN = []
let rankListN = []
2022-10-22 20:08:44 +08:00
let clickTabCanNetworkN = true
let isLockD = true
let isLockN = true
let isLock = true
let canRequsetNextPageD = true
let canRequsetNextPageN = true
2022-10-22 20:08:44 +08:00
const getListRank = (type, page) => {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/listRank',
2022-10-22 20:08:44 +08:00
data: {
type,
page,
pageSize
},
success (res) {
2022-10-22 20:08:44 +08:00
if (res.code === 200) {
if (type === 1) {
// 鉆石榜單
2022-10-22 20:08:44 +08:00
if (res.data.rankList.length === pageSize) {
// 可以請求下一頁
canRequsetNextPageD = true
2022-10-22 20:08:44 +08:00
} else {
// 不再請求下一頁
canRequsetNextPageD = false
}
rankListD.push(...res.data.rankList)
myInfoD = res.data.myRankInfo
renderMyInfo()
renderRankList()
isLockD = true
2022-10-22 20:08:44 +08:00
} else {
if (res.data.rankList.length === pageSize) {
// 可以請求下一頁
canRequsetNextPageN = true
2022-10-22 20:08:44 +08:00
} else {
// 不再請求下一頁
canRequsetNextPageN = false
}
rankListN.push(...res.data.rankList)
myInfoN = res.data.myRankInfo
renderMyInfo()
renderRankList()
isLockN = true
}
2022-10-22 20:08:44 +08:00
} else {
toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤')
}
})
}
// 渲染底部個人信息
const renderMyInfo = () => {
2022-10-22 20:08:44 +08:00
if (type === 1) {
// 鉆石榜單
let erbanNo = myInfoD.erbanNo
let myIndex = rankListD.findIndex((item, index) => {
return item.erbanNo === erbanNo
})
2022-10-22 20:08:44 +08:00
if (myIndex === -1) {
$('.mine-rank').html('未上榜')
2022-10-22 20:08:44 +08:00
} else {
$('.mine-rank').html(myIndex + 1)
}
$('.mine-info').find('img').attr('src', myInfoD.avatar)
2022-10-22 20:08:44 +08:00
if (myInfoD.nick) {
myInfoD.nick.length > 5 ? myInfoD.nick.slice(0, 5) + '...' : myInfoD.nick
2022-10-22 20:08:44 +08:00
} else {
myInfoD.nick = '未知'
}
$('.mine-info').find('.mine-nick').html(myInfoD.nick)
let tostr = myInfoD.num.toString()
let num
2022-10-22 20:08:44 +08:00
if (tostr.length >= 5) {
num = (myInfoD.num / 10000).toFixed(2) + 'w'
} else {
num = myInfoD.num
}
// $('.mine-diamond-num').html('今日獎勵' + num)
$('.mine-diamond-num').html(num)
2022-10-22 20:08:44 +08:00
} else {
let erbanNo = myInfoN.erbanNo
let myIndex = rankListN.findIndex((item, index) => {
return item.erbanNo === erbanNo
})
2022-10-22 20:08:44 +08:00
if (myIndex === -1) {
$('.mine-rank').html('未上榜')
2022-10-22 20:08:44 +08:00
} else {
$('.mine-rank').html(myIndex + 1)
}
$('.mine-info').find('img').attr('src', myInfoN.avatar)
2022-10-22 20:08:44 +08:00
if (myInfoN.nick) {
myInfoN.nick.length > 5 ? myInfoN.nick.slice(0, 5) + '...' : myInfoN.nick
2022-10-22 20:08:44 +08:00
} else {
myInfoN.nick = '未知'
}
$('.mine-info').find('.mine-nick').html(myInfoN.nick)
$('.mine-diamond-num').html('猜中' + myInfoN.num + '次')
}
}
// 渲染榜單信息
const renderRankList = () => {
2022-10-22 20:08:44 +08:00
if (type === 1) {
// 鉆石榜單
// 渲染前3
let topThreeArr = rankListD.slice(0, 1)
2022-10-22 20:08:44 +08:00
if (rankListD.length === 0) {
let len = 1 - rankListD.length
let arr = new Array(len).fill({
nick: '虛位以待',
avatar: './images/default.png',
num: ''
})
topThreeArr.push(...arr)
}
let topThreeStr = ''
topThreeArr.map((item) => {
let tostr = item.num.toString()
let num
2022-10-22 20:08:44 +08:00
if (tostr.length >= 5) {
num = (item.num / 10000).toFixed(2) + 'w'
} else {
num = item.num
}
2022-10-22 20:08:44 +08:00
topThreeStr = `
<div class="info-wrap" uid="${item.uid}">
<div class="avatar">
<p></p>
<img src="${item.avatar}" alt="">
</div>
<p class="diamond-num">${num}</p>
2022-10-22 20:08:44 +08:00
<p class="nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</p>
</div>
`
})
$('.topthree-wrap').html(topThreeStr)
$('.topthree-wrap .info-wrap').click(function () {
let uid = $(this).attr('uid')
openPerson(uid)
})
2022-10-22 20:08:44 +08:00
// 渲染非前3
let othersArr = rankListD.slice(1)
let others = ''
othersArr.map((item, index) => {
let tostr = item.num.toString()
let num
2022-10-22 20:08:44 +08:00
if (tostr.length >= 5) {
num = (item.num / 10000).toFixed(2) + 'w'
} else {
num = item.num
}
others += `
<li uid="${item.uid}">
2022-10-22 20:08:44 +08:00
<span class="index">${index + 2}</span>
<div class="others-info">
<img src="${item.avatar}" alt="">
2022-10-22 20:08:44 +08:00
<span class="others-nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</span>
</div>
<span class="others-diamond-num">${num}</span>
</li>
`
})
$('.other-rank').html(others)
$('.other-rank li').click(function () {
let uid = $(this).attr('uid')
openPerson(uid)
})
2022-10-22 20:08:44 +08:00
} else {
// 歐皇榜單
// 渲染前3
let topThreeArr = rankListN.slice(0, 1)
2022-10-22 20:08:44 +08:00
if (rankListN.length === 0) {
let len = 1 - rankListN.length
let arr = new Array(len).fill({
nick: '虛位以待',
avatar: './images/default.png'
})
topThreeArr.push(...arr)
}
let topThreeStr = ''
topThreeArr.map((item) => {
let num = ''
2022-10-22 20:08:44 +08:00
if (item.erbanNo) {
num = '猜中' + item.num + '次'
}
topThreeStr = `
<div class="info-wrap" uid="${item.uid}">
<div class="avatar">
<p></p>
<img src="${item.avatar}" alt="">
</div>
<p class="diamond-num" style="display:block">${num}</p>
2022-10-22 20:08:44 +08:00
<p class="nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</p>
</div>
`
})
$('.topthree-wrap').html(topThreeStr)
$('.topthree-wrap .info-wrap').click(function () {
let uid = $(this).attr('uid')
openPerson(uid)
})
// 渲染非前3
let othersArr = rankListN.slice(1)
console.log(othersArr);
let others = ''
othersArr.map((item, index) => {
let num
2022-10-22 20:08:44 +08:00
if (item.erbanNo) {
num = '猜中' + item.num + '次'
}
others += `
<li uid="${item.uid}">
2022-10-22 20:08:44 +08:00
<span class="index">${index + 2}</span>
<div class="others-info">
<img src="${item.avatar}" alt="">
2022-10-22 20:08:44 +08:00
<span class="others-nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</span>
</div>
<span class="others-diamond-num">${num}</span>
</li>
`
})
$('.other-rank').html(others)
$('.other-rank li').click(function () {
let uid = $(this).attr('uid')
openPerson(uid)
})
}
2022-10-22 20:08:44 +08:00
}
//跳转个人主页
function openPerson (uid) {
console.log('跳转个人主页方法');
if (!browser.app) return
if (browser.ios) {
window.webkit.messageHandlers.openPersonPage.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openPersonPage(uid);
}
}
}
2022-10-22 20:08:44 +08:00
$(function () {
2022-09-08 18:22:18 +08:00
getInfoFromClient()
2022-10-22 20:08:44 +08:00
setTimeout(function () {
2022-09-08 18:22:18 +08:00
// getUserInfo()
getGameMode()
// getNewestAct()
2022-09-08 18:22:18 +08:00
// getListItem()
$('.recharge').click(function () {
// if (browser.app) {
// if (browser.ios) {
// window.location.href = 'https://api.pekolive.com/peko/modules/pay/index.html?channelType=4';
// } else {
// if (browser.android) {
// let channel = pubInfo.deviceInfo.channel
// console.log(channel);
// if (channel.search('official') != -1) {
// window.androidJsObj.openChargePage();
// } else if (channel.search('official') != -1) {
// window.androidJsObj.openChargePage();
// }
// }
// }
// }
if (browser.app) {
if (browser.android) {
2022-12-09 19:35:35 +08:00
window.androidJsObj.openChargePage(6);
} else if (browser.ios) {
2022-12-09 19:35:35 +08:00
window.webkit.messageHandlers.chargePayClickPage.postMessage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
}
})
2022-09-08 18:22:18 +08:00
}, 50)
// 監聽按鈕點擊事件
2022-09-08 18:22:18 +08:00
// let fragmentNum
// let isSelectTab = false
2022-10-22 20:08:44 +08:00
$('.btn-wrap').on('click', 'div', function () {
2022-09-08 18:22:18 +08:00
$(this).addClass('active').siblings().removeClass('active')
fragmentNum = parseInt($(this).html())
2022-09-08 18:22:18 +08:00
isSelectTab = true
sessionStorage.setItem("mySelect", $(this).index())
})
// 監聽規則按鈕點擊事件
2022-10-22 20:08:44 +08:00
$('.rule').on('click', function () {
2022-09-08 18:22:18 +08:00
$('.shade-mask').show()
})
// 關閉規則彈窗
2022-10-22 20:08:44 +08:00
$('.shade-mask').on('click', function () {
2022-09-08 18:22:18 +08:00
$(this).hide()
})
2022-10-22 20:08:44 +08:00
$('.shade-content').on('click', function (e) {
2022-09-08 18:22:18 +08:00
e.stopPropagation()
})
// 跳轉特權商城
2022-10-22 20:08:44 +08:00
$('.mall').on('click', function () {
window.location.href = './mall.html'
})
// +按钮跳转充值
2022-10-22 20:08:44 +08:00
$('.add').on('click', function () {
if (browser.app) {
if (browser.android) {
let channel = pubInfo.deviceInfo.channel;
console.log(pubInfo.deviceInfo);
if (channel == "google") {
window.androidJsObj.openChargePage(6);
} else {
window.androidJsObj.openChargePage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
} else if (browser.ios) {
window.webkit.messageHandlers.chargePayClickPage.postMessage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
} else {
toastMsg('請在app內打開')
}
})
// 監聽遊戲記錄按鈕點擊事件
2022-10-22 20:08:44 +08:00
$('.record').on('click', function () {
2022-09-08 18:22:18 +08:00
window.location.href = './record.html'
})
// 监听历史开奖记录按钮点击事件
$('.more-result').on('click', function () {
window.location.href = './result.html?roundId=' + roundId
})
// 監聽今日排名按鈕點擊事件
2022-10-22 20:08:44 +08:00
$('.rank').on('click', function () {
getListRank(type, pageD)
$('.shade-mask-rank').show()
2022-09-08 18:22:18 +08:00
})
// 監聽今日排名tab
2022-10-22 20:08:44 +08:00
$('.tab-wrap').on('click', 'span', function () {
$(this).addClass('active').siblings().removeClass('active')
2022-10-22 20:08:44 +08:00
if (type === $(this).index() + 1) return
type = $(this).index() + 1
$('.other-rank').scrollTop(0)
2022-10-22 20:08:44 +08:00
if (type === 1) {
renderRankList()
renderMyInfo()
2022-10-22 20:08:44 +08:00
} else {
if (clickTabCanNetworkN) {
getListRank(type, pageN)
2022-10-22 20:08:44 +08:00
} else {
renderRankList()
renderMyInfo()
}
clickTabCanNetworkN = false
}
2022-09-08 18:22:18 +08:00
})
// 關閉排名彈窗
2022-10-22 20:08:44 +08:00
$('.shade-mask-rank').on('click', function () {
$(this).hide()
type = 1
pageD = 1
pageN = 1
myInfoD = []
myInfoN = []
rankListD = []
rankListN = []
clickTabCanNetworkN = true
$('.diamond-rank').addClass('active').siblings('.num-rank').removeClass('active')
$('.other-rank').html('')
})
2022-10-22 20:08:44 +08:00
$('.shade-content-rank').on('click', function (e) {
e.stopPropagation()
})
// 監聽滾動
// $('.other-rank').on('scroll', function () {
// let scrollTop = $(this).scrollTop();//這是已經卷進去滾動條的的高度
// let scrollHeight = $('.other-rank')[0].scrollHeight;//這個是other-rank包含滾動條的總高度
// let ulHeight = $(this).innerHeight();//這個是other-rank的高度
// //這樣距離到底還有一段距離就請求,但是會導致重復請求,所以要加鎖限製
// if (scrollTop + ulHeight + 100 >= scrollHeight) {
// if (type === 1) {
// if (isLockD) {
// isLockD = false
// pageD++
// if (pageSize * pageD > 30) {
// toastMsg('沒有更多數據啦~')
// } else {
// if (canRequsetNextPageD) {
// getListRank(type, pageD);
// } else {
// toastMsg('沒有更多數據啦~')
// }
// }
// } else {
// if (scrollTop + ulHeight >= scrollHeight) {
// if (pageSize * pageD > 30) {
// toastMsg('沒有更多數據啦~')
// }
// }
// }
// } else {
// if (isLockN) {
// isLockN = false
// pageN++
// if (pageSize * pageN > 30) {
// toastMsg('沒有更多數據啦~')
// } else {
// if (canRequsetNextPageN) {
// getListRank(type, pageN);
// } else {
// toastMsg('沒有更多數據啦')
// }
// }
// } else {
// if (scrollTop + ulHeight >= scrollHeight) {
// if (pageSize * pageN > 30) {
// toastMsg('沒有更多數據啦~')
// }
// }
// }
// }
// }
// })
2022-10-22 20:08:44 +08:00
// 播放3s動畫
2022-12-09 19:35:35 +08:00
// let player1 = new SVGA.Player('.draw-time');
// let parser1 = new SVGA.Parser('.draw-time');
// parser1.load('./images/draw.svga', function (videoItem) {
// // player.loops = 2;
// player1.clearsAfterStop = false;
// player1.setVideoItem(videoItem);
// player1.startAnimation();
// })
// 点击跳转个人主页
// $('.draw-time .top-three .top-three-list .no').off()
$('.draw-time .top-three .top-three-list .no').click(function () {
let uid = $(this).find('.tx').attr('uid');
console.log('uid', uid);
openPerson(uid)
})
// 關閉碎片不足提示彈窗
2022-10-22 20:08:44 +08:00
$('.cancel-btn').on('click', function () {
$('.shade-mask-fragmentNum').hide()
})
2022-10-22 20:08:44 +08:00
$('.shade-mask-fragmentNum').on('click', function () {
$(this).hide()
})
2022-10-22 20:08:44 +08:00
$('.shade-content-fragmentNum').on('click', function (e) {
e.stopPropagation()
})
2022-10-22 20:08:44 +08:00
$('.confirm-btn').on('click', function () {
// window.location.href = './mall.html'
if (browser.app) {
if (browser.android) {
let channel = pubInfo.deviceInfo.channel;
2022-10-22 20:08:44 +08:00
console.log(pubInfo.deviceInfo);
if (channel == "google") {
window.androidJsObj.openChargePage(6);
2022-10-22 20:08:44 +08:00
} else {
window.androidJsObj.openChargePage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
2022-10-22 20:08:44 +08:00
}
} else if (browser.ios) {
window.webkit.messageHandlers.chargePayClickPage.postMessage(6);
2022-10-22 20:08:44 +08:00
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
} else {
toastMsg('請在app內打開')
2022-10-22 20:08:44 +08:00
}
$('.shade-mask-fragmentNum').hide()
})
2022-10-22 20:08:44 +08:00
// 點擊海鮮動物的動畫以及發送請求
2022-10-22 20:08:44 +08:00
$('.select-time ul').on('click', 'li', function () {
if (!isSelectTab) {
return toastMsg('請先選擇碎片數量')
}
2022-10-22 20:08:44 +08:00
if (myFragment < fragmentNum) {
$('.shade-mask-fragmentNum').show()
2022-10-22 20:08:44 +08:00
// toastMsg('鉆石余額不足');
return
2022-09-08 18:22:18 +08:00
}
2022-10-22 20:08:44 +08:00
if (!lock) {
2022-09-08 18:22:18 +08:00
lock = !lock
// console.log($(this).data('total-num'));
// console.log($(this).data('total-num').number);
// console.log(fragmentNum);
// $(this).data('total-num').number = parseInt($(this).data('total-num').number) + fragmentNum
// $(this)
// .stop(true, true)
// .animate({ scale: 1.1 }, 200)
// .animate({ scale: 1 }, 200, function () {
// if (lock) {
// $(this).find('.select-num').html('+' + $(this).data('total-num').number).hide().fadeIn(200)
// }
// setTimeout(() => {
// // getUserInfo()
// getUserPieceNum()
// // getListItem(roundId)
// }, 100)
// })
sendUserDrawInfo($(this).data('total-num').id, fragmentNum, $(this))
2022-09-08 18:22:18 +08:00
}
})
2022-10-22 20:08:44 +08:00
// ios去到後臺或者鎖屏後再回來倒計時不準確
2022-09-08 18:22:18 +08:00
let leftTime, deltaTime, startTime, endTime
2022-10-22 20:08:44 +08:00
document.addEventListener('visibilitychange', function () {
if (document.visibilityState == 'hidden') {
2022-09-08 18:22:18 +08:00
leftTime = countDownTime
startTime = new Date().getTime()
2022-10-22 20:08:44 +08:00
} else if (document.visibilityState == 'visible') {
2022-09-08 18:22:18 +08:00
endTime = new Date().getTime()
2022-10-22 20:08:44 +08:00
deltaTime = Math.floor((endTime - startTime) / 1000) //出去了多久
if (deltaTime > 300) {
2022-09-08 18:22:18 +08:00
window.location.reload()
}
countDownTime = leftTime - deltaTime
2022-10-22 20:08:44 +08:00
if (countDownTime < 0) {
2022-09-08 18:22:18 +08:00
countDownTime = 0
}
$countDown.html(countDownTime)
}
})
})