2023-07-10 18:52:04 +08:00
|
|
|
let urlPrefix = getUrlPrefix()
|
|
|
|
let browser = checkVersion()
|
|
|
|
let env = EnvCheck();
|
|
|
|
if (env == 'test') {
|
|
|
|
new VConsole();
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
// 封裝layer消息提醒框
|
2023-07-10 18:52:04 +08:00
|
|
|
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'
|
|
|
|
})
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
var idOrPhone = true;//判斷id登入或手機號登入
|
|
|
|
var times = 0;//倒計時計時器
|
|
|
|
var isClick = true;//判斷是否再次獲取驗證碼
|
2023-07-11 18:01:38 +08:00
|
|
|
var token;
|
2023-07-10 18:52:04 +08:00
|
|
|
$(function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
getInfoFromClient()
|
|
|
|
setTimeout(function () {
|
|
|
|
getAreaInfo();
|
|
|
|
}, 100)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-07-12 17:00:34 +08:00
|
|
|
// 獲取驗證碼接口
|
2023-07-10 18:52:04 +08:00
|
|
|
function getCode () {
|
2023-07-12 17:29:57 +08:00
|
|
|
var mobileDes = encryptDes(`${$('.box .phone .phoneNumberBox .prefix b').text()}${$('.box .phone .phoneNumberBox .phoneNumber').val()}`, '1ea53d260ecf11e7b56e00163e046a26');
|
2023-07-10 18:52:04 +08:00
|
|
|
showLoading()
|
|
|
|
networkRequest({
|
|
|
|
type: 'POST',
|
|
|
|
url: urlPrefix + '/sms/getCode',
|
2023-07-11 17:05:35 +08:00
|
|
|
headers: { "pub_uid": "0" },
|
2023-07-11 15:27:08 +08:00
|
|
|
data: { mobile: mobileDes, phoneAreaCode: $('.box .phone .phoneNumberBox .prefix b').text(), type: 2 },
|
2023-07-10 18:52:04 +08:00
|
|
|
success (res) {
|
|
|
|
if (res.code === 200) {
|
2023-07-12 17:29:57 +08:00
|
|
|
toastMsg(res.message);
|
2023-07-10 18:52:04 +08:00
|
|
|
$('.box .phone .codeBox .codeBut').addClass('codeButTime')
|
|
|
|
timerFun()
|
|
|
|
} else {
|
|
|
|
toastMsg(res.message)
|
|
|
|
}
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
},
|
|
|
|
error (err) {
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-07-11 18:01:38 +08:00
|
|
|
// ticket接口
|
|
|
|
function ticket () {
|
|
|
|
showLoading()
|
|
|
|
networkRequest({
|
|
|
|
type: 'POST',
|
|
|
|
url: urlPrefix + '/oauth/ticket',
|
|
|
|
data: { issue_type: "multi", access_token: token },
|
|
|
|
success (res) {
|
|
|
|
if (res.code === 200) {
|
|
|
|
sessionStorage.setItem("uid", res.data.uid);
|
2023-07-12 18:27:12 +08:00
|
|
|
sessionStorage.setItem("ticket", res.data.tickets[0].ticket);
|
2023-07-11 18:01:38 +08:00
|
|
|
window.location.href = './index.html'
|
|
|
|
} else {
|
|
|
|
toastMsg(res.message)
|
|
|
|
}
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
},
|
|
|
|
error (err) {
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-07-11 16:05:21 +08:00
|
|
|
// 登入接口
|
2023-07-11 15:27:08 +08:00
|
|
|
function oauthToken () {
|
|
|
|
if (idOrPhone) {
|
2023-07-14 17:20:38 +08:00
|
|
|
var phone = encryptDes($('.box .idLogin .id').val(), '1ea53d260ecf11e7b56e00163e046a26');
|
2023-07-12 17:00:34 +08:00
|
|
|
var password = encryptDes($('.box .idLogin .password').val(), '1ea53d260ecf11e7b56e00163e046a26');
|
2023-07-11 15:27:08 +08:00
|
|
|
} else {
|
|
|
|
var phone = $('.box .phone .phoneNumberBox .phoneNumber').val();
|
|
|
|
var code = $('.box .phone .codeBox .code').val();
|
|
|
|
var phoneAreaCode = $('.box .phone .phoneNumberBox .prefix b').text();
|
|
|
|
}
|
2023-07-10 18:52:04 +08:00
|
|
|
showLoading()
|
|
|
|
networkRequest({
|
|
|
|
type: 'POST',
|
2023-07-17 14:32:06 +08:00
|
|
|
url: urlPrefix + '/oauth/h5/token',
|
2023-07-14 15:27:25 +08:00
|
|
|
data: idOrPhone ? {
|
2023-07-17 14:32:06 +08:00
|
|
|
"grant_type": "password", phone, password,
|
2023-07-14 15:27:25 +08:00
|
|
|
} :
|
2023-07-17 14:32:06 +08:00
|
|
|
{ grant_type: 'verify_code', phoneAreaCode, phone:`${phoneAreaCode}${phone}`, code,},
|
2023-07-10 18:52:04 +08:00
|
|
|
success (res) {
|
|
|
|
if (res.code === 200) {
|
2023-07-11 18:01:38 +08:00
|
|
|
token = res.data.access_token;
|
2023-07-17 14:32:06 +08:00
|
|
|
// ticket();
|
|
|
|
sessionStorage.setItem("uid", res.data.uid);
|
|
|
|
sessionStorage.setItem("ticket", token);
|
|
|
|
window.location.href = './index.html'
|
2023-07-10 18:52:04 +08:00
|
|
|
} else {
|
|
|
|
toastMsg(res.message)
|
|
|
|
}
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
},
|
|
|
|
error (err) {
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
// 區號接口
|
2023-07-10 18:52:04 +08:00
|
|
|
function getAreaInfo () {
|
|
|
|
showLoading()
|
|
|
|
networkRequest({
|
|
|
|
type: 'GEt',
|
|
|
|
url: urlPrefix + '/areaInfo/list',
|
|
|
|
success (res) {
|
|
|
|
if (res.code === 200) {
|
|
|
|
var str = '';
|
|
|
|
res.data.forEach((res, i) => {
|
|
|
|
str += `
|
|
|
|
|
|
|
|
<span>${res.name} +${res.phoneAreaCode}</span>
|
|
|
|
`
|
|
|
|
});
|
|
|
|
$('.area .box .list').append(str);
|
|
|
|
$('.area .box .list span').click(function () {
|
|
|
|
$('.box .phone .phoneNumberBox .prefix b').text($(this).text().replace(/[^0-9]/gi, ''));
|
|
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
toastMsg(res.message)
|
|
|
|
}
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
},
|
|
|
|
error (err) {
|
|
|
|
hideLoading(layerIndex)
|
|
|
|
toastMsg('網絡錯誤,請退出重進')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
// 點擊獲取驗證碼
|
2023-07-10 18:52:04 +08:00
|
|
|
$('.box .phone .codeBox .codeBut').click(function () {
|
|
|
|
var val = $('.box .phone .phoneNumberBox .phoneNumber').val();
|
|
|
|
if (val == '') {
|
|
|
|
toastMsg('請輸入手機號')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (isClick) {
|
|
|
|
getCode()
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2023-07-12 17:00:34 +08:00
|
|
|
// 倒計時
|
2023-07-10 18:52:04 +08:00
|
|
|
function timerFun () {
|
|
|
|
isClick = false;
|
|
|
|
times = 59;
|
2023-07-12 17:00:34 +08:00
|
|
|
// 開啟定時器
|
2023-07-10 18:52:04 +08:00
|
|
|
var timer = setInterval(function () {
|
2023-07-12 17:00:34 +08:00
|
|
|
// 判斷剩余秒數
|
2023-07-10 18:52:04 +08:00
|
|
|
if (times == 0) {
|
2023-07-12 17:00:34 +08:00
|
|
|
// 清除定時器和復原按鈕
|
2023-07-10 18:52:04 +08:00
|
|
|
clearInterval(timer);
|
|
|
|
$('.box .phone .codeBox .codeBut').text('獲取驗證碼');
|
|
|
|
$('.box .phone .codeBox .codeBut').removeClass('codeButTime')
|
|
|
|
isClick = true;
|
|
|
|
} else {
|
|
|
|
$('.box .phone .codeBox .codeBut').text(`${times}秒`);
|
|
|
|
times--;
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
// 切換登入方式按鈕
|
2023-07-10 18:52:04 +08:00
|
|
|
$('.box .hone').click(function () {
|
|
|
|
idOrPhone = !idOrPhone;
|
|
|
|
$('.box .phone .phoneNumberBox .phoneNumber,.box .phone .codeBox .code,.box .idLogin .id,.box .idLogin .password').val('');
|
|
|
|
$('.box .but').removeClass('butok');
|
|
|
|
if (idOrPhone) {
|
|
|
|
$('.idLogin').show();
|
|
|
|
$('.phone').hide();
|
2023-08-03 14:11:46 +08:00
|
|
|
$('.box .hone').text('piko手機號登錄');
|
2023-07-10 18:52:04 +08:00
|
|
|
} else {
|
|
|
|
$('.phone').show();
|
|
|
|
$('.idLogin').hide();
|
2023-08-03 14:11:46 +08:00
|
|
|
$('.box .hone').text('piko賬號登錄');
|
2023-07-10 18:52:04 +08:00
|
|
|
}
|
|
|
|
})
|
2023-07-12 17:00:34 +08:00
|
|
|
// 打開選擇區號
|
2023-07-10 18:52:04 +08:00
|
|
|
$('.box .phone .phoneNumberBox .prefix').click(function () {
|
|
|
|
$('.area').show();
|
|
|
|
return false;
|
|
|
|
})
|
2023-07-12 17:00:34 +08:00
|
|
|
// 關閉選擇區號
|
2023-07-10 18:52:04 +08:00
|
|
|
$('.area').click(function () {
|
|
|
|
$('.area').hide();
|
|
|
|
return false;
|
|
|
|
})
|
2023-07-12 17:00:34 +08:00
|
|
|
//監聽是否可以登入函數
|
2023-07-10 18:52:04 +08:00
|
|
|
function phoneFun () {
|
|
|
|
var num1 = $(".box .idLogin .id").val();
|
|
|
|
var num2 = $(".box .idLogin .password").val();
|
|
|
|
var num3 = $(".box .phone .phoneNumberBox .phoneNumber").val();
|
|
|
|
var num4 = $(".box .phone .codeBox .code").val();
|
|
|
|
if (num1 != '' && num2 != '' || num3 != '' && num4 != '') {
|
|
|
|
$('.box .but').addClass('butok');
|
2023-07-11 15:27:08 +08:00
|
|
|
return true;
|
2023-07-10 18:52:04 +08:00
|
|
|
} else {
|
|
|
|
$('.box .but').removeClass('butok');
|
2023-07-11 15:27:08 +08:00
|
|
|
return false;
|
2023-07-10 18:52:04 +08:00
|
|
|
}
|
|
|
|
}
|
2023-07-12 17:00:34 +08:00
|
|
|
// 監聽賬號輸入
|
2023-07-10 18:52:04 +08:00
|
|
|
$(".box .idLogin .id").on("keyup", function () {
|
|
|
|
phoneFun()
|
|
|
|
});
|
2023-07-12 17:00:34 +08:00
|
|
|
// 監聽密碼輸入
|
2023-07-10 18:52:04 +08:00
|
|
|
$(".box .idLogin .password").on("keyup", function () {
|
|
|
|
phoneFun()
|
|
|
|
});
|
2023-07-12 17:00:34 +08:00
|
|
|
// 監聽手機號輸入
|
2023-07-10 18:52:04 +08:00
|
|
|
$(".box .phone .phoneNumberBox .phoneNumber").on("keyup", function () {
|
|
|
|
phoneFun()
|
|
|
|
});
|
2023-07-12 17:00:34 +08:00
|
|
|
// 監聽驗證碼輸入
|
2023-07-10 18:52:04 +08:00
|
|
|
$(".box .phone .codeBox .code").on("keyup", function () {
|
|
|
|
phoneFun()
|
2023-07-11 15:27:08 +08:00
|
|
|
});
|
2023-07-12 17:00:34 +08:00
|
|
|
// 登入按鈕
|
2023-07-11 15:27:08 +08:00
|
|
|
$('.box .but').click(function () {
|
|
|
|
if (phoneFun()) {
|
|
|
|
oauthToken();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
//DES加密
|
|
|
|
const encryptDes = (message, key) => {
|
|
|
|
var keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
|
|
var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
|
|
|
|
mode: CryptoJS.mode.ECB,
|
|
|
|
padding: CryptoJS.pad.Pkcs7
|
|
|
|
});
|
|
|
|
return encrypted.toString();
|
|
|
|
}
|