pwd-login.vue 4.4 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 9 10 11 12
		<!-- <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="$t('pwdLogin.verifyCodePlaceholder')"/>
		</view> -->
		<uni-captcha scene="login" v-model="captcha"></uni-captcha>
		<uni-agreements @setAgree="agree = $event"></uni-agreements>
13
		<button class="send-btn" :disabled="!canLogin" :type="canLogin?'primary':'default'"
14
			@click="pwdLogin">{{$t('pwdLogin.login')}}</button>
15 16
		<!-- 忘记密码 -->
		<view class="auth-box">
17 18
			<text class="link" @click="toRetrievePwd">{{$t('pwdLogin.forgetPassword')}}</text>
			<text class="link" @click="toRegister">{{$t('pwdLogin.register')}}</text>
19 20
		</view>
		<uni-quick-login :agree="agree" ref="uniQuickLogin"></uni-quick-login>
芊里 已提交
21 22 23
	</view>
</template>

L
123  
linju 已提交
24
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
25
	import mixin from '../common/login-page.mixin.js';
L
123  
linju 已提交
26
	export default {
27
		mixins: [mixin],
芊里 已提交
28
		data() {
29 30 31
			return {
				"password": "",
				"username": "",
32 33
				"agree": false,
				"captcha":false
芊里 已提交
34 35 36 37
			}
		},
		computed: {
			canLogin() {
study夏羽's avatar
update  
study夏羽 已提交
38
				return this.username.length && this.isPwd && this.agree;
39 40 41 42 43 44
			},
			isPwd() {
				return /^.{6,20}$/.test(this.password);
			},
			isPhone() {
				return /^1\d{10}$/.test(this.phone);
DCloud_JSON's avatar
DCloud_JSON 已提交
45
			},
芊里 已提交
46
		},
study夏羽's avatar
study夏羽 已提交
47 48 49
		onLoad() {
			console.log("uni.getLocale(): ",uni.getLocale());
		},
芊里 已提交
50
		methods: {
DCloud_JSON's avatar
DCloud_JSON 已提交
51
			// 页面跳转,找回密码
芊里 已提交
52 53
			toRetrievePwd() {
				uni.navigateTo({
54 55
					url: '../pwd-retrieve/pwd-retrieve?phoneNumber=' + (this.isPhone ? this.username : '') +
						'&phoneArea=' + this.currenPhoneArea
芊里 已提交
56 57 58 59 60
				})
			},
			/**
			 * 密码登录
			 */
study夏羽's avatar
study夏羽 已提交
61
			async pwdLogin() {
62 63
				if (!this.agree) {
					return uni.showToast({
study夏羽's avatar
update  
study夏羽 已提交
64
						title: this.$t('common.noAgree'),
65 66 67
						icon: 'none'
					});
				}
study夏羽's avatar
study夏羽 已提交
68
				return await uniCloud.callFunction({
study夏羽's avatar
study夏羽 已提交
69
					name:'uni-id-cf',
study夏羽's avatar
study夏羽 已提交
70 71 72 73 74 75 76 77
					data:{
						action:'login',
						params:{
							"username": this.username,
							"password": this.password,
							"captcha":this.captcha
						},
					},
study夏羽's avatar
update  
study夏羽 已提交
78
				}).then(({result})=>{
study夏羽's avatar
study夏羽 已提交
79
					console.log("result:--------- ",result);
study夏羽's avatar
study夏羽 已提交
80 81 82 83 84
					if (result.code === 0) {
						this.loginSuccess(result)
					} else {
						if (result.needCaptcha) {
							uni.showToast({
study夏羽's avatar
update  
study夏羽 已提交
85
								title: result.msg||'完成',
study夏羽's avatar
study夏羽 已提交
86 87
								icon: 'none'
							});
study夏羽's avatar
update  
study夏羽 已提交
88 89
							this.needCaptcha = true
							// this.createCaptcha()
study夏羽's avatar
study夏羽 已提交
90 91
						}else{
							uni.showModal({
study夏羽's avatar
update  
study夏羽 已提交
92
								title: this.$t('common.error'),
study夏羽's avatar
study夏羽 已提交
93 94
								content: result.msg,
								showCancel: false,
study夏羽's avatar
update  
study夏羽 已提交
95
								confirmText: this.$t('common.gotIt')
study夏羽's avatar
study夏羽 已提交
96 97 98 99
							});
						}
					}
					return result
study夏羽's avatar
study夏羽 已提交
100 101 102
				}).catch((res)=>{
					console.log("res:-- ",res);
					return res
study夏羽's avatar
study夏羽 已提交
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 134 135 136 137
				// 下边是可以登录
				/* 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.needCaptcha = true
								// this.createCaptcha()
							}else{
								uni.showModal({
									title: this.$t('common.error'),
									content: result.msg,
									showCancel: false,
									confirmText: this.$t('common.gotIt')
								});
							}
						}
					}
				})
138 139
			},
			/* 前往注册 */
study夏羽's avatar
update  
study夏羽 已提交
140
			toRegister() {
141
				uni.navigateTo({
142
					url: '/pages/ucenter/login-page/register/register'
143
				})
144
			}
芊里 已提交
145 146 147 148
		}
	}
</script>

study夏羽's avatar
update  
study夏羽 已提交
149
<style lang="scss" scoped>
DCloud_JSON's avatar
DCloud_JSON 已提交
150
	@import url("../common/login-page.css");
151 152 153

	.auth-box {
		flex-direction: row;
DCloud_JSON's avatar
DCloud_JSON 已提交
154
		justify-content: space-between;
155 156 157 158 159 160 161
		margin-top: 20px;
	}

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

芊里 已提交
162 163
	.login-text-sub {
		color: #8a8f8b;
164
	}
165 166

	.toRegister {
167 168
		margin-top: 80px;
		width: 600rpx;
169 170 171
	}
	.agreement{
		margin-top: 10px;
172 173
	}
</style>