123 lines
3.9 KiB
JavaScript
123 lines
3.9 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
var rankDataType = 1;
|
||
var rankType = 1;
|
||
// 封装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'
|
||
})
|
||
}
|
||
$(function () {
|
||
getInfoFromClient()
|
||
// debug
|
||
if (EnvCheck() == 'test') {
|
||
new VConsole();
|
||
}
|
||
setTimeout(function () {
|
||
getData(rankDataType, rankType);
|
||
}, 50)
|
||
})
|
||
function getData (rankDataType, rankType) {
|
||
showLoading();
|
||
$('.listBox ul li').remove();
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/luckybag/rank/listRank',
|
||
data: { rankDataType, rankType },//rankDataType(1:日榜 3:总榜);rankType(1:神豪榜 2:魅力榜)
|
||
success (res) {
|
||
console.log(res.code == 200);
|
||
if (res.code == 200) {
|
||
var str = '';
|
||
var listTo3 = res.data.slice(0, 3);
|
||
var notListTo3 = res.data.slice(3);
|
||
console.log(listTo3);
|
||
if (listTo3.length < 3) {
|
||
let arr = new Array(3 - listTo3.length).fill({
|
||
avatar: './images/null.png',
|
||
nick: '',
|
||
score: ""
|
||
})
|
||
listTo3.push(...arr)
|
||
}
|
||
// 处理前三
|
||
listTo3.forEach((res, index) => {
|
||
if(res.score > 10000) {
|
||
res.score = ( ( Math.floor(res.score/1000) ) / 10 ).toFixed(1) + 'W'
|
||
}
|
||
$(`.listBox .ranking${index + 1} .imagesBox img`).attr("src", res.avatar);
|
||
$(`.listBox .ranking${index + 1} .nick`).text(res.nick);
|
||
$(`.listBox .ranking${index + 1} .integral`).text(res.score+'积分');
|
||
});
|
||
notListTo3.forEach((res, index) => {
|
||
if(res.score > 10000) {
|
||
res.score = ( ( Math.floor(res.score/1000) ) / 10 ).toFixed(1) + 'W'
|
||
}
|
||
str += `
|
||
<li>
|
||
<span class="num">${index + 4}</span>
|
||
<img src="${res.avatar}" alt="">
|
||
<span class="nick">${res.nick}</span>
|
||
<span class="integral">${res.score}积分</span>
|
||
</li>
|
||
`
|
||
});
|
||
$('.listBox ul').append(str);
|
||
hideLoading(layerIndex);
|
||
}
|
||
},
|
||
error (err) {
|
||
toastMsg('網絡錯誤,請退出重進')
|
||
}
|
||
})
|
||
}
|
||
// 切换榜单事件
|
||
$('.tabBox div').click(function () {
|
||
var index = $(this).index();
|
||
rankType = $(this).attr('type');
|
||
if (index == 0) {
|
||
$(this).addClass('shenhao_A').siblings().removeClass('meili_A');
|
||
getData(rankDataType, rankType);
|
||
} else {
|
||
$(this).addClass('meili_A').siblings().removeClass('shenhao_A');
|
||
getData(rankDataType, rankType);
|
||
}
|
||
})
|
||
// 切换总榜日榜
|
||
$('.listBox .dayTab div').click(function () {
|
||
rankDataType = $(this).attr('type');
|
||
var index = $(this).index();
|
||
if (index == 0) {
|
||
$(this).addClass('day_A').siblings().removeClass('all_A');
|
||
getData(rankDataType, rankType);
|
||
} else {
|
||
$(this).addClass('all_A').siblings().removeClass('day_A');
|
||
getData(rankDataType, rankType);
|
||
}
|
||
})
|
||
// 关闭规则
|
||
$('.rule').click(function () {
|
||
$('body').css('overflow', 'auto');
|
||
$(this).hide();
|
||
})
|
||
// 打开规则
|
||
$('.header .rule_title').click(function () {
|
||
$('body').css('overflow', 'hidden');
|
||
$('.rule').show();
|
||
}) |