Browse Source

添加登录密码汉字校验

achao 2 years ago
parent
commit
723a3f4e08
1 changed files with 50 additions and 24 deletions
  1. 50 24
      pages/public/login.vue

+ 50 - 24
pages/public/login.vue

@@ -9,15 +9,19 @@
 				class="flex">
 				<view class="phone-before-num NumberMedium">+86</view>
 				<view style='width:85%;'>
-					<input class='phone' maxlength='11' v-model='phone'  placeholder="请输入手机号码" type="number">
+					<input class='phone' maxlength='11' v-model='phone' placeholder="请输入手机号码" type="number">
 				</view>
 			</view>
 			<view style='margin-top:20px;border-bottom:1px solid #E8E9ED;position:relative;height:40px'>
 				<view style='position:relative;'>
-					<input class='password' v-model='password' v-if="isShowPassword=='password'" placeholder="请输入密码" type="password">
-					<input maxlength='16' class='password' v-model='password' v-else type="text" placeholder="请输入密码">
-						<image class='yanjingicon' style='width:22px;height:22px;' @click="passWordStatus(1)" v-if="isShowPassword=='password'" src="../../static/yioncang.png" mode=""></image>
-						<image class='yanjingicon' style='width:22px;height:22px;' @click="passWordStatus(2)" v-else src="../../static/xianshi.png" mode=""></image>
+					<input class='password' v-model='password' v-if="isShowPassword=='password'" placeholder="请输入密码"
+						type="password" @input="check">
+					<input maxlength='16' class='password' v-model='password' v-else type="text" placeholder="请输入密码"
+						@input="check">
+					<image class='yanjingicon' style='width:22px;height:22px;' @click="passWordStatus(1)"
+						v-if="isShowPassword=='password'" src="../../static/yioncang.png" mode=""></image>
+					<image class='yanjingicon' style='width:22px;height:22px;' @click="passWordStatus(2)" v-else
+						src="../../static/xianshi.png" mode=""></image>
 				</view>
 			</view>
 			<button :class='phone!=""&&password!=""?"active":""' @click='passlogin'
@@ -31,7 +35,7 @@
 		</view>
 		<u-toast ref="uToast"></u-toast>
 	</view>
-	
+
 	</view>
 </template>
 
@@ -117,6 +121,17 @@
 			// })
 		},
 		methods: {
+			check(val) {
+				console.log(val)
+				if (!uni.$u.test.enOrNum(val.detail.value)) {
+					this.$refs.uToast.show({
+						type: 'error',
+						message: "密码只能是字母或数字!"
+					})
+					this.password = ''
+					return
+				}
+			},
 			passWordStatus(type) {
 				if (type == 1) {
 					this.isShowPassword = 'text'
@@ -126,22 +141,28 @@
 			},
 			passlogin(e) {
 				var that = this
-				if(this.phone==''){
+				if (this.phone == '') {
 					that.$refs.uToast.show({
 						type: 'error',
 						message: "请输入手机号!"
 					})
 					return
 				}
-				if(this.password==''){
+				if (this.password == '') {
 					that.$refs.uToast.show({
 						type: 'error',
 						message: "请输入密码!"
 					})
 					return
 				}
-				
-				
+				if (!uni.$u.test.enOrNum(this.password)) {
+					that.$refs.uToast.show({
+						type: 'error',
+						message: "密码只能是字母或数字!"
+					})
+					return
+				}
+
 				that.$request.baseRequest('get', '/cargoOwnerInfo/firstAuthentication', {
 					phone: this.phone,
 				}).then(res => {
@@ -150,7 +171,7 @@
 							type: 'error',
 							message: "账号审核中!"
 						})
-						
+
 					} else {
 						uni.showLoading({
 							title: '登录中',
@@ -160,14 +181,14 @@
 								phone: that.phone,
 								password: that.password,
 								loginFlag: 1,
-								identification:2
+								identification: 2
 							}).then(res => {
 								if (res.code == 200) {
 									uni.setStorageSync('userInfo', res.data)
 									that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
 										reCommonId: that.userInfo.id,
 									}).then(res3 => {
-										if (res3.data||res3.data==0) {
+										if (res3.data || res3.data == 0) {
 											let name = 'myTip';
 											let value = res3.data
 											if (value == 0) {
@@ -187,7 +208,7 @@
 											}
 										}
 									})
-									
+
 									that.$store.commit('login', res.data)
 									var name = 'userInfo';
 									var value = res.data;
@@ -252,22 +273,26 @@
 	page {
 		background: #fff;
 	}
-	.phone{
-		padding:20rpx;
-		font-size:28rpx;
+
+	.phone {
+		padding: 20rpx;
+		font-size: 28rpx;
 	}
+
 	.close {
 		width: 20px;
 		height: 20px;
 		position: absolute;
 		right: 0px;
 	}
-	.yanjingicon{
-		position:absolute;
-		right:0;
-		top:50%;
-		transform: translate(-50%,-50%);
+
+	.yanjingicon {
+		position: absolute;
+		right: 0;
+		top: 50%;
+		transform: translate(-50%, -50%);
 	}
+
 	.close1 {
 		width: 20px;
 		height: 20px;
@@ -288,7 +313,7 @@
 	.password {
 		border: none;
 		outline: none;
-		font-size:28rpx;
+		font-size: 28rpx;
 	}
 
 	.cuIcon-weixin {
@@ -374,7 +399,8 @@
 		font-weight: 500;
 		color: #333333;
 	}
+
 	/deep/.uni-input-input:disabled {
-	    background:#fff;
+		background: #fff;
 	}
 </style>