pwd-login.vue 4.9 KB
Newer Older
1 2 3
<template>
	<view class="content">
		<!-- 顶部文字 -->
4 5 6
		<text class="title">{{$t('pwdLogin.pwdLogin')}}</text>
		<input class="input-box" :inputBorder="false" v-model="username" :placeholder="$t('pwdLogin.placeholder')"/>
		<input type="password" class="input-box" :inputBorder="false" v-model="password" :placeholder="$t('pwdLogin.passwordPlaceholder')"/>
7 8
		<view class="captcha-box" v-if="captchaBase64">
			<image class="captcha-img" @click="createCaptcha" :src="captchaBase64" mode="widthFix"></image>
9
			<input type="text" class="input-box captcha" :inputBorder="false" v-model="captcha" :placeholder="$t('pwdLogin.verifyCodePlaceholder')"/>
DCloud_JSON's avatar
DCloud_JSON 已提交
10
		</view>
11
		<uni-agreements @setAgree="agree = $event"></uni-agreements>
12
		<button class="send-btn" :disabled="!canLogin" :type="canLogin?'primary':'default'"
13
			@click="pwdLogin">{{$t('pwdLogin.login')}}</button>
14 15
		<!-- 忘记密码 -->
		<view class="auth-box">
16 17
			<text class="link" @click="toRetrievePwd">{{$t('pwdLogin.forgetPassword')}}</text>
			<text class="link" @click="toRegister">{{$t('pwdLogin.register')}}</text>
18 19
		</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
				})
study夏羽's avatar
study夏羽 已提交
54 55 56 57
				// uni.redirectTo({
				// 	url: '../pwd-retrieve/pwd-retrieve?phoneNumber=' + (this.isPhone ? this.username : '') +
				// 		'&phoneArea=' + this.currenPhoneArea
				// })
芊里 已提交
58 59 60 61
			},
			/**
			 * 密码登录
			 */
study夏羽's avatar
study夏羽 已提交
62
			async pwdLogin() {
63 64
				if (!this.agree) {
					return uni.showToast({
65
						title: this.$t('common').noAgree,
66 67 68
						icon: 'none'
					});
				}
study夏羽's avatar
study夏羽 已提交
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 98 99 100
				return await uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'login',
						params:{
							"username": this.username,
							"password": this.password,
							"captcha":this.captcha
						},
					},
				}).then(({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: this.$t('common').error,
								content: result.msg,
								showCancel: false,
								confirmText: this.$t('common').gotIt
							});
						}
					}
					return result
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
				// 下边是可以登录
				// 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: this.$t('common').error,
				// 					content: result.msg,
				// 					showCancel: false,
				// 					confirmText: this.$t('common').gotIt
				// 				});
				// 			}
				// 		}
				// 	}
				// })
134 135
			},
			createCaptcha(){
DCloud_JSON's avatar
DCloud_JSON 已提交
136 137 138 139 140 141 142 143 144 145 146
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'createCaptcha',
						params:{
							scene: "login"
						},
					},
					success: ({result}) => {
						if (result.code === 0) {
							this.captchaBase64 = result.captchaBase64
147 148 149 150 151
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
DCloud_JSON's avatar
DCloud_JSON 已提交
152 153
						}
					}
154
				})
155 156
			},
			/* 前往注册 */
157
			toRegister(e) {
158 159
				console.log(e);
				uni.navigateTo({
160
					url: '/pages/ucenter/login-page/register/register'
161
				})
162
			}
芊里 已提交
163 164 165 166 167
		}
	}
</script>

<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
168
	@import url("../common/login-page.css");
169 170 171

	.auth-box {
		flex-direction: row;
DCloud_JSON's avatar
DCloud_JSON 已提交
172
		justify-content: space-between;
173 174 175 176 177 178 179
		margin-top: 20px;
	}

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

芊里 已提交
180 181
	.login-text-sub {
		color: #8a8f8b;
182
	}
183 184

	.toRegister {
185 186
		margin-top: 80px;
		width: 600rpx;
芊里 已提交
187
	}
188 189 190 191 192 193 194 195 196 197 198 199 200
	.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>