This commit is contained in:
make
2025-04-21 17:49:17 +08:00
parent 7ef217c1b9
commit 2337ab4f7d
942 changed files with 209166 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
import { apiBindPhone,apiSmsCode } from '../public/api/index.js';
import { fetchApi,onError} from '../public/api/fetch.js';
import { getLoginStatus }from '../public/localstorage.js';
$(document).ready(function() {
// 登录状态
if (getLoginStatus()) {
//getUserInfo()
}else{
location.href="/login.html"
}
const PHONE_LENGTH = 0;
const PASSWORD_MIN_LENGTH = 6;
const PASSWORD_MAX_LENGTH = 20;
let intChangIndex = 0;
const $getCodeButton = $('.get-v-code');
// 去空格
const getValueAndTrim = (selector) => $(selector).length > 0 ? $(selector).val().replace(/\s*/g, "") : "";
// 手机号验证
const isValidPhone = (phone) => {
if (phone.length !== 11 ) {
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`请填写正确的手机号码`);
return false;
}
return true;
};
//验证码验证
const isValidCode = (code) => {
if (code.length !== 6 ) {
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`短信验证码必须是6位数字`);
return false;
}
return true;
};
// 提交表单逻辑
const submitForm = async (isLogin) => {
const strPhoneVal = getValueAndTrim(".sc-phone");
const strCodeVal = getValueAndTrim(".sc-code");
if (isLogin ==1) {
//绑定手机号码
if (isValidPhone(strPhoneVal) && isValidCode(strCodeVal)) {
await handleSubmit(strPhoneVal,strCodeVal);
}
}
};
const handleSubmit = async (strPhone,strVCode,) => {
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`绑定成功`);
let postData = {
'phone':strPhone,
'vcode':strVCode,
}
fetchApi(apiBindPhone, postData,successFun, onError,false)
function successFun(res) {
if (res.code == '000') {
$("#code").val('')
pageJumpFn({ 'url': '/member/info.html?free_vip_data=' + res.data.free_vip_data, 'url_type': 1 })
localStorage.setItem(storageObj.isBingPhoneReturn, true)
} else if (res.code == '2001') {
layerPopup(res.msg, 3)
} else {
layerPopup(res.msg, 3)
}
}
};
//绑定号码
$('.sc-binding-btn').on('click', function() {
submitForm(1);
});
/**
* 发送验证码
*/
const sendMsg = () => {
$(".yzm-btn").on('click', function () {
const intPhone = getValueAndTrim(".sc-phone");
if (isValidPhone(intPhone)) {
getSmsCode(intPhone);
}else{
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`请填写正确的手机号码`);
}
});
function getSmsCode(strPhone) {
let postData = {
'phone':strPhone,
'type':'reg',
}
fetchApi(apiSmsCode, postData,successFun, onError)
function successFun(res){
if (res.code == '000') {
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`发送成功,请注意查收`);
}else{
$(".sc-public-popup").show()
$(".sc-public-popup .sc-trends-text").text(`短信已在1分钟内发出请耐心等待`);
}
}
}
}
$(function () {
sendMsg()
//弹窗关闭公共方法2
$(".btn_sty_close").on('click', function () {
$(".sc-prompt-popup").hide()
});
});
});