pwd-login.vue 5.0 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
				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
study夏羽's avatar
study夏羽 已提交
100 101 102
				}).catch((res)=>{
					console.log("res:-- ",res);
					return res
study夏羽's avatar
study夏羽 已提交
103
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
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 134 135 136
				// 下边是可以登录
				// 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
				// 				});
				// 			}
				// 		}
				// 	}
				// })
137 138
			},
			createCaptcha(){
DCloud_JSON's avatar
DCloud_JSON 已提交
139 140 141 142 143 144 145 146 147 148 149
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'createCaptcha',
						params:{
							scene: "login"
						},
					},
					success: ({result}) => {
						if (result.code === 0) {
							this.captchaBase64 = result.captchaBase64
150 151 152 153 154
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
DCloud_JSON's avatar
DCloud_JSON 已提交
155 156
						}
					}
157
				})
158 159
			},
			/* 前往注册 */
160
			toRegister(e) {
161 162
				console.log(e);
				uni.navigateTo({
163
					url: '/pages/ucenter/login-page/register/register'
164
				})
165
			}
芊里 已提交
166 167 168 169 170
		}
	}
</script>

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

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

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

芊里 已提交
183 184
	.login-text-sub {
		color: #8a8f8b;
185
	}
186 187

	.toRegister {
188 189
		margin-top: 80px;
		width: 600rpx;
芊里 已提交
190
	}
191 192 193 194 195 196
	.captcha-box{
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}
	.captcha-img{
197
		margin: 0 15px 10px 0;
198 199 200 201 202 203
		width: 250rpx;
	}
	.captcha{
		width: 350rpx;
	}
</style>