Browse Source

添加login接口

wangyi/feature-20251022162725-启动页登录注册
Ethereal 4 weeks ago
parent
commit
2ec6045bb2
  1. 28
      api/start/login.js
  2. 1
      package.json
  3. 129
      pages/start/login/login.vue
  4. 131
      server/login.json

28
api/start/login.js

@ -13,10 +13,10 @@ import { http } from '../../utils/http'
"idToken":"", //第三方登录idToken "idToken":"", //第三方登录idToken
} }
*/ */
export const Login = (data) => {
export const LoginApi = (data) => {
return http({ return http({
method: 'POST',
url: '/login/wxMin/simple',
method: 'GET',
url: '/loginFailureWrongCode',
data: { data: {
data data
}, },
@ -30,13 +30,13 @@ export const Login = (data) => {
* @param {*} phoneNumber * @param {*} phoneNumber
* @returns * @returns
*/ */
export const sendCode = (phoneNumber) => {
export const SendCodeApi = (data) => {
return http({ 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) => { export const register = (data) => {
return http({ return http({
method: 'POST',
url: '/login/wxMin/simple',
method: 'GET',
url: '/register',
data: { data: {
data data
}, },
@ -63,8 +63,8 @@ export const register = (data) => {
export const updatePassword = (data) => { export const updatePassword = (data) => {
return http({ return http({
method: 'POST',
url: '/login/wxMin/simple',
method: 'GET',
url: '/updatePassword',
data: { data: {
data data
}, },
@ -80,7 +80,7 @@ export const updatePassword = (data) => {
export const postLoginAppleSimpleAPI = (phoneNumber) => { export const postLoginAppleSimpleAPI = (phoneNumber) => {
return http({ return http({
method: 'POST', method: 'POST',
url: '/login/wxMin/simple',
url: '/login',
data: { data: {
phoneNumber, phoneNumber,
}, },

1
package.json

@ -6,6 +6,7 @@
"pinia-plugin-persistedstate": "^4.5.0" "pinia-plugin-persistedstate": "^4.5.0"
}, },
"scripts": { "scripts": {
"server-login": "json-server ./server/login.json --port 8888",
"server-deepchart": "json-server ./server/deepchart.json --port 8888" "server-deepchart": "json-server ./server/deepchart.json --port 8888"
} }
} }

129
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 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 uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
import { verificationPhone, verificationEmail } from "../login/verification"; import { verificationPhone, verificationEmail } from "../login/verification";
import { Login } from "../../../api/start/login";
import { LoginApi, SendCodeApi } from "../../../api/start/login";
const deepChartID = ref(""); const deepChartID = ref("");
const type = ref("member"); const type = ref("member");
@ -257,6 +257,7 @@ const codeBtnText = ref("获取验证码");
const isCodeBtnDisabled = ref(false); // const isCodeBtnDisabled = ref(false); //
const checkboxUrl = ref("../../../static/icons/Check-one-false.png"); const checkboxUrl = ref("../../../static/icons/Check-one-false.png");
const verifyCode = ref(""); const verifyCode = ref("");
const account = ref("");
// 使list.js // 使list.js
const countries = ref( const countries = ref(
@ -299,18 +300,21 @@ function switchUser() {
// //
switchType.value = "User"; switchType.value = "User";
password.value = ""; password.value = "";
verifyCode.value = "";
} }
function switchEmail() { function switchEmail() {
// //
switchType.value = "Email"; switchType.value = "Email";
password.value = ""; password.value = "";
verifyCode.value = "";
} }
function switchPhone() { function switchPhone() {
// //
switchType.value = "Phone"; switchType.value = "Phone";
password.value = ""; password.value = "";
verifyCode.value = "";
} }
async function register() { async function register() {
@ -330,32 +334,6 @@ async function register() {
}); });
return; 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") { if (switchType.value === "Phone") {
@ -381,33 +359,6 @@ async function register() {
return; 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",
});
}
// //
// console.log(":", phone.value); // console.log(":", phone.value);
} }
@ -441,16 +392,34 @@ async function register() {
}); });
return; return;
} }
//
// console.log(":", email.value);
}
if (!agreed.value) {
//
agreementPopup.value.open();
return;
}
//
// uni.showToast({
// title: "",
// icon: "success",
// });
const account = changeAccount();
const res = await Login({
loginType: "EMAIL",
account: email.value,
const res = await LoginApi({
loginType: switchType.value,
account: account,
verifyCode: verifyCode.value, verifyCode: verifyCode.value,
password:'',
useCode: "true",
password: password.value,
useCode: verifyCode.value ? true : false,
idToken: "", idToken: "",
}); });
const message = res.message
if (res.code === 200) { if (res.code === 200) {
// //
uni.showToast({ uni.showToast({
@ -464,25 +433,25 @@ async function register() {
} else { } else {
// //
uni.showToast({ uni.showToast({
title: "验证码有误请重试",
title: message,
icon: "none", icon: "none",
}); });
} }
//
// console.log(":", email.value);
}
function changeAccount() {
if (switchType.value === "User") {
account.value = deepChartID.value;
} }
if (!agreed.value) {
//
agreementPopup.value.open();
return;
if (switchType.value === "Phone") {
account.value = `${country.value}${phone.value}`;
}
if (switchType.value === "Email") {
account.value = email.value;
} }
//
// uni.showToast({
// title: "",
// icon: "success",
// });
return account.value;
} }
// //
@ -560,7 +529,7 @@ function onPhoneInput(e) {
} }
} }
function sendCode() {
async function sendCode() {
if (switchType.value === "Phone") { if (switchType.value === "Phone") {
if (!phone.value) { if (!phone.value) {
uni.showToast({ uni.showToast({
@ -607,6 +576,22 @@ function sendCode() {
// //
if (isCodeBtnDisabled.value) return; 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; isCodeBtnDisabled.value = true;
codeBtnText.value = "重新发送"; codeBtnText.value = "重新发送";

131
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"
}
}
Loading…
Cancel
Save