611 lines
23 KiB
JavaScript
611 lines
23 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
|
let browser = checkVersion()
|
|
let queryObj = getQueryString()
|
|
if (EnvCheck() === 'test') new VConsole
|
|
// 封装layer消息提醒框
|
|
let layerIndex
|
|
const showLoading = () => {
|
|
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'
|
|
})
|
|
}
|
|
|
|
let showReceiveRankTotal //是否展示总榜
|
|
let showMonthList
|
|
// 获取后台配置信息
|
|
const getShowInfo = () => {
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/room/rankings/showInfo',
|
|
data: {
|
|
roomUid: queryObj.roomUid
|
|
},
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
showReceiveRankTotal = res.data.showReceiveRankTotal
|
|
showMonthList = res.data.showMonthList
|
|
if (res.data.showMonthList) {
|
|
$('title').text('主播榜');
|
|
// $('.wrap .tab_wrap').hide();
|
|
// $('.wrap .rank_wrap .top_three_wrap').css("margin-top", "0");
|
|
// $('.wrap .rank_wrap ul').css("height", "6.4rem");
|
|
$('.wrap .tab_wrap .rank_type p:last-child').text('月榜');
|
|
$('.wrap .tab_wrap .tab_contain p').eq(0).text('贡献榜')
|
|
$('.wrap .tab_wrap .rank_type p:last-child').show();
|
|
getList('day')
|
|
$('.wrap').show()
|
|
} else {
|
|
$('.wrap').show()
|
|
if (showReceiveRankTotal) {
|
|
$('.rank_type p').eq(2).show()
|
|
} else {
|
|
$('.rank_type p').eq(2).hide()
|
|
}
|
|
getList('day')
|
|
}
|
|
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
},
|
|
error(err) {
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
|
|
let page = 1
|
|
let pageSize = 10
|
|
let rankList = []
|
|
let isLock = true
|
|
let dayListNext = true
|
|
let weekListNext = true
|
|
let monthListNext = true
|
|
let totalListNext = true
|
|
let dayCharmListNext = true
|
|
let weekCharmListNext = true
|
|
let monthCharmListNext = true
|
|
let totalCharmListNext = true
|
|
|
|
// 获取财富榜数据
|
|
const getList = (type, page = 1) => {
|
|
console.log('贡献榜');
|
|
console.log(type);
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/room/rankings',
|
|
data: {
|
|
type,
|
|
page,
|
|
pageSize,
|
|
roomUid: queryObj.roomUid
|
|
},
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
if (res.data.rankings.length === pageSize) {
|
|
// 能够继续请求下一页
|
|
if (type == 'day') {
|
|
dayListNext = true
|
|
} else if (type == 'week') {
|
|
weekListNext = true
|
|
} else if (type == 'month') {
|
|
monthListNext = true
|
|
} else {
|
|
totalListNext = true
|
|
}
|
|
} else {
|
|
if (type == 'day') {
|
|
dayListNext = false
|
|
} else if (type == 'week') {
|
|
weekListNext = false
|
|
} else if (type == 'month') {
|
|
monthListNext = false
|
|
} else {
|
|
totalListNext = false
|
|
}
|
|
}
|
|
rankList.push(...res.data.rankings)
|
|
if (showMonthList) {
|
|
if (type == 'day') {
|
|
sessionStorage.setItem('dayList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else if (type == 'week') {
|
|
sessionStorage.setItem('weekList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else if (type == 'month') {
|
|
sessionStorage.setItem('monthList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('monthList'))
|
|
}
|
|
} else {
|
|
if (type == 'day') {
|
|
sessionStorage.setItem('dayList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else if (type == 'week') {
|
|
sessionStorage.setItem('weekList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else if (type == 'total') {
|
|
sessionStorage.setItem('totalList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('totalList'))
|
|
}
|
|
}
|
|
isLock = true
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
},
|
|
error(err) {
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
|
|
// 获取魅力榜数据
|
|
const getCharmList = (type, page = 1) => {
|
|
console.log('魅力榜');
|
|
console.log(type);
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/room/recive/rankings',
|
|
data: {
|
|
type,
|
|
page,
|
|
pageSize,
|
|
roomUid: queryObj.roomUid
|
|
},
|
|
success(res) {
|
|
if (res.code === 200) {
|
|
if (res.data.rankings.length === pageSize) {
|
|
// 能够继续请求下一页
|
|
if (type == 'day') {
|
|
dayCharmListNext = true
|
|
} else if (type == 'week') {
|
|
weekCharmListNext = true
|
|
} else if (type == 'month') {
|
|
monthCharmListNext = true
|
|
} else {
|
|
totalCharmListNext = true
|
|
}
|
|
} else {
|
|
if (type == 'day') {
|
|
dayCharmListNext = false
|
|
} else if (type == 'week') {
|
|
weekCharmListNext = false
|
|
} else if (type == 'month') {
|
|
monthCharmListNext = false
|
|
} else {
|
|
totalCharmListNext = false
|
|
}
|
|
}
|
|
rankList.push(...res.data.rankings)
|
|
if (showMonthList) {
|
|
if (type == 'day') {
|
|
sessionStorage.setItem('dayCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else if (type == 'week') {
|
|
sessionStorage.setItem('weekCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else if (type == 'month') {
|
|
sessionStorage.setItem('monthCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('monthCharmList'))
|
|
}
|
|
} else {
|
|
if (type == 'day') {
|
|
sessionStorage.setItem('dayCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else if (type == 'week') {
|
|
sessionStorage.setItem('weekCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else if (type == 'total') {
|
|
sessionStorage.setItem('totalCharmList', JSON.stringify(rankList))
|
|
renderList(sessionStorage.getItem('totalCharmList'))
|
|
}
|
|
}
|
|
|
|
// renderList()
|
|
isLock = true
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
},
|
|
error(err) {
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
|
|
const renderList = (List) => {
|
|
let list = JSON.parse(List)
|
|
rankList = list
|
|
let topThreeArr = list.slice(0, 3)
|
|
if (list.length < 3) {
|
|
let len = 3 - list.length
|
|
let arr = new Array(len).fill({
|
|
nick: '',
|
|
erbanNo: '',
|
|
goldAmount: '',
|
|
gender: ''
|
|
})
|
|
topThreeArr.push(...arr)
|
|
}
|
|
let topThreeStr = ''
|
|
topThreeArr.map((item, index) => {
|
|
let tostr, goldAmount
|
|
if (item.goldAmount) {
|
|
tostr = item.goldAmount.toString()
|
|
}
|
|
if (tostr) {
|
|
if (tostr.length >= 5) {
|
|
goldAmount = (item.goldAmount / 10000).toFixed(2) + 'w'
|
|
} else {
|
|
goldAmount = item.goldAmount
|
|
}
|
|
}
|
|
|
|
topThreeStr += `
|
|
<div class="top_three_item">
|
|
<div class="avatar" data-uid=${item.uid}>
|
|
<p></p>
|
|
<img src="${item.avatar ? item.avatar : `./images/${index + 1}.png`}" alt="">
|
|
</div>
|
|
<div class="nick">
|
|
${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}
|
|
<img src="${item.gender == 1 ? './images/male.png' : './images/female.png'}" alt="" class='gender' style='display:${item.gender ? 'inline-block' : 'none'}'>
|
|
</div>
|
|
<div class="erbanNo"><span>${item.erbanNo ? 'ID:' + item.erbanNo : ''}</span></div>
|
|
<div class="num">${goldAmount ? goldAmount : ''}</div>
|
|
</div>
|
|
`
|
|
})
|
|
$('.top_three_wrap').html(topThreeStr)
|
|
|
|
|
|
// 渲染非前3
|
|
let othersArr = list.slice(3)
|
|
let others = ''
|
|
othersArr.map((item, index) => {
|
|
let tostr = item.goldAmount.toString()
|
|
let goldAmount
|
|
if (tostr.length >= 5) {
|
|
goldAmount = (item.goldAmount / 10000).toFixed(2) + 'w'
|
|
} else {
|
|
goldAmount = item.goldAmount
|
|
}
|
|
others += `
|
|
<li>
|
|
<div class="index">${index + 4}</div>
|
|
<div class="others_avatar" data-uid=${item.uid}><img src="${item.avatar}" alt=""></div>
|
|
<div class="info_wrap">
|
|
<div class="others_nick">
|
|
${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}
|
|
<img src="${item.gender == 1 ? './images/male.png' : './images/female.png'}" alt="">
|
|
</div>
|
|
<div class="others_erbanNo">ID:<span>${item.erbanNo}</span></div>
|
|
</div>
|
|
<div class="others_num">${goldAmount}</div>
|
|
</li>
|
|
`
|
|
})
|
|
$('ul').html(others)
|
|
}
|
|
|
|
$(function () {
|
|
getInfoFromClient()
|
|
setTimeout(() => {
|
|
getShowInfo()
|
|
// getList( 'day' )
|
|
}, 50)
|
|
|
|
// tab切换
|
|
let currentTabIndex = 0
|
|
$('.tab_contain').on('click', 'p', function () {
|
|
let index = $(this).index()
|
|
if (currentTabIndex == index) return;
|
|
currentTabIndex = index
|
|
$(this).addClass('active').siblings('p').removeClass('active')
|
|
rankList = []
|
|
$('.rank_wrap').scrollTop(0)
|
|
page = 1
|
|
if (index) {
|
|
// 魅力榜单
|
|
$('.rank_type p').eq(2).hide()
|
|
$('.rank_type p').eq(currentCharmRankType).addClass('active').siblings('p').removeClass('active')
|
|
if (showMonthList) {
|
|
$('.wrap .tab_wrap .rank_type p:last-child').show();
|
|
if (currentCharmRankType == 0) {
|
|
if (sessionStorage.getItem('dayCharmList')) {
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else {
|
|
getCharmList('day')
|
|
}
|
|
} else if (currentCharmRankType == 1) {
|
|
if (sessionStorage.getItem('weekCharmList')) {
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else {
|
|
getCharmList('week')
|
|
}
|
|
} else if (currentCharmRankType == 2) {
|
|
if (sessionStorage.getItem('monthCharmList')) {
|
|
renderList(sessionStorage.getItem('monthCharmList'))
|
|
} else {
|
|
getCharmList('month')
|
|
}
|
|
}
|
|
} else {
|
|
if (currentCharmRankType == 0) {
|
|
if (sessionStorage.getItem('dayCharmList')) {
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else {
|
|
getCharmList('day')
|
|
}
|
|
} else if (currentCharmRankType == 1) {
|
|
if (sessionStorage.getItem('weekCharmList')) {
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else {
|
|
getCharmList('week')
|
|
}
|
|
} else if (currentCharmRankType == 2) {
|
|
if (sessionStorage.getItem('totalCharmList')) {
|
|
renderList(sessionStorage.getItem('totalCharmList'))
|
|
} else {
|
|
getCharmList('total')
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// 贡献榜&爱意榜
|
|
if (showReceiveRankTotal) {
|
|
$('.rank_type p').eq(2).show()
|
|
}
|
|
if (showMonthList) {
|
|
$('.wrap .tab_wrap .rank_type p:last-child').show();
|
|
$('.rank_type p').eq(currentRankType).addClass('active').siblings('p').removeClass('active')
|
|
if (currentRankType == 0) {
|
|
if (sessionStorage.getItem('dayList')) {
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else {
|
|
getList('day')
|
|
}
|
|
} else if (currentRankType == 1) {
|
|
if (sessionStorage.getItem('weekList')) {
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else {
|
|
getList('week')
|
|
}
|
|
} else if (currentRankType == 2) {
|
|
if (sessionStorage.getItem('monthList')) {
|
|
renderList(sessionStorage.getItem('monthList'))
|
|
} else {
|
|
getList('month')
|
|
}
|
|
}
|
|
} else {
|
|
$('.rank_type p').eq(currentRankType).addClass('active').siblings('p').removeClass('active')
|
|
if (currentRankType == 0) {
|
|
if (sessionStorage.getItem('dayList')) {
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else {
|
|
getList('day')
|
|
}
|
|
} else if (currentRankType == 1) {
|
|
if (sessionStorage.getItem('weekList')) {
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else {
|
|
getList('week')
|
|
}
|
|
} else if (currentRankType == 2) {
|
|
if (sessionStorage.getItem('totalList')) {
|
|
renderList(sessionStorage.getItem('totalList'))
|
|
} else {
|
|
getList('total')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
// 日榜周榜总榜切换
|
|
let currentRankType = 0
|
|
let currentCharmRankType = 0
|
|
$('.rank_type').on('click', 'p', function () {
|
|
$('.rank_wrap').scrollTop(0)
|
|
page = 1
|
|
if (currentTabIndex) {
|
|
// 魅力榜
|
|
let index = $(this).index()
|
|
if (currentCharmRankType == index) return;
|
|
currentCharmRankType = index
|
|
$(this).addClass('active').siblings('p').removeClass('active')
|
|
rankList = []
|
|
|
|
if (showMonthList) {
|
|
if (index == 0) {
|
|
if (sessionStorage.getItem('dayCharmList')) {
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else {
|
|
getCharmList('day')
|
|
}
|
|
|
|
} else if (index == 1) {
|
|
if (sessionStorage.getItem('weekCharmList')) {
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else {
|
|
getCharmList('week')
|
|
}
|
|
} else if (index == 2) {
|
|
if (sessionStorage.getItem('monthCharmList')) {
|
|
renderList(sessionStorage.getItem('monthCharmList'))
|
|
} else {
|
|
getCharmList('month')
|
|
}
|
|
}
|
|
} else {
|
|
if (index == 0) {
|
|
if (sessionStorage.getItem('dayCharmList')) {
|
|
renderList(sessionStorage.getItem('dayCharmList'))
|
|
} else {
|
|
getCharmList('day')
|
|
}
|
|
|
|
} else if (index == 1) {
|
|
if (sessionStorage.getItem('weekCharmList')) {
|
|
renderList(sessionStorage.getItem('weekCharmList'))
|
|
} else {
|
|
getCharmList('week')
|
|
}
|
|
} else if (index == 2) {
|
|
if (sessionStorage.getItem('totalCharmList')) {
|
|
renderList(sessionStorage.getItem('totalCharmList'))
|
|
} else {
|
|
getCharmList('total')
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// 财富榜
|
|
let index = $(this).index()
|
|
if (currentRankType == index) return;
|
|
currentRankType = index
|
|
$(this).addClass('active').siblings('p').removeClass('active')
|
|
rankList = []
|
|
if (showMonthList) {
|
|
if (index == 0) {
|
|
if (sessionStorage.getItem('dayList')) {
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else {
|
|
getList('day')
|
|
}
|
|
|
|
} else if (index == 1) {
|
|
if (sessionStorage.getItem('weekList')) {
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else {
|
|
getList('week')
|
|
}
|
|
} else if (index == 2) {
|
|
if (sessionStorage.getItem('monthList')) {
|
|
renderList(sessionStorage.getItem('monthList'))
|
|
} else {
|
|
getList('month')
|
|
}
|
|
}
|
|
} else {
|
|
if (index == 0) {
|
|
if (sessionStorage.getItem('dayList')) {
|
|
renderList(sessionStorage.getItem('dayList'))
|
|
} else {
|
|
getList('day')
|
|
}
|
|
|
|
} else if (index == 1) {
|
|
if (sessionStorage.getItem('weekList')) {
|
|
renderList(sessionStorage.getItem('weekList'))
|
|
} else {
|
|
getList('week')
|
|
}
|
|
} else if (index == 2) {
|
|
if (sessionStorage.getItem('totalList')) {
|
|
renderList(sessionStorage.getItem('totalList'))
|
|
} else {
|
|
getList('total')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
// 监听滚动
|
|
$('.rank_wrap').scroll(function () {
|
|
let scrollTop = $(this).scrollTop()
|
|
let scrollHeight = $('.rank_wrap')[0].scrollHeight
|
|
let ulHeight = $(this).innerHeight()
|
|
if (scrollTop + ulHeight + 100 >= scrollHeight) {
|
|
if (isLock) {
|
|
// 请求下一页
|
|
// if (canNext) {
|
|
if (showMonthList) {
|
|
if (currentTabIndex) {
|
|
if (currentCharmRankType == 0) {
|
|
if (!dayCharmListNext) return
|
|
getCharmList('day', ++page)
|
|
} else if (currentCharmRankType == 1) {
|
|
if (!weekCharmListNext) return
|
|
getCharmList('week', ++page)
|
|
} else if (currentCharmRankType == 2) {
|
|
if (!monthCharmListNext) return
|
|
getCharmList('month', ++page)
|
|
}
|
|
} else {
|
|
if (currentRankType == 0) {
|
|
if (!dayListNext) return
|
|
getList('day', ++page)
|
|
} else if (currentRankType == 1) {
|
|
if (!weekListNext) return
|
|
getList('week', ++page)
|
|
} else if (currentRankType == 2) {
|
|
if (!monthListNext) return
|
|
getList('month', ++page)
|
|
}
|
|
}
|
|
} else {
|
|
if (currentTabIndex) {
|
|
if (currentCharmRankType == 0) {
|
|
if (!dayCharmListNext) return
|
|
getCharmList('day', ++page)
|
|
} else if (currentCharmRankType == 1) {
|
|
if (!weekCharmListNext) return
|
|
getCharmList('week', ++page)
|
|
} else if (currentCharmRankType == 2) {
|
|
if (!totalCharmListNext) return
|
|
getCharmList('total', ++page)
|
|
}
|
|
} else {
|
|
if (currentRankType == 0) {
|
|
if (!dayListNext) return
|
|
getList('day', ++page)
|
|
} else if (currentRankType == 1) {
|
|
if (!weekListNext) return
|
|
getList('week', ++page)
|
|
} else if (currentRankType == 2) {
|
|
if (!totalListNext) return
|
|
getList('total', ++page)
|
|
}
|
|
}
|
|
}
|
|
isLock = false
|
|
// }
|
|
}
|
|
}
|
|
})
|
|
|
|
//跳转个人主页
|
|
function openPerson(document, dom) {
|
|
$(document).on('click', dom, function () {
|
|
let erbanUid = $(this).data('uid')
|
|
if (!browser.app) return
|
|
if (browser.ios) {
|
|
window.webkit.messageHandlers.openPersonPage.postMessage(erbanUid);
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
window.androidJsObj.openPersonPage(erbanUid);
|
|
}
|
|
}
|
|
})
|
|
}
|
|
openPerson('.top_three_wrap', '.avatar')
|
|
openPerson('ul', '.others_avatar')
|
|
}) |