pwd-login.vue 3.5 KB
Newer Older
1 2 3 4 5
<template>
	<view class="content">
		<!-- 顶部文字 -->
		<text class="title">用户名密码登录</text>
		<uni-agreements @setAgree="agree = $event"></uni-agreements>
6
		<input class="input-box" :inputBorder="false" v-model="username" placeholder="请输入手机号/用户名"></input>
7 8 9 10
		<input type="password" class="input-box" :inputBorder="false" v-model="password" placeholder="请输入密码"></input>
		<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>
DCloud_JSON's avatar
DCloud_JSON 已提交
11
		</view>
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 31 32 33
			return {
				"password": "",
				"username": "",
				"agree": false,
				"captchaBase64":"",
				"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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
				if (!this.agree) {
					return uni.showToast({
						title: '你未同意隐私政策协议',
						icon: 'none'
					});
				}
				// 下边是可以登录
				this.request('user-center/login', {
					"username": this.username,
					"password": this.password,
					"captcha":this.captcha
				}, result => {
					console.log(result);
					if (result.code === 0) {
						this.loginSuccess(result)
					} else {
						if (result.needCaptcha) {
							uni.showToast({
								title: result.msg,
								icon: 'none'
							});
							this.createCaptcha()
DCloud_JSON's avatar
DCloud_JSON 已提交
81 82 83 84 85 86 87
						}else{
							uni.showModal({
								title: '错误',
								content: result.msg,
								showCancel: false,
								confirmText: '知道了'
							});
88 89 90 91 92 93 94 95 96 97 98 99
						}
					}
				})
			},
			createCaptcha(){
				this.request(
				'user-center/createCaptcha', {
					scene: "login"
				},
				result => {
					if (result.code === 0) {
						this.captchaBase64 = result.captchaBase64
DCloud_JSON's avatar
DCloud_JSON 已提交
100
					}
101
				})
102 103
			},
			/* 前往注册 */
104
			toRegister(e) {
105 106
				console.log(e);
				uni.navigateTo({
107
					url: '/pages/ucenter/login-page/register/register'
108
				})
109
			}
芊里 已提交
110 111 112 113 114
		}
	}
</script>

<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
115
	@import url("../common/login-page.css");
116 117 118

	.auth-box {
		flex-direction: row;
DCloud_JSON's avatar
DCloud_JSON 已提交
119
		justify-content: space-between;
120 121 122 123 124 125 126
		margin-top: 20px;
	}

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

芊里 已提交
127 128
	.login-text-sub {
		color: #8a8f8b;
129
	}
130 131

	.toRegister {
132 133
		margin-top: 80px;
		width: 600rpx;
134 135 136 137 138 139 140 141 142 143 144 145
	}
	.captcha-box{
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}
	.captcha-img{
		margin:15px 15px 0 0;
		width: 250rpx;
	}
	.captcha{
		width: 350rpx;
芊里 已提交
146
	}
147
</style>