pwd-login.vue 4.5 KB
Newer Older
芊里 已提交
1
<template>
芊里 已提交
2 3 4
	<view class="wrap">
		<view class="wrap-content">
			<view class="content">
芊里 已提交
5
				<!-- 顶部文字 -->
芊里 已提交
6
				<text class="content-top-title">手机号密码登录</text>
芊里 已提交
7
				<login-ikonw class="login-iknow" :link="link" text="登录即表示同意用户协议和隐私政策"></login-ikonw>
芊里 已提交
8 9 10
				<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
				<uni-forms ref="form" :value="formData" :rules="rules">
					<uni-forms-item name="phone">
L
123  
linju 已提交
11 12 13 14 15 16 17 18
						<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
							v-model="formData.phone" maxlength="11" placeholder="请输入手机号">
							<template slot="left">
								<!-- 当前仅支持中国大陆手机号 -->
								<!-- <picker mode="selector" :range="phoneArea" @change="selectPhoneArea"> -->
									<text class="phone-area" @click="selectPhoneArea">{{currenPhoneArea}}</text>
								<!-- </picker> -->
							</template>
芊里 已提交
19
						</uni-easyinput>
芊里 已提交
20
						<uni-easyinput type="password" class="phone-input-box" :inputBorder="false"
芊里 已提交
21 22 23 24 25
							v-model="formData.pwd" placeholder="请输入密码"></uni-easyinput>
					</uni-forms-item>
					<button class="send-btn-box" :disabled="!canLogin" :type="canLogin?'primary':'default'"
						@click="pwdLogin">登录</button>
				</uni-forms>
芊里 已提交
26 27

				<!-- 忘记密码 -->
芊里 已提交
28 29 30
				<view class="auth-box">
					<text class="login-text login-text-sub">忘记了?</text>
					<text class="login-text" @click="toRetrievePwd">找回密码</text>
芊里 已提交
31 32 33 34 35 36
				</view>
			</view>
		</view>
	</view>
</template>

L
123  
linju 已提交
37
<script>
芊里 已提交
38
	import mixin from '../../common/loginPage.mixin.js';
L
123  
linju 已提交
39
	export default {
芊里 已提交
40
		mixins:[mixin],
芊里 已提交
41 42
		data() {
			return {
L
123  
linju 已提交
43 44 45 46 47 48
				link: [{
					text: '用户协议',
					to: '/pages/ucenter/agree-list/service/service'
				}, {
					text: '隐私政策',
					to: '/pages/ucenter/agree-list/privacy/privacy'
芊里 已提交
49
				}],
芊里 已提交
50
				phoneArea: ['+86'],
L
123  
linju 已提交
51
				currenPhoneArea: '+86',
芊里 已提交
52 53 54 55 56 57
			}
		},
		computed: {
			canLogin() {
				let reg_phone = /^1\d{10}$/;
				let reg_pwd = /^.{6,20}$/;
芊里 已提交
58
				let isPhone = reg_phone.test(this.formData.phone);
芊里 已提交
59

芊里 已提交
60
				let isPwd = reg_pwd.test(this.formData.pwd);
芊里 已提交
61 62 63 64 65 66 67 68 69
				return isPhone && isPwd;
			}
		},
		methods: {
			/**
			 * 页面跳转,找回密码
			 */
			toRetrievePwd() {
				let reg_phone = /^1\d{10}$/;
芊里 已提交
70
				let isPhone = reg_phone.test(this.formData.phone);
芊里 已提交
71 72 73 74 75 76
				if (!isPhone) return uni.showToast({
					title: '请输入正确的手机号',
					icon: 'none'
				});

				uni.navigateTo({
芊里 已提交
77
					url: './pwd-retrieve?phoneNumber=' + this.formData.phone + '&phoneArea=' + this.currenPhoneArea
芊里 已提交
78 79 80 81 82 83 84
				})
			},
			/**
			 * 密码登录
			 */
			pwdLogin() {
				if (!this.canLogin) return;
L
123  
linju 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
				// 下边是可以登录
				uniCloud.callFunction({
					name:"user-center",
					"data":{
						"action":"login",
						"params":{
							"username":this.formData.phone,
							"password":this.formData.pwd
						}
					},
					success:async (e) => {
						uni.hideLoading()
						console.log(e.result);
						if(e.result.code === 0){
							uni.setStorageSync('uni_id_uid', e.result.uid)
							uni.setStorageSync('uni_id_token', e.result.token)
							uni.setStorageSync('uni_id_token_expired', e.result.tokenExpired)
							// console.log('66666=',e.result.uid,e.result.token,e.result.tokenExpired);
							delete e.result.userInfo.token
							this.setUserInfo(e.result.userInfo)
							uni.showToast({
								title: '登陆成功',
								icon: 'none'
							});
L
123  
linju 已提交
109 110 111
							uni.switchTab({
								url:"/pages/list/list"
							})
L
123  
linju 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
						}else{
							uni.showModal({
								title: '错误',
								content: e.result.msg,
								showCancel: false,
								confirmText: '知道了',
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showModal({
							title: '错误',
							content: JSON.stringify(err),
							showCancel: false,
							confirmText: '知道了',
						});
						if(err.errCode===30002){
							
						}
					},
					complete: () => {
						uni.hideLoading()
					}
L
123  
linju 已提交
136
				})
芊里 已提交
137
			},
L
123  
linju 已提交
138 139 140 141
			selectPhoneArea(event) {
				uni.showToast({
					title: '当前仅支持中国大陆手机号',
					icon: 'none'
芊里 已提交
142 143
				});
				// this.currenPhoneArea = this.phoneArea[event.detail.value];
芊里 已提交
144 145 146 147 148 149
			},
		}
	}
</script>

<style>
芊里 已提交
150 151 152 153 154 155 156
	@import url("../../common/loginPage.css");

	.phone-input-box {
		margin-top: 20rpx;
	}

	.auth-box {
L
123  
linju 已提交
157
		justify-content: flex-start;
芊里 已提交
158 159 160 161 162
		margin-top: 20rpx;
	}

	.login-text-sub {
		color: #8a8f8b;
芊里 已提交
163
	}
L
123  
linju 已提交
164
</style>