使用 uview 重构实际登陆

This commit is contained in:
YunaiV 2021-11-28 20:48:41 +08:00
parent 0d8f10cf1f
commit ccb56b3b99
2 changed files with 49 additions and 71 deletions

View File

@ -2,26 +2,33 @@ import { request } from '@/common/js/request.js'
// 手机号 + 密码登陆 // 手机号 + 密码登陆
export function login(mobile, password) { export function login(mobile, password) {
const data = {
mobile,
password
}
return request({ return request({
url: 'login', url: 'login',
method: 'post', method: 'post',
data: data data: {
mobile, password
}
}) })
} }
// 手机号 + 验证码登陆 // 手机号 + 验证码登陆
export function smsLogin(mobile, code) { export function smsLogin(mobile, code) {
const data = {
mobile,
code
}
return request({ return request({
url: 'sms-login', url: 'sms-login',
method: 'post', method: 'post',
data: data data: {
mobile, code
}
}) })
}
// 发送手机验证码
export function sendSmsCode(mobile, scene) {
return request({
url: 'send-sms-code',
method: 'post',
data: {
mobile, scene
}
})
} }

View File

@ -1,11 +1,8 @@
<template> <template>
<view class="app"> <view class="app">
<!-- 左下角的环 -->
<view class="left-bottom-sign"></view>
<!-- 右上角的折角 -->
<view class="right-top-sign"></view>
<!-- 左上角的 x 关闭 --> <!-- 左上角的 x 关闭 -->
<view class="back-btn mix-icon icon-guanbi" @click="navBack"></view> <view class="back-btn mix-icon icon-guanbi" @click="navBack"></view>
<!-- 用户协议 --> <!-- 用户协议 -->
<view class="agreement center"> <view class="agreement center">
<text class="mix-icon icon-xuanzhong" :class="{active: agreement}" @click="checkAgreement"></text> <text class="mix-icon icon-xuanzhong" :class="{active: agreement}" @click="checkAgreement"></text>
@ -26,8 +23,8 @@
<!-- 判断使用验证码还是密码 --> <!-- 判断使用验证码还是密码 -->
<u-form-item prop="code" borderBottom v-if="loginType == 'code'"> <u-form-item prop="code" borderBottom v-if="loginType == 'code'">
<u--input type="number" v-model="form.code" placeholder="请输入验证码" border="none"></u--input> <u--input type="number" v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
<u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini" :disabled="disabled1"></u-button> <u-button slot="right" @tap="getCode" :text="uCode.tips" type="success" size="mini" :disabled="uCode.disabled"></u-button>
<u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code> <u-code ref="uCode" @change="codeChange" seconds="60" @start="uCode.disabled === true" @end="uCode.disabled === false"></u-code>
</u-form-item> </u-form-item>
<u-form-item prop="password" borderBottom v-else> <u-form-item prop="password" borderBottom v-else>
<u--input password v-model="form.password" placeholder="请输入密码" border="none"></u--input> <u--input password v-model="form.password" placeholder="请输入密码" border="none"></u--input>
@ -69,7 +66,7 @@
<script> <script>
import { checkStr } from '@/common/js/util' import { checkStr } from '@/common/js/util'
import { login, smsLogin } from '@/api/system/auth.js' import { login, smsLogin, sendSmsCode } from '@/api/system/auth.js'
import loginMpWx from './mixin/login-mp-wx.js' import loginMpWx from './mixin/login-mp-wx.js'
import loginAppWx from './mixin/login-app-wx.js' import loginAppWx from './mixin/login-app-wx.js'
@ -78,7 +75,7 @@
data() { data() {
return { return {
agreement: true, agreement: true,
loginType: 'password', // code password loginType: 'code', // code password
loading: false, // loading: false, //
rules: { rules: {
mobile: [{ mobile: [{
@ -98,8 +95,10 @@
code: '', code: '',
password: '', password: '',
}, },
disabled1: false, uCode: {
tips: '', tips: '',
disable: false,
}
} }
}, },
onLoad() { onLoad() {
@ -126,11 +125,10 @@
this.loading = false; this.loading = false;
}) })
}).catch(errors => { }).catch(errors => {
debugger;
}); });
}, },
// //
loginSuccessCallBack(data){ loginSuccessCallBack(data) {
this.$util.msg('登录成功'); this.$util.msg('登录成功');
this.$store.commit('setToken', data); this.$store.commit('setToken', data);
// TODO // TODO
@ -139,7 +137,9 @@
}, 1000) }, 1000)
}, },
navBack() { navBack() {
uni.navigateBack(); uni.navigateBack({
delta: 1
});
}, },
setLoginType(loginType) { setLoginType(loginType) {
this.loginType = loginType; this.loginType = loginType;
@ -151,8 +151,8 @@
required: true, required: true,
message: '请输入验证码' message: '请输入验证码'
}, { }, {
min: 1000, min: 4,
max: 999999, max: 6,
message: '验证码不正确' message: '验证码不正确'
}]; }];
} else { } else {
@ -181,24 +181,27 @@
})) }))
}, },
codeChange(text) { codeChange(text) {
this.tips = text; this.uCode.tips = text;
}, },
getCode() { getCode() {
if (this.$refs.uCode.canGetCode) { //
// if (!this.$refs.uCode.canGetCode) {
uni.showLoading({ return;
title: '正在获取验证码' }
}) //
setTimeout(() => { this.$refs.form.validateField('mobile', errors => {
uni.hideLoading(); if (errors.length > 0) {
// this.start() uni.$u.toast(errors[0].message);
return;
}
// TODO
sendSmsCode(this.form.mobile, 1).then(data => {
uni.$u.toast('验证码已发送'); uni.$u.toast('验证码已发送');
// //
this.$refs.uCode.start(); this.$refs.uCode.start();
}, 2000); }).catch(erros => {
} else { })
uni.$u.toast('倒计时结束后再发送'); })
}
}, },
} }
} }
@ -243,41 +246,9 @@
.left-top-sign { .left-top-sign {
font-size: 120rpx; font-size: 120rpx;
color: #f8f8f8; color: #f8f8f8;
position:relative; position: relative;
left: -12rpx; left: -12rpx;
} }
.left-bottom-sign {
position: absolute;
left: -270rpx;
bottom: -320rpx;
border: 100rpx solid #d0d1fd;
border-radius: 50%;
padding: 180rpx;
}
.right-top-sign {
position:absolute;
top: 80rpx;
right: -30rpx;
z-index: 95;
&:before, &:after{
display:block;
content:"";
width: 400rpx;
height: 80rpx;
background: #b4f3e2;
}
&:before{
transform: rotate(50deg);
border-top-right-radius: 50px;
}
&:after{
position: absolute;
right: -198rpx;
top: 0;
transform: rotate(-50deg);
border-top-left-radius: 50px;
}
}
/** 手机登录部分 */ /** 手机登录部分 */
.input-content { .input-content {