pwd-login.vue 3.8 KB
Newer Older
1 2 3 4
<template>
	<view class="content">
		<!-- 顶部文字 -->
		<text class="title">用户名密码登录</text>
5
		<input class="input-box" :inputBorder="false" v-model="username" placeholder="请输入手机号/用户名"></input>
6
		<input type="password" class="input-box" :inputBorder="false" v-model="password" placeholder="请输入密码"></input>
7 8 9
		<view class="captcha-box" v-if="captchaBase64">
			<image class="captcha-img" @click="createCaptcha" :src="captchaBase64" mode="widthFix"></image>
			<input type="text" class="input-box captcha" :inputBorder="false" v-model="captcha" placeholder="请输入验证码"></input>
10 11
		</view>
		<uni-agreements @setAgree="agree = $event"></uni-agreements>
12 13 14 15 16 17 18 19
		<button class="send-btn" :disabled="!canLogin" :type="canLogin?'primary':'default'"
			@click="pwdLogin">登录</button>
		<!-- 忘记密码 -->
		<view class="auth-box">
			<text class="link" @click="toRetrievePwd">忘记密码</text>
			<text class="link" @click="toRegister">注册账号</text>
		</view>
		<uni-quick-login :agree="agree" ref="uniQuickLogin"></uni-quick-login>
芊里 已提交
20 21 22
	</view>
</template>

L
123  
linju 已提交
23
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
24
	import mixin from '../common/login-page.mixin.js';
L
123  
linju 已提交
25
	export default {
26
		mixins: [mixin],
芊里 已提交
27
		data() {
28 29 30
			return {
				"password": "",
				"username": "",
31 32
				"agree": false,
				"captchaBase64":"",
33
				"captcha":""
芊里 已提交
34 35 36 37
			}
		},
		computed: {
			canLogin() {
38 39 40 41 42 43 44
				return this.username.length && this.isPwd;
			},
			isPwd() {
				return /^.{6,20}$/.test(this.password);
			},
			isPhone() {
				return /^1\d{10}$/.test(this.phone);
DCloud_JSON's avatar
DCloud_JSON 已提交
45
			},
芊里 已提交
46 47
		},
		methods: {
DCloud_JSON's avatar
DCloud_JSON 已提交
48
			// 页面跳转,找回密码
芊里 已提交
49 50
			toRetrievePwd() {
				uni.navigateTo({
51 52
					url: '../pwd-retrieve/pwd-retrieve?phoneNumber=' + (this.isPhone ? this.username : '') +
						'&phoneArea=' + this.currenPhoneArea
芊里 已提交
53 54 55 56 57 58
				})
			},
			/**
			 * 密码登录
			 */
			pwdLogin() {
59 60 61 62 63 64
				if (!this.agree) {
					return uni.showToast({
						title: '你未同意隐私政策协议',
						icon: 'none'
					});
				}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
				// 下边是可以登录
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'login',
						params:{
							"username": this.username,
							"password": this.password,
							"captcha":this.captcha
						},
					},
					success: ({result}) => {
						console.log(result);
						if (result.code === 0) {
							this.loginSuccess(result)
						} else {
							if (result.needCaptcha) {
								uni.showToast({
									title: result.msg,
									icon: 'none'
								});
								this.createCaptcha()
							}else{
								uni.showModal({
									title: '错误',
									content: result.msg,
									showCancel: false,
									confirmText: '知道了'
								});
							}
						}
					}
				})
98 99
			},
			createCaptcha(){
100 101 102 103 104 105 106 107 108 109 110
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'createCaptcha',
						params:{
							scene: "login"
						},
					},
					success: ({result}) => {
						if (result.code === 0) {
							this.captchaBase64 = result.captchaBase64
111 112 113 114 115
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
116 117
						}
					}
118
				})
119 120
			},
			/* 前往注册 */
121
			toRegister(e) {
122 123
				console.log(e);
				uni.navigateTo({
124
					url: '/pages/ucenter/login-page/register/register'
125
				})
126
			}
芊里 已提交
127 128 129 130 131
		}
	}
</script>

<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
132
	@import url("../common/login-page.css");
133 134 135

	.auth-box {
		flex-direction: row;
DCloud_JSON's avatar
DCloud_JSON 已提交
136
		justify-content: space-between;
137 138 139 140 141 142 143
		margin-top: 20px;
	}

	.auth-box .link {
		font-size: 26rpx;
	}

芊里 已提交
144 145
	.login-text-sub {
		color: #8a8f8b;
146
	}
147 148

	.toRegister {
149 150
		margin-top: 80px;
		width: 600rpx;
芊里 已提交
151
	}
152 153 154 155 156 157 158 159 160 161 162 163 164
	.captcha-box{
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}
	.captcha-img{
		margin:15px 15px 0 0;
		width: 250rpx;
	}
	.captcha{
		width: 350rpx;
	}
</style>