pwd-login.vue 5.0 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 20 21 22 23 24 25
						</uni-easyinput>
						<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
							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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
				currenPhoneArea: '+86',
				
				formData: {
					phone: '17769516081',
					pwd:'123456'
				},
				rules: {
					phone: {
						rules: [{
								required: true,
								errorMessage: '请输入手机号',
							},
							{
								pattern: /^1\d{10}$/,
								errorMessage: '手机号格式不正确',
							}
						]
					},
					pwd:{
						rules: [{
								required: true,
								errorMessage: '请输入密码',
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: '密码应为6到20位',
							}
						]
					}
芊里 已提交
80
				}
芊里 已提交
81 82 83 84 85 86
			}
		},
		computed: {
			canLogin() {
				let reg_phone = /^1\d{10}$/;
				let reg_pwd = /^.{6,20}$/;
芊里 已提交
87
				let isPhone = reg_phone.test(this.formData.phone);
芊里 已提交
88

芊里 已提交
89
				let isPwd = reg_pwd.test(this.formData.pwd);
芊里 已提交
90 91 92 93 94 95 96 97 98
				return isPhone && isPwd;
			}
		},
		methods: {
			/**
			 * 页面跳转,找回密码
			 */
			toRetrievePwd() {
				let reg_phone = /^1\d{10}$/;
芊里 已提交
99
				let isPhone = reg_phone.test(this.formData.phone);
芊里 已提交
100 101 102 103 104 105
				if (!isPhone) return uni.showToast({
					title: '请输入正确的手机号',
					icon: 'none'
				});

				uni.navigateTo({
芊里 已提交
106
					url: './pwd-retrieve?phoneNumber=' + this.formData.phone + '&phoneArea=' + this.currenPhoneArea
芊里 已提交
107 108 109 110 111 112 113
				})
			},
			/**
			 * 密码登录
			 */
			pwdLogin() {
				if (!this.canLogin) return;
L
123  
linju 已提交
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:"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 已提交
138 139 140
							uni.switchTab({
								url:"/pages/list/list"
							})
L
123  
linju 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
						}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 已提交
165
				})
芊里 已提交
166
			},
L
123  
linju 已提交
167 168 169 170
			selectPhoneArea(event) {
				uni.showToast({
					title: '当前仅支持中国大陆手机号',
					icon: 'none'
芊里 已提交
171 172
				});
				// this.currenPhoneArea = this.phoneArea[event.detail.value];
芊里 已提交
173 174 175 176 177 178
			},
		}
	}
</script>

<style>
芊里 已提交
179 180 181 182 183 184 185
	@import url("../../common/loginPage.css");

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

	.auth-box {
L
123  
linju 已提交
186
		justify-content: flex-start;
芊里 已提交
187 188 189 190 191
		margin-top: 20rpx;
	}

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