DELL 3 ani în urmă
părinte
comite
70ebe1d42b
2 a modificat fișierele cu 47 adăugiri și 13 ștergeri
  1. 10 8
      src/components/auth/auth.vue
  2. 37 5
      src/pages/login/index.vue

+ 10 - 8
src/components/auth/auth.vue

@@ -3,7 +3,12 @@
 		<u-popup :show="authShow" mode="bottom">
 			<view class="auth-wrap">
 				<view class="tip">为了正常使用功能,请授权用户信息。</view>
+				<!-- #ifdef MP-ALIPAY -->
+				<button :loading="authIng" @click="getInfoAli()" type="default">授权</button>
+				<!-- #endif -->
+				<!-- #ifndef MP-ALIPAY -->
 				<button :loading="authIng" @click="getInfo()" type="default">授权</button>
+				<!-- #endif -->
 			</view>
 		</u-popup>
 	</view>
@@ -68,14 +73,11 @@
 					}
 				})
 			},
-
-			getBaseInfo() {
-				$http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
-					if (res.code == 0) {
-						uni.setStorageSync('userInfo', res.data)
-					}
-				})
-			},
+			
+			
+			getInfoAli(){
+				
+			}
 		}
 	}
 </script>

+ 37 - 5
src/pages/login/index.vue

@@ -15,7 +15,7 @@
 			</view>
 			<!-- #ifdef MP-ALIPAY -->
 			<view class="login-btn">
-			<button if="canIUseAuthButton" open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>支付宝登录</button>
+			<button open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>支付宝登录</button>
 			<button @click="onCode">获取code</button>
 			</view>
 			<!-- #endif -->
@@ -59,7 +59,6 @@
 				authShow: false,
 				token: '',
 				checked: true,
-				canIUseAuthButton: my.canIUse('button.open-type.getAuthorize')
 			};
 		},
 		methods: {
@@ -168,6 +167,7 @@
 				$http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
 					uni.hideLoading();
 					if (res.code == 0) {
+						console.log(res);
 						uni.setStorageSync('userInfo', res.data)
 						if (res.data.openId) {
 							uni.$u.toast('登录成功');
@@ -184,19 +184,51 @@
 					uni.hideLoading();
 				})
 			},
+			getBaseInfoAli(){
+				$http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
+					uni.hideLoading();
+					if (res.code == 0) {
+						console.log(res);
+						uni.setStorageSync('userInfo', res.data)
+						if (res.data.aliUserId) {
+							uni.$u.toast('登录成功');
+							setTimeout(() => {
+								uni.navigateBack({
+									delta: 1
+								})
+							}, 500)
+						} else {
+							this.authShow = true
+						}
+					}
+				}).catch(() => {
+					uni.hideLoading();
+				})
+			},
 			onAuthError(e) {
 				console.log("err",e);
 			},
 			onGetAuthorize(e){
+				let _this = this
+				if (!_this.checked) {
+					uni.$u.toast('请阅读并勾选底部协议');
+					return
+				}
+				
 				 my.getPhoneNumber({
 				    success: (res) => {
-				        let encryptedData = res.response;
+						uni.showLoading({
+							title: '登录中'
+						});
 						$http.post('/api/v1/mp/user/aliAuth/mobile', {
-							encryptedData,
+							encryptedData: res.response,
 							identity: 1,
 							noToken: true
 						}).then(res=>{
-							console.log("successres",res);
+							if(res.code == 0){
+								uni.setStorageSync('token', res.token)
+								_this.getBaseInfoAli()
+							}
 						})
 				    },
 				    fail: (res) => {