Browse Source

成功对接登录注册接口

lihuilin/feature-20251024095243-我的
Ethereal 4 weeks ago
parent
commit
6e1b299fad
  1. 18
      api/start/login.js
  2. 152
      pages/start/Registration/Registration.vue
  3. 34
      pages/start/login/login.vue
  4. 46
      pages/start/recoverPassword/recoverPassword.vue

18
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,
})
}

152
pages/start/Registration/Registration.vue

@ -149,9 +149,10 @@
<button class="register-btn" @click="register">注册</button>
<!-- 或者 -->
<text class="or-text" @click="goToLogin">已有账号
<text class="or-text" @click="goToLogin"
>已有账号
<text class="link">登录</text>
</text>
</text>
<!-- 同意弹窗 -->
<uniPopup ref="agreementPopup" type="dialog">
@ -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 = "重新发送";

34
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",
});
}

46
pages/start/recoverPassword/recoverPassword.vue

@ -46,7 +46,7 @@
<view v-else class="switch-container-occupy"> </view>
<!-- 输入框 -->
<view v-if="isRecovering" class="input-container">
<view >
<view>
<!-- 修改邮箱输入框容器将图标包含在内 -->
<view class="input-with-icon">
<image
@ -56,7 +56,6 @@
/>
<input
class="input-field"
:type="newPasswordLookFirst ? 'text' : 'password'"
placeholder="输入新密码"
v-model="newPasswordFirst"
@ -79,7 +78,6 @@
alt=""
/>
<input
class="input-field"
:type="newPasswordLookSecond ? 'text' : 'password'"
placeholder="再次确认"
@ -211,7 +209,10 @@
</text>
<!-- 或者 -->
<text class="or-text" @click="goToLogin">已有账号登录 </text>
<text class="or-text" @click="goToLogin">已有账号
<text class="link">登录
</text>
</text>
<!-- 同意弹窗 -->
<uniPopup ref="agreementPopup" type="dialog">
@ -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 = "重新发送";

Loading…
Cancel
Save