DELL 3 жил өмнө
parent
commit
c0fefad41c

+ 22 - 1
src/components/auth/auth.vue

@@ -5,6 +5,7 @@
 				<view class="tip">为了正常使用功能,请授权用户信息。</view>
 				<!-- #ifdef MP-ALIPAY -->
 				<button :loading="authIng" @click="getInfoAli()" type="default">授权</button>
+				<view style="height: 100rpx;"></view>
 				<!-- #endif -->
 				<!-- #ifndef MP-ALIPAY -->
 				<button :loading="authIng" @click="getInfo()" type="default">授权</button>
@@ -76,7 +77,27 @@
 			
 			
 			getInfoAli(){
-				
+				let _this = this
+				if (this.authIng) {
+					return
+				}
+				_this.authIng = true
+				my.getAuthCode ({
+					scopes : ['auth_user'],
+					success: (res) => {
+						console.log("res2",res);
+						$http.post('/api/v1/mp/user/aliAuth', {code: res.authCode}).then(res => {
+							_this.authIng = false
+							if (res.code === 0) {
+								uni.$u.toast('授权成功');
+								_this.authIng = false
+								_this.$emit('close')
+							}
+						}).catch(() => {
+							_this.authIng = false
+						})
+					}
+				})
 			}
 		}
 	}

+ 17 - 2
src/pages/login/code.vue

@@ -110,11 +110,11 @@
 				}).then(res => {
 					_this.loading = false
 					if (res.code === 0 && res.token) {
-						// #ifdef MP-WEIXIN
+						// #ifdef MP-WEIXIN || MP-ALIPAY
 						uni.setStorageSync('token', res.token)
 						_this.getBaseInfo()
 						// #endif
-						// #ifdef H5 || MP-ALIPAY
+						// #ifdef H5 
 						uni.$u.toast('登录成功');
 						uni.setStorageSync('token', res.token)
 						setTimeout(() => {
@@ -134,6 +134,20 @@
 					uni.hideLoading();
 					if (res.code == 0) {
 						uni.setStorageSync('userInfo', res.data)
+						// #ifdef MP-ALIPAY
+						console.log("111");
+						if (res.data.aliuserId) {
+							uni.$u.toast('登录成功');
+							setTimeout(() => {
+								uni.navigateBack({
+									delta: 2
+								})
+							}, 500)
+						} else {
+							this.authShow = true
+						}
+						// #endif
+						// #ifndef MP-ALIPAY
 						if (res.data.openId) {
 							uni.$u.toast('登录成功');
 							setTimeout(() => {
@@ -144,6 +158,7 @@
 						} else {
 							this.authShow = true
 						}
+						// #endif
 					}
 				}).catch(() => {
 					uni.hideLoading();

+ 7 - 27
src/pages/login/index.vue

@@ -16,7 +16,6 @@
 			<!-- #ifdef MP-ALIPAY -->
 			<view class="login-btn">
 			<button open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>支付宝登录</button>
-			<button @click="onCode">获取code</button>
 			</view>
 			<!-- #endif -->
 			<!-- #ifndef MP-ALIPAY -->
@@ -188,9 +187,9 @@
 				$http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
 					uni.hideLoading();
 					if (res.code == 0) {
-						console.log(res);
+						console.log("11111",res);
 						uni.setStorageSync('userInfo', res.data)
-						if (res.data.aliUserId) {
+						if (res.data.aliuserId) {
 							uni.$u.toast('登录成功');
 							setTimeout(() => {
 								uni.navigateBack({
@@ -205,16 +204,12 @@
 					uni.hideLoading();
 				})
 			},
-			onAuthError(e) {
-				console.log("err",e);
-			},
 			onGetAuthorize(e){
 				let _this = this
 				if (!_this.checked) {
 					uni.$u.toast('请阅读并勾选底部协议');
 					return
 				}
-				
 				 my.getPhoneNumber({
 				    success: (res) => {
 						uni.showLoading({
@@ -225,33 +220,18 @@
 							identity: 1,
 							noToken: true
 						}).then(res=>{
+							console.log("res",res);
 							if(res.code == 0){
 								uni.setStorageSync('token', res.token)
 								_this.getBaseInfoAli()
+							}else{
+								uni.hideLoading();
 							}
 						})
 				    },
-				    fail: (res) => {
-				        console.log("faukres",res);
-				        console.log('getPhoneNumber_fail');
-				    },
-				  });
-				console.log("phone",e);
+					})
 			},
-			onCode() {
-				console.log("1111");
-				 my.getAuthCode ({
-					scopes : ['auth_user'],
-					success: (res) => {
-						console.log(res);
-						my.alert({
-							content: res.authCode,
-						});
-					},
-				})
-			}
-			
-		},
+		}
 	}
 </script>