chenxiong 3 éve
szülő
commit
93238e0ebb
3 módosított fájl, 328 hozzáadás és 165 törlés
  1. 138 75
      pages/login/login.vue
  2. 78 23
      pages2/register/forget.vue
  3. 112 67
      pages2/register/register.vue

+ 138 - 75
pages/login/login.vue

@@ -7,14 +7,14 @@
 				<u-subsection @change="sectionChange" :list="list" :current="current" active-color="#007AFF" inactive-color="#ffffff" bg-color="rgba(255,255,255,0.52)"></u-subsection>
 			</view>
 			<view class="login_box">
-				<u-form :model="form" ref="uForm" v-if="current==0">
-					<u-form-item ><u-input type="idcard" v-model="form.account" placeholder="手机号/学员身份证"/></u-form-item>
-					<u-form-item ><u-input v-model="form.pwd" type="password" placeholder="登录密码"/></u-form-item>
+				<u-form :model="form" ref="uForm1" v-show="current==0">
+					<u-form-item prop="account" ><u-input type="idcard" v-model="form.account" placeholder-style="color:#999999" placeholder="手机号/学员身份证"/></u-form-item>
+					<u-form-item prop="pwd" ><u-input class="password" v-model="form.pwd" placeholder-style="color:#999999" type="password" placeholder="登录密码"/></u-form-item>
 				</u-form>
-				<u-form :model="form" ref="uForm" v-if="current==1">
-					<u-form-item ><u-input type="number" maxlength="11"  v-model="form.tel" placeholder="手机号"/></u-form-item>
-					<u-form-item >
-						<u-input v-model="form.code" type="number"  placeholder="验证码"/>
+				<u-form :model="form" ref="uForm2" v-show="current==1">
+					<u-form-item  prop="tel" ref="tel"><u-input type="number" maxlength="11" placeholder-style="color:#999999"  v-model="form.tel" placeholder="手机号"/></u-form-item>
+					<u-form-item prop="code" >
+						<u-input v-model="form.code" type="number" placeholder-style="color:#999999"  placeholder="验证码"/>
 						<u-button slot="right"  size="mini" @click="getCode">{{codeTips}}</u-button>
 					</u-form-item>
 				</u-form>
@@ -61,6 +61,50 @@ export default {
 					name: '短信登录'
 				}
 			],
+			rules: {
+				tel: [
+					{ 
+						required: true, 
+						message: '请输入手机号', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					},
+					{
+						validator: (rule, value, callback) => {
+							// 上面有说,返回true表示校验通过,返回false表示不通过
+							// this.$u.test.mobile()就是返回true或者false的
+							return this.$u.test.mobile(value);
+						},
+						message: '手机号码格式不正确',
+						// 触发器可以同时用blur和change
+						trigger: ['change','blur'],
+					}
+				],
+				account: [
+					{ 
+						required: true, 
+						message: '请输入手机号/学员身份证', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+				pwd: [
+					{ 
+						required: true, 
+						message: '请输入密码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+				code: [
+					{ 
+						required: true, 
+						message: '请输入验证码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+			},
 			current: 0,
 			codeTips: '',
 			isUse:false,
@@ -68,6 +112,8 @@ export default {
 		};
 	},
 	onLoad(option) {
+		this.$refs.uForm1.setRules(this.rules)
+		this.$refs.uForm2.setRules(this.rules)
 		if(option.isBack){
 			this.isBack = option.isBack;
 		}
@@ -96,57 +142,62 @@ export default {
 			}
 		},
 		sms_login(){
-			let that = this
-			if(!this.form.tel){
-				this.$u.toast('请输入手机号码');
-				return 
-			}
-			if(!this.form.code){
-				this.$u.toast('请输入验证码');
-				return 
-			}
-			that.isUse = true
-			let datas = {
-				tel:this.form.tel,
-				code:this.form.code
-			}
-			that.$api.smsLogin(datas).then(
-				res => {
-					that.isUse = false
-					if (res.data.code == 200) {
-						if(res.data.data.full_info){
-							//信息完善,直接进入页面
-							uni.setStorageSync('user_account', res.data.data.user_account);
-							uni.setStorageSync('token', res.data.data.token);
-							that.$api.getInfo().then(resdata => {
-								if(resdata.data.code == 200){
-									that.$store.state.userInfo = resdata.data.data;
-									
-									if(!that.isBack){
-										uni.reLaunch({
-											url:'/pages/index/index'
-										})
-									}else{
-										uni.navigateBack();
-									}
-								}
-								
-							});
-							
-						}else{
-							//未完善信息,存为临时信息
-							uni.setStorageSync('user_account_temp', res.data.data.user_account);
-							uni.setStorageSync('token_temp', res.data.data.token);
-							that.$navTo.togo('/pages2/register/bind');
-						}	
-					} else {
-						that.$u.toast(res.data.msg);
+			this.$refs.uForm2.validate(valid => {
+				if(valid) {
+					let that = this
+					if(!this.form.tel){
+						this.$u.toast('请输入手机号码');
+						return 
 					}
-				},
-				err => {
-					that.isUse = false
+					if(!this.form.code){
+						this.$u.toast('请输入验证码');
+						return 
+					}
+					that.isUse = true
+					let datas = {
+						tel:this.form.tel,
+						code:this.form.code
+					}
+					that.$api.smsLogin(datas).then(
+						res => {
+							that.isUse = false
+							if (res.data.code == 200) {
+								if(res.data.data.full_info){
+									//信息完善,直接进入页面
+									uni.setStorageSync('user_account', res.data.data.user_account);
+									uni.setStorageSync('token', res.data.data.token);
+									that.$api.getInfo().then(resdata => {
+										if(resdata.data.code == 200){
+											that.$store.state.userInfo = resdata.data.data;
+											
+											if(!that.isBack){
+												uni.reLaunch({
+													url:'/pages/index/index'
+												})
+											}else{
+												uni.navigateBack();
+											}
+										}
+										
+									});
+									
+								}else{
+									//未完善信息,存为临时信息
+									uni.setStorageSync('user_account_temp', res.data.data.user_account);
+									uni.setStorageSync('token_temp', res.data.data.token);
+									that.$navTo.togo('/pages2/register/bind');
+								}	
+							} else {
+								that.$u.toast(res.data.msg);
+							}
+						},
+						err => {
+							that.isUse = false
+						}
+					);
 				}
-			);
+			})
+			
 		},
 		fakeLogin(){
 			uni.setStorageSync('user_account', '123');
@@ -211,26 +262,28 @@ export default {
 		// 获取验证码
 		getCode() {
 			let that = this
-			if(that.$refs.uCode.canGetCode) {
-				if(!this.form.tel){
-					this.$u.toast('请输入手机号码');
-					return 
-				}
-				let datas = {tel:this.form.tel}
-				that.$api.loginSms(datas).then(
-					res => {
-						if (res.data.code == 200) {
-							that.$u.toast('验证码已发送');
-							// 通知验证码组件内部开始倒计时
-							that.$refs.uCode.start();
-						} else {
-							that.$u.toast(res.data.msg);
+			if(that.$refs.uCode.canGetCode) { 
+				if(that.$refs.tel.validateState == 'success') {
+					let datas = {tel:this.form.tel}
+					that.$api.loginSms(datas).then(
+						res => {
+							if (res.data.code == 200) {
+								that.$u.toast('验证码已发送');
+								// 通知验证码组件内部开始倒计时
+								that.$refs.uCode.start();
+							} else {
+								that.$u.toast(res.data.msg);
+							}
+						},
+						err => {
+							console.log(err);
 						}
-					},
-					err => {
-						console.log(err);
-					}
-			);}
+					);
+				} else {
+					this.$refs.tel.onFieldBlur()
+				}
+			}
+			
 		},
 		sectionChange(index) {
 			this.current = index;
@@ -347,6 +400,16 @@ export default {
 		border-radius: 24rpx;
 		margin-top: 30rpx;
 		padding:40rpx 35rpx;
+		
+		
+		.password {
+			/deep/.uicon-eye-fill {
+				&::before{
+					color:#007AFF;
+					content:"\e613";
+				}
+			}
+		}
 	}
 	/deep/ .u-item-bg{
 		border-radius: 32px !important;

+ 78 - 23
pages2/register/forget.vue

@@ -5,13 +5,13 @@
 		<view style="padding: 30rpx;">
 			<view class="login_box">
 				<u-form :model="form" ref="uForm" >
-					<u-form-item ><u-input  v-model="form.tel" type="number" maxlength="11" placeholder="手机号"/></u-form-item>
-					<u-form-item >
-						<u-input v-model="form.code" type="number"  placeholder="验证码"/>
+					<u-form-item prop="tel" ref="tel"><u-input  v-model="form.tel" type="number" maxlength="11" placeholder-style="color:#999999" placeholder="手机号"/></u-form-item>
+					<u-form-item prop="code">
+						<u-input v-model="form.code" type="number" placeholder-style="color:#999999"  placeholder="验证码"/>
 						<u-button slot="right"  size="mini" @click="getCode">{{codeTips}}</u-button>
 					</u-form-item>
-					<u-form-item ><u-input v-model="form.pwd" type="password" placeholder="请输入新密码"/></u-form-item>
-					<u-form-item ><u-input v-model="form.pwdAgain" type="password" placeholder="再次输入新密码"/></u-form-item>
+					<u-form-item prop="pwd"><u-input class="password" placeholder-style="color:#999999" v-model="form.pwd" type="password" placeholder="请输入新密码"/></u-form-item>
+					<u-form-item prop="pwdAgain"><u-input class="password" placeholder-style="color:#999999" v-model="form.pwdAgain" type="password" placeholder="再次输入新密码"/></u-form-item>
 				</u-form>
 			</view>
 			
@@ -35,6 +35,50 @@ export default {
 				pwd:'',
 				pwdAgain:''
 			},
+			rules: {
+				tel: [
+					{ 
+						required: true, 
+						message: '请输入手机号', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					},
+					{
+						validator: (rule, value, callback) => {
+							// 上面有说,返回true表示校验通过,返回false表示不通过
+							// this.$u.test.mobile()就是返回true或者false的
+							return this.$u.test.mobile(value);
+						},
+						message: '手机号码格式不正确',
+						// 触发器可以同时用blur和change
+						trigger: ['change','blur'],
+					}
+				],
+				pwd: [
+					{ 
+						required: true, 
+						message: '请输入密码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+				pwdAgain: [
+					{ 
+						required: true, 
+						message: '请输入密码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+				code: [
+					{ 
+						required: true, 
+						message: '请输入验证码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+			},
 			codeTips: '',
 			read:'',
 			isUse:false
@@ -108,25 +152,26 @@ export default {
 		getCode() {
 			let that = this
 			if(that.$refs.uCode.canGetCode) {
-				if(!this.form.tel){
-					this.$u.toast('请输入手机号码');
-					return 
+				if(that.$refs.tel.validateState == 'success') {
+					let datas = {tel:this.form.tel}
+					that.$api.forgetSms(datas).then(
+						res => {
+							if (res.data.code == 200) {
+								that.$u.toast('验证码已发送');
+								// 通知验证码组件内部开始倒计时
+								that.$refs.uCode.start();
+							} else {
+								that.$u.toast(res.data.msg);
+							}
+						},
+						err => {
+							console.log(err);
+						});
+				} else {
+					this.$refs.tel.onFieldBlur()
 				}
-				let datas = {tel:this.form.tel}
-				that.$api.forgetSms(datas).then(
-					res => {
-						if (res.data.code == 200) {
-							that.$u.toast('验证码已发送');
-							// 通知验证码组件内部开始倒计时
-							that.$refs.uCode.start();
-						} else {
-							that.$u.toast(res.data.msg);
-						}
-					},
-					err => {
-						console.log(err);
-					}
-			);}
+			}
+				
 		},
 		sectionChange(index) {
 			this.current = index;
@@ -191,6 +236,7 @@ export default {
 		}
 	},
 	onLoad(option) {
+		this.$refs.uForm.setRules(this.rules)
 		let that = this;
 		this.from = option.from;
 		uni.login({
@@ -252,6 +298,15 @@ export default {
 		border-radius: 24rpx;
 		margin-top: 30rpx;
 		padding:40rpx 35rpx;
+		
+		.password {
+			/deep/.uicon-eye-fill {
+				&::before{
+					color:#007AFF;
+					content:"\e613";
+				}
+			}
+		}
 	}
 	/deep/ .u-item-bg{
 		border-radius: 32px !important;

+ 112 - 67
pages2/register/register.vue

@@ -5,12 +5,12 @@
 		<view style="padding: 30rpx;">
 			<view class="login_box">
 				<u-form :model="form" ref="uForm" >
-					<u-form-item ><u-input  v-model="form.tel" type="number" maxlength="11" placeholder="手机号"/></u-form-item>
-					<u-form-item >
-						<u-input v-model="form.code"  type="number" placeholder="验证码"/>
+					<u-form-item prop="tel" ref="tel"><u-input  v-model="form.tel" type="number" maxlength="11" placeholder-style="color:#999999" placeholder="手机号"/></u-form-item>
+					<u-form-item prop="code">
+						<u-input v-model="form.code"  type="number" placeholder-style="color:#999999" placeholder="验证码"/>
 						<u-button slot="right"  size="mini" @click="getCode">{{codeTips}}</u-button>
 					</u-form-item>
-					<u-form-item ><u-input v-model="form.pwd" type="password" placeholder="请输入登录密码"/></u-form-item>
+					<u-form-item prop="pwd"><u-input v-model="form.pwd" type="password" placeholder-style="color:#999999" placeholder="请输入登录密码"/></u-form-item>
 				</u-form>
 			</view>
 			<view style="margin: 30rpx 0;">
@@ -23,9 +23,7 @@
 			<button :disabled="isUse" class="loginBtn" :class="{able:canRegister()}" @click="submit">
 				确定
 			</button>
-			
-			
-			
+		
 		</view>
 		<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
 	</view>
@@ -42,6 +40,42 @@ export default {
 			},
 			codeTips: '',
 			read:false,
+			rules: {
+				tel: [
+					{ 
+						required: true, 
+						message: '请输入手机号', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					},
+					{
+						validator: (rule, value, callback) => {
+							// 上面有说,返回true表示校验通过,返回false表示不通过
+							// this.$u.test.mobile()就是返回true或者false的
+							return this.$u.test.mobile(value);
+						},
+						message: '手机号码格式不正确',
+						// 触发器可以同时用blur和change
+						trigger: ['change','blur'],
+					}
+				],
+				pwd: [
+					{ 
+						required: true, 
+						message: '请输入密码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+				code: [
+					{ 
+						required: true, 
+						message: '请输入验证码', 
+						// 可以单个或者同时写两个触发验证方式 
+						trigger: ['change','blur'],
+					}
+				],
+			},
 			isUse:false
 		};
 	},
@@ -55,49 +89,58 @@ export default {
 		},
 		submit(){
 			let that = this
-			if(!this.form.tel){
-				this.$u.toast('请输入手机号码');
-				return 
-			}
-			if(!this.form.code){
-				this.$u.toast('请输入验证码');
-				return 
-			}
-			if(!this.form.pwd){
-				this.$u.toast('请输入注册密码');
-				return 
-			}
-			if(!this.read){
-				this.$u.toast('请勾选服务协议');
-				return 
-			}
-			that.isUse = true
-			let datas = {
-				tel:this.form.tel,
-				code:this.form.code,
-				pwd:this.form.pwd
-				}
-			that.$api.registerUser(datas).then(
-				res => {
-					that.isUse = false
-					if (res.data.code == 200) {
-						uni.showModal({
-							title: '提示',
-							content: '注册成功',
-							showCancel:false,
-							success: function(resst) {
-								uni.navigateBack()
-							}
-						});
-					} else {
-						that.$u.toast(res.data.msg);
+			// if(!this.form.tel){
+			// 	this.$u.toast('请输入手机号码');
+			// 	return 
+			// }
+			// if(!this.form.code){
+			// 	this.$u.toast('请输入验证码');
+			// 	return 
+			// }
+			// if(!this.form.pwd){
+			// 	this.$u.toast('请输入注册密码');
+			// 	return 
+			// }
+			// if(!this.read){
+			// 	this.$u.toast('请勾选服务协议');
+			// 	return 
+			// }
+			this.$refs.uForm.validate(valid => {
+				if(valid) {
+					if(!this.read){
+						this.$u.toast('请勾选服务协议');
+						return 
 					}
-				},
-				err => {
-					that.isUse = false
-					console.log(err);
+					that.isUse = true
+					let datas = {
+						tel:this.form.tel,
+						code:this.form.code,
+						pwd:this.form.pwd
+						}
+					that.$api.registerUser(datas).then(
+						res => {
+							that.isUse = false
+							if (res.data.code == 200) {
+								uni.showModal({
+									title: '提示',
+									content: '注册成功',
+									showCancel:false,
+									success: function(resst) {
+										uni.navigateBack()
+									}
+								});
+							} else {
+								that.$u.toast(res.data.msg);
+							}
+						},
+						err => {
+							that.isUse = false
+							console.log(err);
+						}
+					);
 				}
-			);
+			})
+			
 		},
 		radioGroupChange(e) {
 			 console.log(e);
@@ -109,25 +152,26 @@ export default {
 		getCode() {
 			let that = this
 			if(that.$refs.uCode.canGetCode) {
-				if(!this.form.tel){
-					this.$u.toast('请输入手机号码');
-					return 
-				}
-				let datas = {tel:this.form.tel}
-				that.$api.registerSms(datas).then(
-					res => {
-						if (res.data.code == 200) {
-							that.$u.toast('验证码已发送');
-							// 通知验证码组件内部开始倒计时
-							that.$refs.uCode.start();
-						} else {
-							that.$u.toast(res.data.msg);
+				if(that.$refs.tel.validateState == 'success') {
+					let datas = {tel:this.form.tel}
+					that.$api.registerSms(datas).then(
+						res => {
+							if (res.data.code == 200) {
+								that.$u.toast('验证码已发送');
+								// 通知验证码组件内部开始倒计时
+								that.$refs.uCode.start();
+							} else {
+								that.$u.toast(res.data.msg);
+							}
+						},
+						err => {
+							console.log(err);
 						}
-					},
-					err => {
-						console.log(err);
-					}
-			);}
+					);	
+				} else {
+					this.$refs.tel.onFieldBlur()
+				}
+			}
 
 		},
 		sectionChange(index) {
@@ -194,6 +238,7 @@ export default {
 	},
 	onLoad(option) {
 		let that = this;
+		this.$refs.uForm.setRules(this.rules)
 		this.from = option.from;
 		uni.login({
 			provider: 'weixin',
@@ -248,7 +293,7 @@ export default {
 	}
 	.login_box{
 		width: 100%;
-		height: 463rpx;
+		height: 500rpx;
 		background: #FFFFFF;
 		box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
 		border-radius: 24rpx;