login.vue 4.2 KB
<template>
	<!-- 登录页 -->
	<view class="login">
		<!-- 手机号登录 -->
		<view class="phoneLogin">
			<view class="phoneSize">
				<p class="BigSize">手机号登录</p>
				<view class="firstLogin">
					首次登录享受新人福利
				</view>
			</view>
			<u-field v-model="phone" label="手机号" placeholder="请填写手机号" :error-message="errorMessage" class="inpPhone"
				@input="isPhone">

			</u-field>
			<!-- <input class="inputPhone" v-model="phone" type="text" placeholder="请输入手机号"> -->

			<view class="btnCode" @click="gainCode">
				获取验证码
			</view>
			<!-- <view class="NobtnCode" v-if="">
				
			</view> -->
			<view class="agreement">
				<checkbox @click="consent=!consent" :checked="consent" />
				我已阅读并同意<span @click="navAgreement">《幸运星球用户协议》</span>及<span @click="navPolicy">《幸运星球隐私政策》</span>
			</view>
		</view>
		<!-- 提示框 -->
		<u-toast ref="uToast" :duration="10" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 手机号
				phone: "",
				// 手机号判断
				phoneTrue: false,
				// 错误提示
				errorMessage: '',
				// 协议
				consent: true,
				// 60秒内不能重新获取
				// noRepetition:true
			};
		},
		methods: {
			//手机号码判断
			isPhone(val) {
				if (val == "") {
					this.errorMessage = "此为必填项"
					this.phoneTrue = false
				} else {
					let re = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
					if (re.test(val)) {
						this.errorMessage = ""
						this.phoneTrue = true
					} else {
						this.errorMessage = "手机号码不正确"
						this.phoneTrue = false
					}
				}
			},		
			// 获取验证码
			async gainCode() {
				if (!this.phoneTrue) {
					this.$refs.uToast.show({
						title: '请填写手机号',
						type: 'error'
					})
				} else if (!this.consent) {
					this.$refs.uToast.show({
						title: '请勾选协议',
						type: 'error'
					})
				} else {
					// this.$Router.replace({
					// 	name: "codeLogin",
					// 	params: {
					// 		phone: this.phone,
					// 		redirect: this.$Route.query.redirect,
					// 	}
					// })
					try{
						await this.$store.dispatch("gainCode",this.phone)
						this.$Router.replace({
							name:"codeLogin",
							params:{
								phone:this.phone,
								redirect:this.$Route.query.redirect
							}
						})

					}catch(e){
						this.$refs.uToast.show({
							title: '不能重复获取',
							type: 'error'
						})
					}
				}
			},

			// 跳转用户协议
			navAgreement() {
				this.$Router.push("/pages/my/agreement/agreement")
			},
			// 跳转隐私政策
			navPolicy() {
				this.$Router.push("/pages/my/policy/policy")
			},
		}
	}
</script>

<style lang="scss">
	// 登录页
	* {
		margin: 0;
		padding: 0;
	}

	// 登录
	.login {
		width: 750rpx;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;

		// background-color: red;
		// 手机号登录
		.phoneLogin {
			width: 680rpx;
			height: 700rpx;
			margin-top: 150rpx;
			// background-color: red;
			display: flex;
			flex-direction: column;
			align-items: center;

			// 字体
			.phoneSize {
				width: 290rpx;
				height: 160rpx;
				margin-bottom: 60rpx;
				align-self: flex-start;

				.BigSize {
					font-size: 27px;
					font-weight: 550;
					margin-bottom: 15rpx;
				}

				.firstLogin {
					color: white;
					background-color: blue;
					border-radius: 10rpx;
					text-align: center;
					padding: 3rpx;
				}
			}

			// 手机号输入框
			.inpPhone {
				width: 650rpx !important;
				font-size: 15px !important;
			}

			// 验证码登录
			.btnCode {
				width: 650rpx;
				height: 80rpx;
				background: linear-gradient(129deg, #FFB193 15%, #F72934 100%);
				border-radius: 15rpx;
				margin: 50rpx 0;
				text-align: center;
				line-height: 80rpx;
				color: white;
				font-size: 16px;

			}

			// 用户协议
			.agreement {
				width: 500rpx;
				font-size: 12px;

				span {
					color: red;
				}
			}
		}
	}
</style>