364 lines
13 KiB
JavaScript
364 lines
13 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
||
let browser = checkVersion()
|
||
let env = EnvCheck();
|
||
if (env == 'test') {
|
||
new VConsole();
|
||
}
|
||
// 封裝layer消息提醒框
|
||
let layerIndex
|
||
var langReplace;
|
||
var localLang;
|
||
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.history.back();
|
||
})
|
||
fuzzyMatchUpdateQueryStringParameterFun(); // 判断语言
|
||
langReplace = window.lang.replace;
|
||
localLang = window.lang;
|
||
translateFun();
|
||
h5User();
|
||
getParamOptions();
|
||
}, 100)
|
||
})
|
||
var agencySubmit = false;
|
||
function translateFun() {
|
||
var langReplace = window.lang.replace;
|
||
var localLang = window.lang;
|
||
$('.text1').text(langReplace(localLang.createGuild.text1));
|
||
$('.text2').text(langReplace(localLang.createGuild.text2));
|
||
$('.text3').text(langReplace(localLang.createGuild.text3));
|
||
$('.text4').text(langReplace(localLang.createGuild.text4));
|
||
$('.text5').text(langReplace(localLang.createGuild.text5));
|
||
$('.text6').text(langReplace(localLang.createGuild.text6));
|
||
$('.text7').text(langReplace(localLang.createGuild.text7));
|
||
$('.text8').text(langReplace(localLang.createGuild.text8));
|
||
// $('.text9').text(langReplace(localLang.createGuild.text9));
|
||
// $('.text10').text(langReplace(localLang.createGuild.text10));
|
||
$('.placeholder').attr('placeholder', langReplace(localLang.createGuild.placeholder));
|
||
$('.Area_Code').text(langReplace(localLang.createGuild.Area_Code));
|
||
$('.Contact_type').text(langReplace(localLang.createGuild.Contact_type));
|
||
$('.Select').attr('placeholder', langReplace(localLang.createGuild.Select));
|
||
$('.Please_number').attr('placeholder', langReplace(localLang.createGuild.Please_number));
|
||
$('.confirm').text(langReplace(localLang.createGuild.confirm));
|
||
|
||
}
|
||
|
||
|
||
$('.submitSuccessfully .submitSuccessfully_in .but').click(function () {
|
||
$('.submitSuccessfully').hide();
|
||
if(partitionId == 16){
|
||
if (browser.android) {
|
||
window.androidJsObj.openAppConcernedChat(92368)
|
||
} else {
|
||
window.webkit.messageHandlers.openAppConcernedChat.postMessage(92368)
|
||
}
|
||
}else{
|
||
if (browser.android) {
|
||
window.androidJsObj.closeWebView()
|
||
} else {
|
||
window.webkit.messageHandlers.closeWebView.postMessage(null)
|
||
}
|
||
}
|
||
|
||
})
|
||
function fileChangeF(e) {
|
||
var file = document.querySelector('#backImageUpload').files[0];
|
||
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 fileChangeF2(e) {
|
||
var file = document.querySelector('#backImageUpload2').files[0];
|
||
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 fileChangeF3(e) {
|
||
var file = document.querySelector('#backImageUpload3').files[0];
|
||
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, 3)
|
||
}
|
||
}
|
||
// 上傳图片接口
|
||
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(res,'-------res');
|
||
const imageUrl = `${customDomain}/${file.name}`
|
||
// 创建一个新的 Image 对象来加载图片
|
||
const img = new Image();
|
||
img.src = imageUrl;
|
||
// 监听图片加载完成事件
|
||
img.onload = () => {
|
||
if (type == 1) { // 背景
|
||
$('.info .agencyAvatar').attr('src', imageUrl);
|
||
} else if (type == 2) { // 身份证
|
||
$('.info .agentIDCardImg').attr('src', imageUrl);
|
||
} else { // 邀请人图片
|
||
$('.inviterInfo .inviterPicImg').attr('src', imageUrl);
|
||
}
|
||
hideLoading(layerIndex);
|
||
};
|
||
// 监听图片加载失败事件
|
||
img.onerror = () => {
|
||
console.error('图片加载失败:', imageUrl);
|
||
hideLoading(layerIndex);
|
||
toastMsg(langReplace(localLang.createGuild.imgerr));
|
||
};
|
||
|
||
// if (type == 1) {//背景
|
||
// $('.info .agencyAvatar').attr('src', `${customDomain}/${file.name}`);
|
||
// } else if (type == 2) {//背景
|
||
// $('.info .agentIDCardImg').attr('src', `${customDomain}/${file.name}`);
|
||
// } else {
|
||
// $('.inviterInfo .inviterPicImg').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))
|
||
}
|
||
})
|
||
}
|
||
var erbanNo;
|
||
var partitionId;
|
||
|
||
// 自己信息接口
|
||
function h5User() {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'get',
|
||
url: urlPrefix + '/web-user',
|
||
data: { uid: pubInfo.uid },
|
||
success(res) {
|
||
if (res.code == 200) {
|
||
$('.myInfo .tx').attr('src', res.data.avatar);
|
||
$('.myInfo p').text(res.data.nick);
|
||
$('.myInfo b').text(`ID:${res.data.erbanNo}`);
|
||
erbanNo = res.data.erbanNo;
|
||
if (res.data.inviteErbanNo != '' && res.data.inviteErbanNo) {
|
||
$('.inviterInfo .InviterId input').val(res.data.inviteErbanNo)
|
||
$('.inviterInfo .InviterId input').attr('disabled', 'disabled');
|
||
}
|
||
partitionId = res.data.partitionId;
|
||
if (res.data.partitionId == 16) {
|
||
$('.text9').html(langReplace(localLang.createGuild.text9_new));
|
||
$('.text10').text(langReplace(localLang.createGuild.text10_new));
|
||
} else {
|
||
$('.text9').text(langReplace(localLang.createGuild.text9));
|
||
$('.text10').text(langReplace(localLang.createGuild.text10));
|
||
}
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
// 区号接口
|
||
function getParamOptions() {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'get',
|
||
url: urlPrefix + '/guild/apply/paramOptions',
|
||
success(res) {
|
||
if (res.code == 200) {
|
||
let str = '';
|
||
res.data.areaCodeOption.forEach((item, index) => {
|
||
str += `
|
||
<div value='${item}' class="countryPub">+${item}</div>
|
||
`
|
||
});
|
||
$('.areaCodeOption .areaCode').text('+' + res.data.areaCodeOption[0]);
|
||
$('.pub .pub_in .countryPubTab').append(str);
|
||
|
||
let contactTypeStr = '';
|
||
res.data.contactTypeOption.forEach((item, index) => {
|
||
contactTypeStr += `
|
||
<div value='${item}' class="countryPub">${item}</div>
|
||
`
|
||
});
|
||
$('.pub_Contact .pub_in .countryPubTab').append(contactTypeStr);
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
// 创建接口
|
||
function apply(obj) {
|
||
showLoading()
|
||
networkRequest({
|
||
type: 'post',
|
||
contentType: 'application/json',
|
||
url: urlPrefix + '/guild/apply',
|
||
data: obj,
|
||
success(res) {
|
||
if (res.code == 200) {
|
||
$('.submitSuccessfully').show();
|
||
} else {
|
||
toastMsg(res.message)
|
||
}
|
||
hideLoading(layerIndex)
|
||
},
|
||
error(err) {
|
||
hideLoading(layerIndex)
|
||
toastMsg(langReplace(localLang.demoModule.layerIndex3))
|
||
}
|
||
})
|
||
}
|
||
$('.butBox').click(function () {
|
||
var guildAvatar = $('.info .agencyAvatar').attr('src');
|
||
var guildName = $('.info .agencyName input').val();
|
||
var guildContact = $('.info .agentContactInfo input').val();
|
||
var countryCode = $('.areaCode').text().replace('+', '');
|
||
;
|
||
var idCard = $('.info .agentIDCardImg').attr('src');
|
||
var inviteErbanNo = $('.inviterInfo .InviterId input').val();
|
||
var inviteCheck = $('.inviterInfo .inviterPicImg').attr('src');
|
||
var guildContactType = $('.info .guildContactType input').val();
|
||
var obj = {};
|
||
obj.guildAvatar = guildAvatar;
|
||
obj.guildName = guildName;
|
||
obj.guildContact = countryCode + guildContact;
|
||
obj.idCard = idCard;
|
||
obj.inviteErbanNo = inviteErbanNo;
|
||
obj.inviteCheck = inviteCheck;
|
||
obj.erbanNo = erbanNo;
|
||
obj.applyUid = pubInfo.uid;
|
||
obj.guildContactType = guildContactType;
|
||
// console.log(obj);
|
||
if (guildName != '' && guildContact != '' && guildAvatar != './images/createGuildNull.png' && idCard != './images/createGuildNull.png' && guildContactType != '') {
|
||
apply(JSON.stringify(obj))
|
||
} else {
|
||
toastMsg(localLang.createGuild.null)
|
||
}
|
||
})
|
||
// 打开区号选择弹窗
|
||
$('.areaCodeOption').click(function () {
|
||
$('.pub').show()
|
||
})
|
||
var nameTitle = '886';
|
||
// 选中区号
|
||
$('.pub .pub_in').on('click', '.countryPub', function name(params) {
|
||
$(this).addClass('act').siblings().removeClass('act');
|
||
nameTitle = $(this).attr('value');
|
||
return false;
|
||
})
|
||
// 确认选中区号
|
||
$('.pub .pub_in .soure').click(function name(params) {
|
||
$('.areaCodeOption .areaCode').text('+' + nameTitle);
|
||
$('.pub').hide();
|
||
})
|
||
var ContactName;
|
||
// 打开联系方式选择弹窗
|
||
$('.Contact_box').click(function () {
|
||
$('.pub_Contact').show()
|
||
})
|
||
// 选中联系方式
|
||
$('.pub_Contact .pub_in').on('click', '.countryPub', function name(params) {
|
||
$(this).addClass('act').siblings().removeClass('act');
|
||
ContactName = $(this).attr('value');
|
||
return false;
|
||
})
|
||
// 确认选中区号
|
||
$('.pub_Contact .pub_in .soure').click(function name(params) {
|
||
$('.Contact_box .Contact_value .Select').val(ContactName);
|
||
$('.pub_Contact').hide();
|
||
}) |