diff --git a/api/start/login.js b/api/start/login.js index 3f86a58..5b1a9c5 100644 --- a/api/start/login.js +++ b/api/start/login.js @@ -13,10 +13,10 @@ import { http } from '../../utils/http' "idToken":"", //第三方登录idToken } */ -export const Login = (data) => { +export const LoginApi = (data) => { return http({ - method: 'POST', - url: '/login/wxMin/simple', + method: 'GET', + url: '/loginFailureWrongCode', data: { data }, @@ -30,13 +30,13 @@ export const Login = (data) => { * @param {*} phoneNumber * @returns */ -export const sendCode = (phoneNumber) => { +export const SendCodeApi = (data) => { return http({ - method: 'POST', - url: '/login/wxMin/simple', - data: { - phoneNumber - }, + method: 'GET', + url: '/sendCodeFailureTooFrequent', + data:{ + data + } }) } @@ -48,8 +48,8 @@ export const sendCode = (phoneNumber) => { export const register = (data) => { return http({ - method: 'POST', - url: '/login/wxMin/simple', + method: 'GET', + url: '/register', data: { data }, @@ -63,8 +63,8 @@ export const register = (data) => { export const updatePassword = (data) => { return http({ - method: 'POST', - url: '/login/wxMin/simple', + method: 'GET', + url: '/updatePassword', data: { data }, @@ -80,7 +80,7 @@ export const updatePassword = (data) => { export const postLoginAppleSimpleAPI = (phoneNumber) => { return http({ method: 'POST', - url: '/login/wxMin/simple', + url: '/login', data: { phoneNumber, }, diff --git a/package.json b/package.json index c3ef205..bc1f757 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "pinia-plugin-persistedstate": "^4.5.0" }, "scripts": { + "server-login": "json-server ./server/login.json --port 8888", "server-deepchart": "json-server ./server/deepchart.json --port 8888" } } diff --git a/pages/start/login/login.vue b/pages/start/login/login.vue index 4c89f27..8f964cf 100644 --- a/pages/start/login/login.vue +++ b/pages/start/login/login.vue @@ -242,7 +242,7 @@ import footerBar from "../../../components/footerBar-cn"; import uniPopupDialogVue from "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue"; import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue"; import { verificationPhone, verificationEmail } from "../login/verification"; -import { Login } from "../../../api/start/login"; +import { LoginApi, SendCodeApi } from "../../../api/start/login"; const deepChartID = ref(""); const type = ref("member"); @@ -257,6 +257,7 @@ const codeBtnText = ref("获取验证码"); const isCodeBtnDisabled = ref(false); // 添加验证码按钮禁用状态 const checkboxUrl = ref("../../../static/icons/Check-one-false.png"); const verifyCode = ref(""); +const account = ref(""); // 使用从list.js导入的完整国家列表数据 const countries = ref( @@ -299,18 +300,21 @@ function switchUser() { // 切换到手机注册 switchType.value = "User"; password.value = ""; + verifyCode.value = ""; } function switchEmail() { // 切换到邮箱注册 switchType.value = "Email"; password.value = ""; + verifyCode.value = ""; } function switchPhone() { // 切换到手机注册 switchType.value = "Phone"; password.value = ""; + verifyCode.value = ""; } async function register() { @@ -330,32 +334,6 @@ async function register() { }); return; } - - const res = await Login({ - loginType: "USER", - account: deepChartID.value, - verifyCode: "", - password: password.value, - useCode: "false", - idToken: "", - }); - if (res.code === 200) { - // 登录成功 - uni.showToast({ - title: "登录成功", - icon: "success", - }); - // 跳转到首页 - uni.switchTab({ - url: "/pages/start/index/index", - }); - } else { - // 登录失败 - uni.showToast({ - title: "登录失败,用户名或密码错误", - icon: "none", - }); - } } if (switchType.value === "Phone") { @@ -378,36 +356,9 @@ async function register() { const phoneAll = `${country.value}${phone.value}`; console.log("完整手机号" + phoneAll); if (!validatePhoneNumber(country.value, phone.value)) { - return; - } - - const res = await Login({ - loginType: "PHONE", - account: phoneAll, - verifyCode: verifyCode.value, - password:'', - useCode: "true", - idToken: "", - }); - if (res.code === 200) { - // 登录成功 - uni.showToast({ - title: "登录成功", - icon: "success", - }); - // 跳转到首页 - uni.switchTab({ - url: "/pages/start/index/index", - }); - } else { - // 登录失败 - uni.showToast({ - title: "验证码有误请重试", - icon: "none", - }); + return; } - // 发送登录请求 // console.log("登录:", phone.value); } @@ -441,33 +392,6 @@ async function register() { }); return; } - - - const res = await Login({ - loginType: "EMAIL", - account: email.value, - verifyCode: verifyCode.value, - password:'', - useCode: "true", - idToken: "", - }); - if (res.code === 200) { - // 登录成功 - uni.showToast({ - title: "登录成功", - icon: "success", - }); - // 跳转到首页 - uni.switchTab({ - url: "/pages/start/index/index", - }); - } else { - // 登录失败 - uni.showToast({ - title: "验证码有误请重试", - icon: "none", - }); - } // 发送登录请求 // console.log("登录:", email.value); } @@ -483,6 +407,51 @@ async function register() { // title: "登录成功", // icon: "success", // }); + + const account = changeAccount(); + + const res = await LoginApi({ + loginType: switchType.value, + account: account, + verifyCode: verifyCode.value, + password: password.value, + useCode: verifyCode.value ? true : false, + idToken: "", + }); + + const message = res.message + if (res.code === 200) { + // 登录成功 + uni.showToast({ + title: "登录成功", + icon: "success", + }); + // 跳转到首页 + uni.switchTab({ + url: "/pages/start/index/index", + }); + } 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; } // 添加弹窗引用 @@ -560,7 +529,7 @@ function onPhoneInput(e) { } } -function sendCode() { +async function sendCode() { if (switchType.value === "Phone") { if (!phone.value) { uni.showToast({ @@ -607,6 +576,22 @@ function sendCode() { // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; + + // 发送验证码 + const res = await SendCodeApi({ + + }) + console.log("验证码:",res.message); + + + const message = res.message + if(res.code ===200){ + uni.showToast({ + title: message, + icon: "none", + }); + } + // 设置按钮为禁用状态 isCodeBtnDisabled.value = true; codeBtnText.value = "重新发送"; diff --git a/server/login.json b/server/login.json index e69de29..57f17d8 100644 --- a/server/login.json +++ b/server/login.json @@ -0,0 +1,131 @@ +{ + "loginSuccessByEmail": { + "code": 200, + "message": "登录成功", + "interface": "login", + "data": { + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", + "userInfo": { + "id": "123456789", + "username": "q614588746", + "email": "q614588746@163.com" + } + } + }, + "loginFailureEmailNotFound": { + "code": 404, + "message": "账号不存在", + "interface": "login" + }, + "loginFailureWrongCode": { + "code": 400, + "message": "验证码错误", + "interface": "login" + }, + "loginSuccessByPhone": { + "code": 200, + "message": "登录成功", + "interface": "login", + "data": { + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", + "userInfo": { + "id": "987654321", + "username": "13800138000", + "phone": "13800138000" + } + } + }, + "loginSuccessByPassword": { + "code": 200, + "message": "登录成功", + "interface": "login", + "data": { + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", + "userInfo": { + "id": "556677889", + "username": "testuser" + } + } + }, + "sendCodeSuccess": { + "code": 200, + "message": "验证码发送成功", + "interface": "sendCode", + "data": { + "expireTime": 180 + } + }, + "sendCodeFailureInvalidFormat": { + "code": 400, + "message": "手机号格式错误", + "interface": "sendCode" + }, + "sendCodeFailureTooFrequent": { + "code": 429, + "message": "发送频率过高,请稍后再试", + "interface": "sendCode" + }, + "registerSuccess": { + "code": 200, + "message": "注册成功", + "interface": "register", + "data": { + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", + "userInfo": { + "id": "112233445", + "username": "newuser", + "email": "newuser@example.com" + } + } + }, + "registerFailureEmailExist": { + "code": 400, + "message": "邮箱已被注册", + "interface": "register" + }, + "registerFailurePhoneExist": { + "code": 400, + "message": "手机号已被注册", + "interface": "register" + }, + "registerFailureWrongCode": { + "code": 400, + "message": "验证码错误", + "interface": "register" + }, + "updatePasswordSuccess": { + "code": 200, + "message": "密码修改成功", + "interface": "updatePassword" + }, + "updatePasswordFailureWrongOldPassword": { + "code": 400, + "message": "旧密码错误", + "interface": "updatePassword" + }, + "updatePasswordFailureWrongCode": { + "code": 400, + "message": "验证码错误", + "interface": "updatePassword" + }, + "forgotPasswordSuccessByEmail": { + "code": 200, + "message": "密码重置成功,新密码已发送至邮箱", + "interface": "forgotPassword" + }, + "forgotPasswordSuccessByPhone": { + "code": 200, + "message": "密码重置成功,新密码已发送至手机", + "interface": "forgotPassword" + }, + "forgotPasswordFailureAccountNotFound": { + "code": 404, + "message": "账号不存在", + "interface": "forgotPassword" + }, + "forgotPasswordFailureWrongCode": { + "code": 400, + "message": "验证码错误", + "interface": "forgotPassword" + } +} \ No newline at end of file