Sfoglia il codice sorgente

商户端登录调试

zhaoxw 4 anni fa
parent
commit
e3ae756c90
1 ha cambiato i file con 65 aggiunte e 62 eliminazioni
  1. 65 62
      pages/index/index.vue

+ 65 - 62
pages/index/index.vue

@@ -14,19 +14,23 @@
 			</button>
 			<view class="authorize-info">{{wxPhoneData? '****************' : ''}}</view> -->
 			<!-- <view class="authorize-login" @click="getUserInfo">登录</view> -->
+			<!-- #ifdef MP-WEIXIN -->
 			<button 
 				class="authorize-login" 
 				open-type="getUserInfo" 
 				@getuserinfo="getUserinfoWechat" withCredentials="true" >
 				登录
 			</button>
-			<view @click="showAgreement = true" class="agreement">点击登录视为同意<text class="underline">商家入驻协议</text></view>
-			<!-- <button 
+			<!-- #endif -->
+
+			<!-- #ifdef APP-PLUS -->
+			<button
 				class="authorize-login" 
-				open-type="getUserInfo" 
 				@click="getUserinfoApp">
-				登录
-			</button> -->
+				登录4
+			</button>
+			<!-- #endif -->
+			<view @click="showAgreement = true" class="agreement">点击登录视为同意<text class="underline">商家入驻协议</text></view>
 		</view>
 		{{tipxx}}
 		<u-top-tips ref="uTips"></u-top-tips>
@@ -287,6 +291,7 @@
 			// 		})
 			// 	}
 			// },
+			// #ifdef MP-WEIXIN
 			getUserinfoWechat(data) {
 				uni.getProvider({
 					service: 'oauth',
@@ -327,69 +332,67 @@
 					}
 				});
 			},
-			//  获取登录权限
-			// getUserinfoApp() {
-			// 	uni.getProvider({
-			// 		service: 'oauth',
-			// 		success: (res) => {
-			// 			if (~res.provider.indexOf('weixin')) {
-			// 				uni.login({
-			// 					provider: 'weixin',
-			// 					success: (res2) => {
-			// 						uni.getUserInfo({
-			// 							provider: 'weixin',
-			// 							success: (info) => {
-			// 								uni.setStorage({
-			// 									key: 'wxLoginData',
-			// 									data: {
-			// 										code: res2.code,
-			// 										encryptedData: info.encryptedData,
-			// 										iv: info.iv,
-			// 										rawData: info.rawData,
-			// 										signature: info.signature,
-			// 									}
-			// 								})
-			// 								this.wxLoginData = uni.getStorageSync("wxLoginData")
-			// 								console.log(1111111,this.wxLoginData&&this.wxLoginData.rawData)
-			// 								this.userNmae = JSON.parse(this.wxLoginData.rawData).nickName
-			// 								this.getUserInfo()
-			// 								// this.$refs.uTips.show({
-			// 								// 	title: '获取角色信息成功',
-			// 								// 	type: 'success',
-			// 								// })
-			// 							},
-			// 							fail: (error) => {
-			// 								console.log(2222, error)
-			// 								this.$refs.uTips.show({
-			// 									title: '微信登录授权失败',
-			// 									type: 'warning',
-			// 								})
-			// 							}
-			// 						})
-			// 					},
-			// 					fail: () => {
-			// 						console.log(33333, error)
-			// 						this.$refs.uTips.show({
-			// 							title: '微信登录授权失败',
-			// 							type: 'warning',
-			// 						})
-			// 					}
-			// 				})
-			// 			} else {
-			// 				this.$refs.uTips.show({
-			// 					title: '请先安装微信或升级版本',
-			// 					type: 'warning',
-			// 				})
-			// 			}
-			// 		}
-			// 	});
-			// },
+            //#endif
+			
+			// #ifdef APP-PLUS
+			//  获取app登录权限
+			getUserinfoApp() {
+				let that = this
+				console.log('app enter')
+				uni.login({
+					provider: 'weixin',
+					success: (res2) => {
+						console.log('res2', res2)
+						uni.getUserInfo({
+							provider: 'weixin',
+							success: (info) => {
+								console.log('info',info)
+								uni.setStorage({
+									key: 'wxLoginData',
+									data: {
+										nickName: info.userInfo.nickName,
+										gender: info.userInfo.gender,
+										avatarUrl: info.userInfo.avatarUrl,
+										unionId: info.userInfo.unionId,
+										openId:info.userInfo.openId
+									}
+								})
+								that.wxLoginData = uni.getStorageSync("wxLoginData")
+								console.log(1111111, that.wxLoginData)
+								// that.userNmae = JSON.parse(that.wxLoginData.rawData).nickName
+								that.getUserInfo()
+								this.$refs.uTips.show({
+									title: '获取角色信息成功',
+									type: 'success',
+								})
+							},
+							fail: (error) => {
+								console.log(2222, error)
+								that.$refs.uTips.show({
+									title: '微信登录授权失败',
+									type: 'warning',
+								})
+							}
+						})
+					},
+					fail: (error) => {
+						console.log(33333, error)
+						that.$refs.uTips.show({
+							title: '微信登录授权失败',
+							type: 'warning',
+						})
+					}
+				})
+				console.log('app end')
+			},
+			//#endif
 			// 发请求获取个人数据
 			getUserInfo() {
 				NET.request(API.WxLogin, {
 					...this.wxLoginData,
 					// ...this.wxPhoneData,
 				}, 'POST').then(res => {
+					console.log('发请求获取个人数据', res)
 					uni.setStorage({
 						key: 'token',
 						data: res.data.token