115 lines
4.6 KiB
JavaScript
115 lines
4.6 KiB
JavaScript
let info = {};
|
|
$(function () {
|
|
let browser = checkVersion();
|
|
let api = getUrlPrefix();
|
|
if (EnvCheck() == 'test') { let vConsole = new VConsole };
|
|
let locateObj = getQueryString();
|
|
|
|
//type=user 用戶等級(財富等級) type = charm 魅力等級
|
|
if (locateObj.type == 'user') {
|
|
$('.level').eq(0).addClass('active').siblings().removeClass('active');
|
|
$('.user-content').eq(0).show().siblings('.user-content').hide();
|
|
console.log("user")
|
|
} else if (locateObj.type == 'charm') {
|
|
$('.level').eq(1).addClass('active').siblings().removeClass('active');
|
|
$('.user-content').eq(1).show().siblings('.user-content').hide();
|
|
console.log("charm")
|
|
}
|
|
|
|
|
|
if (browser.app) {
|
|
if (browser.ios) {
|
|
info.uid = tools.cookieUtils.get('uid');
|
|
window.webkit.messageHandlers.getTicket.postMessage(null);
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
info.uid = parseInt(window.androidJsObj.getUid());
|
|
info.ticket = window.androidJsObj.getTicket();
|
|
}
|
|
}
|
|
} else {
|
|
info.uid = 936365;
|
|
info.ticket = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjo5MzYzNjUsInRpY2tldF9pZCI6IjcxYTVkNmM1LTZiZGYtNDQxYS1iMjg5LTE5MzU0MmQ4NjU0MiIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.mmTJQ5rI5wEBmj5VN1YkSv0MO5aqy8z7W4XTPN-Jx04"
|
|
}
|
|
var mySwiper = new Swiper('.swiper-container', {
|
|
autoHeight: true,
|
|
onSlideChangeStart: function (swiper) {
|
|
let index = swiper.activeIndex;
|
|
$('.level-head .level').eq(index).addClass('active').siblings('.level').removeClass('active');
|
|
$('.user-content').eq(index).show().siblings('.user-content').hide();
|
|
$(window).scrollTop(0)
|
|
}
|
|
})
|
|
//等級數據渲染
|
|
const renderUser = (data) => {
|
|
let $user = $('.user-content');
|
|
$user.find('.user-head .user-avatar').attr('src', data.avatar);
|
|
$user.find('.grade .grade-now').html('LV.' + data.userLevelExperience.levelExperience.levelSeq);
|
|
$user.find('.grade .grade-next').html('LV.' + data.userLevelExperience.nextLevelExperience.levelSeq);
|
|
$user.find('.treasure-now').html('財富值:' + data.userLevelExperience.amount);
|
|
var barWidth = (data.userLevelExperience.amount / data.userLevelExperience.nextLevelExperience.amount) * 100;
|
|
// console.log(barWidth);
|
|
barWidth = barWidth >= 100 ? 100 : barWidth
|
|
$user.find('.progress-bar .progress-bar-now').css({
|
|
width: barWidth + '%'
|
|
})
|
|
let dis = data.userLevelExperience.nextLevelExperience.amount - data.userLevelExperience.amount;
|
|
if (dis <= 0) {
|
|
dis = '∞';
|
|
}
|
|
$user.find('.treasure-upgrade').html('升級所需財富值:' + `<span class="num">${dis}</span>`);
|
|
}
|
|
//魅力數據渲染
|
|
const renderCharm = (data) => {
|
|
let $user = $('.user-charm');
|
|
$user.find('.user-head .user-avatar').attr('src', data.avatar);
|
|
$user.find('.grade .grade-now').html('LV.' + data.userLevelCharm.levelCharm.levelSeq);
|
|
$user.find('.grade .grade-next').html('LV.' + data.userLevelCharm.nextLevelCharm.levelSeq);
|
|
$user.find('.treasure-now').html('魅力值:' + data.userLevelCharm.amount);
|
|
let barWidth = (data.userLevelCharm.amount / data.userLevelCharm.nextLevelCharm.amount) * 100;
|
|
barWidth = barWidth >= 100 ? 100 : barWidth
|
|
$user.find('.progress-bar .progress-bar-now').css({
|
|
width: barWidth + '%'
|
|
})
|
|
let dis = data.userLevelCharm.nextLevelCharm.amount - data.userLevelCharm.amount;
|
|
if (dis <= 0) {
|
|
dis = '∞';
|
|
}
|
|
$user.find('.treasure-upgrade').html('升級所需魅力值:' + `<span class="num">${dis}</span>`);
|
|
}
|
|
|
|
const getMsg = () => {
|
|
$.get(api + '/userLevel/getUserExper', { uid: info.uid, ticket: info.ticket }, function (res) {
|
|
if (res.code == 200) {
|
|
console.log(res.data);
|
|
renderUser(res.data);
|
|
}
|
|
})
|
|
$.get(api + '/userLevel/getUserCharm', { uid: info.uid, ticket: info.ticket }, function (res) {
|
|
if (res.code == 200) {
|
|
console.log(res.data);
|
|
renderCharm(res.data);
|
|
}
|
|
})
|
|
}
|
|
setTimeout(function () {
|
|
getMsg();
|
|
}, 100)
|
|
|
|
function convertName(name) {
|
|
return name.split('L')[0];
|
|
}
|
|
//用戶等級和魅力等級切換
|
|
$('.level-head').on('click', '.level', function () {
|
|
if ($(this).hasClass('active')) return;
|
|
mySwiper.slideTo($(this).index(), 400, false)
|
|
$(this).addClass('active').siblings('.level').removeClass('active');
|
|
var index = $(this).index();
|
|
$('.user-content').eq(index).show().siblings('.user-content').hide();
|
|
$(window).scrollTop(0)
|
|
})
|
|
})
|
|
function getMessage(key, value) {
|
|
info[key] = value;
|
|
}
|