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

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

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

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

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

芊里 已提交
159 160
	.login-text-sub {
		color: #8a8f8b;
161
	}
162 163

	.toRegister {
164 165
		margin-top: 80px;
		width: 600rpx;
study夏羽's avatar
update  
study夏羽 已提交
166 167 168
	}
	.agreement{
		margin-top: 10px;
169 170
	}
</style>