优化房间帮ui

This commit is contained in:
Dragon
2024-03-28 10:17:29 +08:00
parent 4f23c91703
commit ddc6d7e6c4
28 changed files with 2716 additions and 1028 deletions

View File

@@ -1,15 +1,18 @@
let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let queryObj = getQueryString()
if (EnvCheck() === 'test') new VConsole
let env = EnvCheck();
var urlData = getQueryString();
if (env == 'test') {
new VConsole();
}
// 封装layer消息提醒框
let layerIndex
const showLoading = () => {
const showLoading = (content = '加载中...') => {
layer.open({
type: 2,
shadeClose: false,
content: '加載中...',
success(e) {
content,
success (e) {
layerIndex = $(e).attr('index')
}
})
@@ -24,588 +27,189 @@ const toastMsg = (content = '操作完成', time = 2) => {
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)
}
var listType = 1;
var experImgUrl = 'https://yinmeng-1318633625.cos.ap-guangzhou.myqcloud.com/new_exper_';
var charmImgUrl = 'https://yinmeng-1318633625.cos.ap-guangzhou.myqcloud.com/new_charm_';
var typeWealth = 'day';//财富榜类型day 日 week 周 month 月 total 总
// 初始化函数
$(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')
}
}
setTimeout(function () {
// 页面全屏
if (browser.app) {
if (browser.android) {
window.androidJsObj.initShowNav(false)
} 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')
}
}
window.webkit.messageHandlers.initShowNav.postMessage(0)
}
} 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')
}
}
};
// 顶部返回事件
$('.back').click(() => {
if (browser.android) {
window.androidJsObj.closeWebView()
} 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);
}
window.webkit.messageHandlers.closeWebView.postMessage(null)
}
})
getRankingsWealth();
}, 100)
})
// 榜单切换
$('.largestBox .tab div').click(function () {
var i = $(this).index() + 1;
listType = i;
$('.largestBox .tab div').removeClass('tabColor1').removeClass('tabColor2')
$(this).addClass(`tabColor${listType}`);
$('.largestBox .dayTab div').removeClass('dayTabColor1').removeClass('dayTabColor2');
$('.largestBox .dayTab div').eq(0).addClass(`dayTabColor${listType}`);
typeWealth = 'day';
if (listType == 1) {
getRankingsWealth();
} else {
getReciveRankingsWealth();
}
})
// 日榜切换
$('.largestBox .dayTab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass(`dayTabColor${listType}`).siblings().removeClass('dayTabColor1').removeClass('dayTabColor2');
if (i == 1) {
typeWealth = 'day';//财富榜类型day 日 week 周 month 月 total 总
} else if (i == 2) {
typeWealth = 'week';
} else if (i == 3) {
typeWealth = 'month';
}
if (listType == 1) {
getRankingsWealth();
} else {
getReciveRankingsWealth();
}
})
// 爱意榜接口
function getRankingsWealth () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/room/rankings',
data: {
roomUid: urlData.roomUid,
type: typeWealth,
page: 1,
pageSize: 30,
},
success (res) {
if (res.code === 200) {
listDomFun(res, 1);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('网络错误,请退出重进')
}
})
}
// 魅力榜接口
function getReciveRankingsWealth () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/room/recive/rankings',
data: {
roomUid: urlData.roomUid,
type: typeWealth,
page: 1,
pageSize: 30,
},
success (res) {
if (res.code === 200) {
listDomFun(res, 2);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('网络错误,请退出重进')
}
})
}
// 渲染样式
function listDomFun (res, num) {
$('.largestBox ul li').remove();
// 处理前三
var top3 = res.data.rankings.slice(0, 3);
if (top3.length < 3) {
let arr = new Array(3 - top3.length).fill({
avatar: './images/logo.png',
nick: '虚位以待',
goldAmount: '',
})
top3.push(...arr);
}
top3.forEach((res, i) => {
if (res.avatar == './images/logo.png') {
$(`.largestBox .top3 .no${i + 1} .box p .sp`).hide();
$(`.largestBox .top3 .no${i + 1} .box .icon`).hide();
} else {
$(`.largestBox .top3 .no${i + 1} .box p .sp`).show();
$(`.largestBox .top3 .no${i + 1} .box .icon`).show();
}
$(`.largestBox .top3 .no${i + 1} .box .tx`).attr('src', res.avatar);
$(`.largestBox .top3 .no${i + 1} .box .ts`).attr('uid', res.uid);
$(`.largestBox .top3 .no${i + 1} .box p .sp1`).text(res.nick.length > 6 ? res.nick.slice(0, 6) + '...' : res.nick);
$(`.largestBox .top3 .no${i + 1} .box p .sp`).removeClass('boy').removeClass('woman')
$(`.largestBox .top3 .no${i + 1} .box p .sp`).addClass(`${res.gender == 1 ? 'boy' : 'woman'}`);
$(`.largestBox .top3 .no${i + 1} .box p .sp img`).attr('src', res.gender == 1 ? './images/boy.png' : './images/woman.png');
$(`.largestBox .top3 .no${i + 1} .box .icon .icon1`).attr('src', experImgUrl + `${res.experSeq <= 9 ? '0' + res.experSeq : res.experSeq}.png`)
$(`.largestBox .top3 .no${i + 1} .box .icon .icon2`).attr('src', charmImgUrl + `${res.charmSeq <= 9 ? '0' + res.charmSeq : res.charmSeq}.png`)
$(`.largestBox .top3 .no${i + 1} .box .score`).text(unitProcessing(res.goldAmount, 10000, 1, 'W'));
})
// 处理非前三
var notTop3 = res.data.rankings.slice(3);
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${i + 4}</div>
<img src="${res.avatar}" uid=${res.uid} alt="" class="tx">
<div class="userInfo">
<p>${res.nick}</p>
<img src="${experImgUrl + `${res.experSeq <= 9 ? '0' + res.experSeq : res.experSeq}.png`}" alt="" class="icon1">
<img src="${charmImgUrl + `${res.charmSeq <= 9 ? '0' + res.charmSeq : res.charmSeq}.png`}" alt="" class="icon2">
</div>
<div class="score">
<p>${unitProcessing(res.goldAmount, 10000, 1, 'W')}</p>
<span>${num == 1 ? '爱意值' : '魅力值'}</span>
</div>
</li>
`
})
$('.largestBox ul').append(str);
}
// 点击前三跳转房间
$('.largestBox').on('click', '.top3 .no .box .ts', function () {
var uid = $(this).attr('uid');
if (browser.ios) {
window.webkit.messageHandlers.openPersonPage.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openPersonPage(uid);
}
}
})
// 点击非前三跳转房间
$('.largestBox').on('click', 'ul li .tx', function () {
var uid = $(this).attr('uid');
if (browser.ios) {
window.webkit.messageHandlers.openPersonPage.postMessage(uid);
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openPersonPage(uid);
}
}
openPerson('.top_three_wrap', '.avatar')
openPerson('ul', '.others_avatar')
})