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

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

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

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

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

	.toRegister {
163 164
		margin-top: 80px;
		width: 600rpx;
165 166 167
	}
	.agreement{
		margin-top: 10px;
168 169
	}
</style>