From b0defffdd56df59265f6e42ecf66c2759ba5df7c Mon Sep 17 00:00:00 2001 From: Dragon <13925835632@139.com> Date: Mon, 28 Nov 2022 18:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90h5=E6=B3=A8=E5=86=8C=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/peko/modules/register/index.html | 4 +- view/peko/modules/register/js/des.js | 9 +++ view/peko/modules/register/js/index.js | 107 +++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 view/peko/modules/register/js/des.js diff --git a/view/peko/modules/register/index.html b/view/peko/modules/register/index.html index c0c884f..197acd8 100644 --- a/view/peko/modules/register/index.html +++ b/view/peko/modules/register/index.html @@ -18,7 +18,7 @@
-
獲取驗證碼
+
獲取驗證碼
提交
@@ -38,6 +38,8 @@ + + \ No newline at end of file diff --git a/view/peko/modules/register/js/des.js b/view/peko/modules/register/js/des.js new file mode 100644 index 0000000..a095725 --- /dev/null +++ b/view/peko/modules/register/js/des.js @@ -0,0 +1,9 @@ +//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(); +} \ No newline at end of file diff --git a/view/peko/modules/register/js/index.js b/view/peko/modules/register/js/index.js index e3658b1..b5cde1b 100644 --- a/view/peko/modules/register/js/index.js +++ b/view/peko/modules/register/js/index.js @@ -23,18 +23,23 @@ const toastMsg = (content = '操作完成', time = 2) => { var browser = checkVersion(); const urlPrefix = getUrlPrefix(); var getUrl = getQueryString(); +var time = 59; +var isClick = true; if (EnvCheck() == 'test') {//degBug new VConsole(); } $(function () { getInfoFromClient();//请求依赖 }) -function request () { +function request (phone, num) { showLoading() networkRequest({ - type: 'GET', - url: urlPrefix + '', - data: {}, + type: 'POST', + url: urlPrefix + '/phone/auth/apply', + data: { + phone: `${phone}`, + phoneAreaCode: num + }, success: function (res) { if (res.code == 200) { $('.box .phone input').val(''); @@ -43,20 +48,91 @@ function request () { hideLoading(layerIndex) } else { hideLoading(layerIndex) - toastMsg(ress.message) + toastMsg(res.message) } }, error () { + hideLoading(layerIndex) toastMsg('網絡錯誤'); } }); } +function getCode (num, phone, code) { + showLoading() + networkRequest({ + type: 'POST', + url: urlPrefix + '/sms/getCode', + data: { + mobile: encryptDes(`${num}${phone}`, "1ea53d260ecf11e7b56e00163e046a26"), + type: 15, + phoneAreaCode: num + }, + success: function (res) { + if (res.code == 200) { + timerFun() + hideLoading(layerIndex) + toastMsg(res.message) + } else { + hideLoading(layerIndex) + toastMsg(res.message) + } + }, + error () { + hideLoading(layerIndex) + toastMsg('網絡錯誤'); + } + }); +} +function verify (num, phone, code) { + $.ajax({ + type: 'POST', + url: urlPrefix + '/sms/verify', + data: { + mobile: `${num}${phone}`, + phoneAreaCode: num, + code, + }, + beforeSend: function (request) { + }, + success: function (res) { + if (res.code == 200) { + request(phone, num) + } else { + hideLoading(layerIndex) + toastMsg(res.message) + } + }, + error: function (data) { + hideLoading(layerIndex) + toastMsg('網絡錯誤'); + } + }) +} // 提交按钮 $('.box .but').click(function () { var num = Number($('.box .phone .num').text().match(/\d+/)[0]); var phone = Number($('.box .phone input').val()); var code = Number($('.box .code input').val()); - console.log(num, phone, code); + if (code == '') { + toastMsg('請輸入驗證碼'); + } else { + verify(num, phone, code) + } +}) +// 获取验证码按钮 +$('.box .code .num').click(function () { + var num = Number($('.box .phone .num').text().match(/\d+/)[0]); + var phone = Number($('.box .phone input').val()); + var code = Number($('.box .code input').val()); + if (isClick) { + if (phone == '') { + toastMsg('請輸入手機號'); + } else { + getCode(num, phone, code); + } + } else { + console.log('倒计时中'); + } }) // 关闭弹窗 $('.pop_up .pop_up_in img').click(function () { @@ -65,4 +141,21 @@ $('.pop_up .pop_up_in img').click(function () { // 关闭弹窗 $('.pop_up .pop_up_in .but').click(function () { $('.pop_up').hide(); -}) \ No newline at end of file +}) + +function timerFun () { + // 开启定时器 + var timer = setInterval(function () { + // 判断剩余秒数 + if (time == 0) { + // 清除定时器和复原按钮 + clearInterval(timer); + $('.box .code .num').text('獲取驗證碼'); + isClick = true; + } else { + $('.box .code .num').text(`${time}秒後重新獲取`); + time--; + isClick = false; + } + }, 1000); +} \ No newline at end of file