diff --git a/api/start/login.js b/api/start/login.js index aaf3f73..aecf0cf 100644 --- a/api/start/login.js +++ b/api/start/login.js @@ -34,9 +34,7 @@ export const SendEmailCodeApi = (data) => { return http({ method: 'POST', url: '/UserLogin/sendEmail', - data: { - data - } + data: data }) } @@ -51,9 +49,7 @@ export const SendPhoneCodeApi = (data) => { return http({ method: 'POST', url: '/UserLogin/sendPhone', - data: { - data - } + data:data }) } @@ -63,13 +59,11 @@ export const SendPhoneCodeApi = (data) => { * 注册 */ -export const register = (data) => { +export const registerApi = (data) => { return http({ - method: 'GET', - url: '/register', - data: { - data - }, + method: 'POST', + url: '/UserLogin/register', + data: data, }) } diff --git a/pages/start/Registration/Registration.vue b/pages/start/Registration/Registration.vue index 9ef0ba7..65be655 100644 --- a/pages/start/Registration/Registration.vue +++ b/pages/start/Registration/Registration.vue @@ -149,9 +149,10 @@ - 已有账号? + 已有账号? 登录 - + @@ -184,6 +185,11 @@ import countryList from "../login/list"; import footerBar from "../../../components/footerBar-cn.vue"; import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue"; import { verificationPhone, verificationEmail } from "../login/verification"; +import { + registerApi, + SendEmailCodeApi, + SendPhoneCodeApi, +} from "../../../api/start/login"; const type = ref("member"); const email = ref(""); @@ -247,39 +253,76 @@ function switchPhone() { verifyCode.value = ""; } -// function register() { -// if (switchType.value === "Email") { -// // 登录逻辑 -// if (!email.value) { -// uni.showToast({ -// title: "请输入邮箱地址", -// icon: "none", -// }); -// return; -// } - -// // 发送登录请求 -// console.log("登录:", email.value); -// } - -// if (switchType.value === "Phone") { -// // 登录逻辑 -// if (!phone.value) { -// uni.showToast({ -// title: "请输入手机号码", -// icon: "none", -// }); -// return; -// } - -// // 发送登录请求 -// console.log("登录:", phone.value); -// } -// } -function register() { +// 注册 +async function register() { if (!basicVerification()) { return; } + + const account = changeAccount(); + const registerType = changeLoginType(); + + const res = await registerApi({ + registerType: registerType, + account: account, + verifyCode: verifyCode.value, + agree: agreed.value, + }); + + const message = res.message; + if (res.code === 200) { + // 登录成功 + uni.showToast({ + title: "注册成功", + icon: "success", + }); + + const userStore = useUserStore(); + userStore.setUserInfo(res.data); + + console.log("userInfo为", userStore.userInfo); + + // 跳转到首页 + uni.navigateTo({ + url: "/pages/home/home", + }); + } else { + // 登录失败 + uni.showToast({ + title: message, + icon: "none", + }); + } +} + +// 请求账户 +function changeAccount() { + if (switchType.value === "User") { + account.value = deepChartID.value; + } + + if (switchType.value === "Phone") { + account.value = `${country.value}${phone.value}`; + } + if (switchType.value === "Email") { + account.value = email.value; + } + + return account.value; +} + +// 改变请求时的type +function changeLoginType() { + if (switchType.value === "User") { + return "DCCODE"; + } + + if (switchType.value === "Phone") { + return "PHONE"; + } + if (switchType.value === "Email") { + return "EMAIL"; + } } // 基础验证 @@ -367,8 +410,8 @@ function basicVerification() { } // 验证码验证 -function VerCodeVerfifcation() { - if (switchType.value === "Phone") { +function VerCodeVerfifcation() { + if (switchType.value === "Phone") { if (!phone.value) { uni.showToast({ title: "请输入手机号", @@ -432,16 +475,47 @@ function onPhoneInput(e) { } } - -function sendCode() { - - if (!VerCodeVerfifcation()) { - return ; +async function sendCode() { + if (!VerCodeVerfifcation()) { + return; } // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; + console.log("发送验证码"); + if (switchType.value === "Phone") { + // 发送验证码 + + const phoneAll = `${country.value}${phone.value}`; + const res = await SendPhoneCodeApi({ + phone: phoneAll, + }); + console.log("手机验证码:", res.message); + + if (!res) { + uni.showToast({ + title: "请求失败", + icon: "none", + }); + } + } + if (switchType.value === "Email") { + // 发送验证码 + const res = await SendEmailCodeApi({ + email: email.value, + }); + console.log("邮箱验证码:", res.message); + + if (!res) { + uni.showToast({ + title: "请求失败", + icon: "none", + }); + } + } + + // 设置按钮为禁用状态 isCodeBtnDisabled.value = true; codeBtnText.value = "重新发送"; diff --git a/pages/start/login/login.vue b/pages/start/login/login.vue index efdbb49..331f8d4 100644 --- a/pages/start/login/login.vue +++ b/pages/start/login/login.vue @@ -351,26 +351,6 @@ async function Login() { idToken: "", }); - // const res = await uni.request({ - // url: 'https://hwjb.homilychart.com/testApi/UserLogin/login', - // data: {}, - // header: { - // Accept: 'application/json', - // 'Content-Type': 'application/json' }, - // method: 'POST', - // sslVerify: true, - // success: ({ data, statusCode, header }) => { - // console.log(data); - // console.log(statusCode); - // console.log(header); - - - // }, - // fail: (error) => { - // console.log("error是",error); - // } - // }) - const message = res.message; if (res.code === 200) { // 登录成功 @@ -385,8 +365,8 @@ async function Login() { console.log("userInfo为", userStore.userInfo); // 跳转到首页 - uni.switchTab({ - url: "/pages/start/index/index", + uni.navigateTo({ + url: "/pages/home/home", }); } else { // 登录失败 @@ -658,10 +638,9 @@ async function sendCode() { }); console.log("手机验证码:", res.message); - const message = res.message; - if (res.code === 200) { + if (!res) { uni.showToast({ - title: message, + title: "请求失败", icon: "none", }); } @@ -673,10 +652,9 @@ async function sendCode() { }); console.log("邮箱验证码:", res.message); - const message = res.message; - if (res.code === 200) { + if (!res) { uni.showToast({ - title: message, + title: "请求失败", icon: "none", }); } diff --git a/pages/start/recoverPassword/recoverPassword.vue b/pages/start/recoverPassword/recoverPassword.vue index 9455cfe..3cf2623 100644 --- a/pages/start/recoverPassword/recoverPassword.vue +++ b/pages/start/recoverPassword/recoverPassword.vue @@ -46,7 +46,7 @@ - + - 已有账号?登录 + 已有账号? + 登录 + + @@ -234,6 +235,7 @@ import countryList from "../login/list"; import footerBar from "../../../components/footerBar-cn.vue"; import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue"; import { verificationPhone, verificationEmail } from "../login/verification"; +import { SendEmailCodeApi, SendPhoneCodeApi } from "../../../api/start/login"; const type = ref("member"); const email = ref(""); @@ -332,7 +334,6 @@ function register() { } console.log("123"); - const phoneAll = `${country.value}${phone.value}`; console.log("完整手机号" + phoneAll); @@ -399,6 +400,13 @@ function goToLogin() { }); } +function goToRegistration() { + // 跳转到登录页 + uni.navigateTo({ + url: "/pages/start/Registration/Registration", + }); +} + function onPhoneInput(e) { // 确保只允许输入数字 const value = e.detail.value; @@ -466,6 +474,34 @@ function sendCode() { // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; + console.log("发送验证码"); + // 发送验证码 + if (switchType.value === "Email") { + const res = SendEmailCodeApi({ + email: email.value, + }); + + if (!res) { + uni.showToast({ + title: "发送失败", + icon: "none", + }); + } + } + if (switchType.value === "Phone") { + const phoneAll = `${country.value}${phone.value}`; + + const res = SendPhoneCodeApi({ + phone: phoneAll, + }); + if (!res) { + uni.showToast({ + title: "发送失败", + icon: "none", + }); + } + } + // 设置按钮为禁用状态 isCodeBtnDisabled.value = true; codeBtnText.value = "重新发送";