pwd-login.vue 4.1 KB
Newer Older
芊里 已提交
1
<template>
芊里 已提交
2 3 4
	<view class="wrap">
		<view class="wrap-content">
			<view class="content">
芊里 已提交
5
				<!-- 顶部文字 -->
L
23  
linju 已提交
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
						<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
L
23  
linju 已提交
12
							v-model="formData.phone" maxlength="11" placeholder="请输入手机号/用户名/邮箱">
L
123  
linju 已提交
13 14 15 16 17 18
							<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
				</view>
			</view>
L
23  
linju 已提交
33 34
		</view>
		<uni-quick-login ref="uniQuickLogin"></uni-quick-login>
芊里 已提交
35 36 37
	</view>
</template>

L
123  
linju 已提交
38
<script>
芊里 已提交
39
	import mixin from '../../common/loginPage.mixin.js';
L
123  
linju 已提交
40
	export default {
芊里 已提交
41
		mixins:[mixin],
芊里 已提交
42 43
		data() {
			return {
芊里 已提交
44
				phoneArea: ['+86'],
L
123  
linju 已提交
45
				currenPhoneArea: '+86',
芊里 已提交
46 47 48 49
			}
		},
		computed: {
			canLogin() {
50
				return this.isPhone && this.isPwd;
芊里 已提交
51 52 53 54 55 56 57
			}
		},
		methods: {
			/**
			 * 页面跳转,找回密码
			 */
			toRetrievePwd() {
58
				if (!this.isPhone) return uni.showToast({
芊里 已提交
59 60 61 62
					title: '请输入正确的手机号',
					icon: 'none'
				});
				uni.navigateTo({
L
23  
linju 已提交
63
					url: '../pwd-retrieve/pwd-retrieve?phoneNumber=' + this.formData.phone + '&phoneArea=' + this.currenPhoneArea
芊里 已提交
64 65 66 67 68 69
				})
			},
			/**
			 * 密码登录
			 */
			pwdLogin() {
L
123  
linju 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
				// 下边是可以登录
				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 已提交
94 95 96
							uni.switchTab({
								url:"/pages/list/list"
							})
L
123  
linju 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
						}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 已提交
121
				})
芊里 已提交
122
			},
L
123  
linju 已提交
123 124 125 126
			selectPhoneArea(event) {
				uni.showToast({
					title: '当前仅支持中国大陆手机号',
					icon: 'none'
芊里 已提交
127 128
				});
				// this.currenPhoneArea = this.phoneArea[event.detail.value];
芊里 已提交
129 130 131 132 133 134
			},
		}
	}
</script>

<style>
芊里 已提交
135 136 137 138 139
	@import url("../../common/loginPage.css");
	.phone-input-box {
		margin-top: 20rpx;
	}
	.auth-box {
L
123  
linju 已提交
140
		justify-content: flex-start;
芊里 已提交
141 142 143 144
		margin-top: 20rpx;
	}
	.login-text-sub {
		color: #8a8f8b;
芊里 已提交
145
	}
L
123  
linju 已提交
146
</style>