304 lines
10 KiB
JavaScript
304 lines
10 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
let env = EnvCheck();
|
||
if (env == 'test') {
|
||
new VConsole();
|
||
}
|
||
var urlDate = getQueryString();
|
||
// 封裝layer消息提醒框
|
||
let layerIndex
|
||
var langReplace;
|
||
var localLang;
|
||
var newBg;
|
||
var textConte1;
|
||
var textConte2;
|
||
const showLoading = (content = langReplace(localLang.demoModule.layerIndex1)) => {
|
||
layer.open({
|
||
type: 2,
|
||
shadeClose: false,
|
||
content,
|
||
success(e) {
|
||
layerIndex = $(e).attr('index')
|
||
}
|
||
})
|
||
}
|
||
const hideLoading = (index) => {
|
||
layer.close(index)
|
||
}
|
||
const toastMsg = (content = langReplace(localLang.demoModule.layerIndex2), time = 2) => {
|
||
layer.open({
|
||
content,
|
||
time,
|
||
skin: 'msg'
|
||
})
|
||
}
|
||
// 初始化函數
|
||
$(function () {
|
||
getInfoFromClient();
|
||
fuzzyMatchUpdateQueryStringParameterFun(); // 判断语言
|
||
setTimeout(function () {
|
||
// 頁面全屏
|
||
if (browser.app) {
|
||
if (browser.android) {
|
||
window.androidJsObj.initShowNav(false)
|
||
} else {
|
||
window.webkit.messageHandlers.initShowNav.postMessage(0)
|
||
}
|
||
};
|
||
// 頂部返回事件
|
||
$('.back img').click(() => {
|
||
window.location.href = './index.html';
|
||
})
|
||
// pubInfo['Accept-Language'] = 'ar'
|
||
fuzzyMatchUpdateQueryStringParameterFun(); // 判断语言
|
||
langReplace = window.lang.replace;
|
||
localLang = window.lang;
|
||
translateFun();
|
||
textConte1 = langReplace(localLang.guildInfoSet.textConte1);
|
||
textConte2 = langReplace(localLang.guildInfoSet.textConte2);
|
||
$('.name input').val(urlDate.guildNick);
|
||
$('.payoneer input').val(urlDate.payoneer == undefined ? urlDate.payoneer : '');
|
||
$('.usdt input').val(urlDate.usdt == undefined ? urlDate.usdt : '');
|
||
$('.paypal input').val(urlDate.payPal == undefined ? urlDate.payPal : '');
|
||
$('.background img').attr('src', urlDate.backgroundUrl);
|
||
newBg = urlDate.backgroundUrl;
|
||
if ($('.payoneer input').val() != '') {
|
||
$('.payoneer span').hide();
|
||
$('.payoneer input').attr('disabled', true);
|
||
}
|
||
if ($('.usdt input').val() != '') {
|
||
$('.usdt span').hide();
|
||
$('.usdt input').attr('disabled', true);
|
||
}
|
||
if ($('.paypal input').val() != '') {
|
||
$('.paypal span').hide();
|
||
$('.paypal input').attr('disabled', true);
|
||
}
|
||
}, 100)
|
||
})
|
||
function translateFun() {
|
||
var langReplace = window.lang.replace;
|
||
var localLang = window.lang;
|
||
$('.text1').text(langReplace(localLang.guildInfoSet.text1));
|
||
$('.text2').text(langReplace(localLang.guildInfoSet.text2));
|
||
$('.text3').text(langReplace(localLang.guildInfoSet.text3));
|
||
$('.text4').attr('placeholder', langReplace(localLang.guildInfoSet.text4));
|
||
$('.text5').text(langReplace(localLang.guildInfoSet.text5));
|
||
$('.text55').text(langReplace(localLang.guildInfoSet.text55));
|
||
$('.text6').text(langReplace(localLang.guildInfoSet.text6));
|
||
$('.text7').text(langReplace(localLang.guildInfoSet.text7));
|
||
$('.textConte2').text(langReplace(localLang.guildInfoSet.textConte2));
|
||
$('.textConte3').text(langReplace(localLang.guildInfoSet.textConte3));
|
||
$('.textConte1').text(langReplace(localLang.guildInfoSet.textConte1));
|
||
$('.textConte4').text(langReplace(localLang.guildInfoSet.textConte4));
|
||
|
||
}
|
||
// 上傳图片接口
|
||
function getToken(file, type) {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/tencent/cos/getToken',
|
||
success(res) {
|
||
if (res.code === 200) {
|
||
let cos = new COS({
|
||
SecretId: res.data.secretId,
|
||
SecretKey: res.data.secretKey,
|
||
SecurityToken: res.data.sessionToken,
|
||
StartTime: res.data.startTime,
|
||
ExpiredTime: res.data.expireTime,
|
||
});
|
||
console.log(cos);
|
||
var customDomain = res.data.customDomain;
|
||
cos.uploadFile({
|
||
Bucket: res.data.bucket, /* 填写自己的 bucket,必须字段 */
|
||
Region: res.data.region, /* 存储桶所在地域,必须字段 */
|
||
Key: file.name, /* 存储在桶里的对象键(例如:1.jpg,a/b/test.txt,图片.jpg)支持中文,必须字段 */
|
||
Body: file, // 上传文件对象
|
||
SliceSize: 1024 * 1024 * 5, /* 触发分块上传的阈值,超过5MB使用分块上传,小于5MB使用简单上传。可自行设置,非必须 */
|
||
onProgress: function (progressData) {
|
||
console.log(JSON.stringify(progressData));
|
||
}
|
||
}).then(res => {
|
||
console.log('上传成功');
|
||
console.log(res);
|
||
if (type == 1) {//背景
|
||
setInfo(null, `${customDomain}/${file.name}`, function () { }, null);
|
||
$('.backgrounds img').attr('src', `${customDomain}/${file.name}`);
|
||
} else {
|
||
setInfo(null, null, function () { }, `${customDomain}/${file.name}`);
|
||
$('.backgrounds2 img').attr('src', `${customDomain}/${file.name}`);
|
||
}
|
||
}).catch(err => {
|
||
console.log('上传失败', err);
|
||
hideLoading(layerIndex)
|
||
toastMsg(err.message);
|
||
});
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
// hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
// 上傳图片接口
|
||
function getUploadToken() {
|
||
const backImage = document.getElementById('backImageUpload').files[0];
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefiw,
|
||
success(res) {
|
||
if (res.code === 200) {
|
||
var frontImageKey = res.data.key;
|
||
var frontImageToken = res.data.token;
|
||
showLoading()
|
||
const observable = qiniu.upload(
|
||
backImage,
|
||
frontImageKey,
|
||
frontImageToken
|
||
);
|
||
observable.subscribe({
|
||
complete: (res) => {
|
||
console.log(res);
|
||
$('.background img').attr('src', res.path);
|
||
setInfo(null, res.path, function () { });
|
||
// toastMsg(langReplace(localLang.guildInfoSet.text8))
|
||
},
|
||
});
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
// hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
// 上传公会头像
|
||
function fileChangeF2(e) {
|
||
var file = document.querySelector('#backImageUpload2').files[0];
|
||
console.log(file);
|
||
if (file.length == 0) {
|
||
return;
|
||
}
|
||
var fileType = file.type;
|
||
// 判断是否是动图
|
||
if (fileType == 'image/gif' || file.name.includes('.gif')) {
|
||
toastMsg(langReplace(localLang.guildInfoSet.toastMsgText1))
|
||
} else {
|
||
getToken(file, 2)
|
||
}
|
||
}
|
||
// 上传公会背景
|
||
function fileChangeF(e) {
|
||
var file = document.querySelector('#backImageUpload').files[0];
|
||
console.log(file);
|
||
if (file.length == 0) {
|
||
return;
|
||
}
|
||
var fileType = file.type;
|
||
// 判断是否是动图
|
||
if (fileType == 'image/gif' || file.name.includes('.gif')) {
|
||
toastMsg(langReplace(localLang.guildInfoSet.toastMsgText1))
|
||
} else {
|
||
getToken(file, 1)
|
||
}
|
||
}
|
||
// 保存接口
|
||
function setInfo(name, backgroundUrl, fun, avatar) {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'post',
|
||
url: urlPrefix + '/family/setInfo',
|
||
data: { name, backgroundUrl, avatar },
|
||
success(res) {
|
||
if (res.code === 200) {
|
||
fun();
|
||
// window.location.href = "./index.html"
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
// 保存按钮
|
||
$('.boxBut .ok').click(function () {
|
||
var name = $('.nick input').val();
|
||
var bgUrl = $('.bg img').attr('src');
|
||
setInfo(name, bgUrl);
|
||
})
|
||
// 修改昵称按钮
|
||
var statusName = true;
|
||
$('.name span').click(function () {
|
||
if (statusName) {
|
||
$('.name span').addClass('act');
|
||
$('.name span').text(textConte1);
|
||
$('.name input').attr("disabled", false);
|
||
$('.name input').val("");
|
||
$('.name input').focus();
|
||
statusName = false;
|
||
} else {
|
||
var funParams = function (params) {
|
||
$('.name span').removeClass('act');
|
||
$('.name span').text(textConte2);
|
||
$('.name input').attr("disabled", true);
|
||
$('.name input').val($('.name input').val())
|
||
statusName = true;
|
||
}
|
||
setInfo($('.name input').val(), null, funParams)
|
||
}
|
||
})
|
||
// 保存账户接口
|
||
function savePayAccount(payoneer, usdt, payPal, fun) {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'post',
|
||
url: urlPrefix + '/family/savePayAccount',
|
||
data: { payoneer, usdt, payPal },
|
||
success(res) {
|
||
if (res.code === 200) {
|
||
fun();
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
$('.payoneer span').click(function () {
|
||
var funParams = function (params) {
|
||
$('.payoneer input').val($('.payoneer input').val())
|
||
$('.payoneer span').hide();
|
||
}
|
||
savePayAccount($('.payoneer input').val(), null, null, funParams)
|
||
})
|
||
$('.usdt span').click(function () {
|
||
var funParams = function (params) {
|
||
$('.usdt input').val($('.usdt input').val())
|
||
$('.usdt span').hide();
|
||
}
|
||
savePayAccount(null, $('.usdt input').val(), null, funParams)
|
||
})
|
||
$('.paypal span').click(function () {
|
||
var funParams = function (params) {
|
||
$('.paypal input').val($('.paypal input').val())
|
||
$('.paypal span').hide();
|
||
}
|
||
savePayAccount(null, null, $('.paypal input').val(), funParams)
|
||
}) |