106 lines
2.8 KiB
JavaScript
106 lines
2.8 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
|
let browser = checkVersion()
|
|
let env = EnvCheck();
|
|
if (env == 'test') {
|
|
new VConsole();
|
|
}
|
|
// 封裝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 () {
|
|
setTimeout(function () {
|
|
getInfoFromClient()
|
|
if (browser.app) {
|
|
$('.back').hide();
|
|
}
|
|
setTimeout(function () {
|
|
getQueryWithRoomType();
|
|
getUser();
|
|
}, 100)
|
|
})
|
|
})
|
|
// 鉆石金幣接口
|
|
function getQueryWithRoomType () {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/purse/queryWithRoomType',
|
|
success (res) {
|
|
if (res.code === 200) {
|
|
$('.diamond p').text(res.data.diamonds);
|
|
$('.gold p').text(res.data.golds);
|
|
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
|
|
window.location.href = './login.html'
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error (err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
}
|
|
})
|
|
}
|
|
// 基本信息接口
|
|
function getUser () {
|
|
showLoading()
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/user/get',
|
|
data: { uid: pubInfo.uid },
|
|
success (res) {
|
|
if (res.code === 200) {
|
|
$('.myInfo img').attr('src', res.data.avatar);
|
|
$('.myInfo div p').text(res.data.nick);
|
|
$('.myInfo div b').text("ID:" + res.data.erbanNo);
|
|
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
|
|
window.location.href = './login.html'
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
hideLoading(layerIndex)
|
|
},
|
|
error (err) {
|
|
hideLoading(layerIndex)
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
}
|
|
})
|
|
}
|
|
// 返回按鈕
|
|
$('.back').click(function () {
|
|
window.history.go(-1)
|
|
})
|
|
|
|
//返回页面 重新请求接口
|
|
var hiddenProperty = 'hidden' in document ? 'hidden' :
|
|
'webkitHidden' in document ? 'webkitHidden' :
|
|
'mozHidden' in document ? 'mozHidden' : null;
|
|
|
|
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
|
|
var onVisibilityChange = function () {
|
|
if (!document[hiddenProperty]) {
|
|
location.reload()
|
|
}
|
|
}
|
|
document.addEventListener(visibilityChangeEvent, onVisibilityChange); |