瀏覽代碼

增加授权码登录

htc 2 天之前
父節點
當前提交
7e6d8810f1
共有 2 個文件被更改,包括 80 次插入23 次删除
  1. 2 2
      http/baseApi.js
  2. 78 21
      pages/login.vue

+ 2 - 2
http/baseApi.js

@@ -1,6 +1,6 @@
 // const BaseApi = 'https://transcend.ringzle.com/chuangheng-app/app' //线上
-const BaseApi = 'https://wxapp.transcend-intl.cn/chuangheng-app/app' //生产
-// const BaseApi = 'http://192.168.2.19:9023/chuangheng-app/app' //李勇
+// const BaseApi = 'https://wxapp.transcend-intl.cn/chuangheng-app/app' //生产
+const BaseApi = 'http://192.168.2.19:9023/chuangheng-app/app' //李勇
 
 export {
 	BaseApi

+ 78 - 21
pages/login.vue

@@ -20,8 +20,21 @@
 				</div>
 			</div>
 			<button class="zt_btn" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">手机号一键登录</button>
+			<button class="zt_btn" style="margin-top: 20rpx;" @tap="codeLogin">授权码登录</button>
 			<div class="qx_btn" @click="cancelLogin">取消登录</div>
 		</div>
+		<u-popup :show="show" @close="cancel" mode="center" :round="20">
+			<div class="code">
+				<p>授权码登录</p>
+				<u-input v-model="phone" placeholder="请输入手机号"></u-input>
+				<div style="margin-top: 20rpx;"></div>
+				<u-input v-model="code" placeholder="请输入授权码"></u-input>
+				<div class="cbtns adfacjb">
+					<div class="zt_btn" @tap="toCodeLogin">登录</div>
+					<div class="qx_btn" @tap="cancel">取消</div>
+				</div>
+			</div>
+		</u-popup>
 	</view>
 </template>
 
@@ -29,7 +42,9 @@
 	export default {
 		data(){
 			return {
-				
+				show:false,
+				phone:'',
+				code:''
 			}
 		},
 		methods:{
@@ -41,7 +56,25 @@
 					return
 				}
 				if(e.detail.code) this.wxLogin(e.detail.code);
-			},
+			},
+			codeLogin(){
+				this.show = true;
+			},
+			toCodeLogin(){
+				if(!this.$reg.mobile(this.phone)) return this.$showToast('请输入正确的手机号!')
+				if(!this.code) return this.$showToast('请输入授权码!')
+				this.$api.get('/wx/login-code',{
+					checkCode:this.code,
+					phone:this.phone
+				}).then(res=>{
+					if(res.data.code!==0) return this.$showToast(res.data.msg)
+					this.loginSuccessFn(res);
+				})
+			},
+			cancel(){
+				this.code = '';
+				this.show = false;
+			},
 			wxLogin(code){
 				uni.showLoading({ title:'登录中' });
 				let that = this;
@@ -52,29 +85,32 @@
 							phoneCode:code
 						},false).then(res=>{
 							if(res.data.code===0){
-								uni.setStorageSync('token',res.data.data.token);
-								uni.setStorageSync('userInfo',JSON.stringify({
-									id:res.data.data.id,
-									gender:res.data.data.gender,
-									realName:res.data.data.realName,
-									mobile:res.data.data.mobile,
-									headUrl:res.data.data.headUrl,
-									teamId:res.data.data.teamId,
-									enterpriseId:res.data.data.enterpriseId,
-									enterpriseName:res.data.data.enterpriseName,
-									teamName:res.data.data.teamName
-								}));
-								
-								uni.hideLoading();
-								that.$showToast('登录成功');
-								setTimeout(()=>{
-									uni.reLaunch({ url:'/pages/home' })
-								},1500)
+								this.loginSuccessFn(res);
 							}else that.$showToast(res.data.msg)
 						})
 					}
 				})
 			},
+			loginSuccessFn(res){
+				uni.setStorageSync('token',res.data.data.token);
+				uni.setStorageSync('userInfo',JSON.stringify({
+					id:res.data.data.id,
+					gender:res.data.data.gender,
+					realName:res.data.data.realName,
+					mobile:res.data.data.mobile,
+					headUrl:res.data.data.headUrl,
+					teamId:res.data.data.teamId,
+					enterpriseId:res.data.data.enterpriseId,
+					enterpriseName:res.data.data.enterpriseName,
+					teamName:res.data.data.teamName
+				}));
+				
+				uni.hideLoading();
+				this.$showToast('登录成功');
+				setTimeout(()=>{
+					uni.reLaunch({ url:'/pages/home' })
+				},1500)
+			},
 			cancelLogin(){
 				// uni.exitMiniProgram();
 				uni.reLaunch({ url:'/pages/home' })
@@ -140,11 +176,32 @@
 				}
 			}
 			.zt_btn{
-				margin-top: 216rpx;
+				margin-top: 176rpx;
 			}
 			.qx_btn{
 				margin-top: 36rpx;
 			}
 		}
 	}
+	
+	.code{
+		width: 700rpx;
+		padding: 40rpx 60rpx 40rpx;
+		border-radius: 32rpx 32rpx 0 0;
+		box-sizing: border-box;
+		p{
+			font-size: 40rpx;
+			font-weight: bold;
+			margin-bottom: 50rpx;
+		}
+		.cbtns{
+			margin-top: 50rpx;
+			&>div{
+				width: calc(50% - 20rpx);
+			}
+			.qx_btn{
+				background: #f1f1f1;
+			}
+		}
+	}
 </style>