twt преди 2 години
родител
ревизия
ebd1536445
променени са 2 файла, в които са добавени 95 реда и са изтрити 50 реда
  1. 65 2
      pages/index/index.vue
  2. 30 48
      pages/user/user.vue

+ 65 - 2
pages/index/index.vue

@@ -6,7 +6,7 @@
 		<view>
 			url:{{url}}
 		</view>
-		
+		<button type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">获取手机号</button>
 	</view>
 </template>
 
@@ -16,17 +16,35 @@
 			return {
 				shopId: '',
 				url:'',
+				wxOpenData:'',
+				code:'',
 			}
 		},
 		onLoad() {
+			var that=this;
 			 this.$common.getExtStoreId()
 			 var ext=this.$common.getExtStoreId();
 			console.log(ext)
 			this.shopId=ext.shopId;
 			this.url=ext.url;
+			uni.setStorage({
+				key: 'extdata',
+				data: {
+					shopId:'E37BB296-5A08-4534-859D-B351BA611AF9',
+				},
+				 success: function () {
+				     that.uniLogin()
+				 
+				 }
+			}); 
 			this.uniLogin()
 		},
 		methods: {
+			decryptPhoneNumber: function(e) {
+			  console.log(e);
+			  this.code=e.detail.code
+			  this.wxPhoneLogin()
+			},
              wxgologin(){
              	var that=this;
              	uni.getUserProfile({
@@ -60,13 +78,58 @@
 				 });
 			 },
 			 getWxOpenID(e){
+				 var that=this;
+				// this.code=e.code;
 				 this.$http('miniApp2/sys/getWxOpenID', {
 				   code:e.code,
 				   shopId:'E37BB296-5A08-4534-859D-B351BA611AF9'
 				  },'GET').then(res => {
-				 	
+				 	this.wxOpenData=res.data;
+					//that.wxPhoneLogin()
+					uni.setStorage({
+						key: 'wxOpenData',
+						data: that.wxOpenData,
+						 success: function () {
+						    // that.uniLogin()
+						 
+						 }
+					}); 
+					if(this.wxOpenData.loginInfo){
+						uni.setStorage({
+							key: 'userInfo',
+							data: that.wxOpenData.loginInfo.openUser,
+							 success: function () {
+							    // that.uniLogin()
+							 
+							 }
+						}); 
+					}
+					
+					
 				  })
 			 },
+			 wxPhoneLogin(){
+				 var that=this;
+				 this.$http('miniApp2/sys/wxPhoneLogin', {
+				   appId:'wx33053a645546ec31',
+				   shopId:'E37BB296-5A08-4534-859D-B351BA611AF9',
+				   code:this.code,
+				   openId:this.wxOpenData.openid
+				  },'POST').then(res => {
+				 	var data = res.data;
+					if(data.loginInfo){
+						uni.setStorage({
+							key: 'userInfo',
+							data: data.loginInfo.openUser,
+							 success: function () {
+							    // that.uniLogin()
+							 
+							 }
+						}); 
+					}
+				 		
+				  })
+			 }
 			 
 		}
 	}

+ 30 - 48
pages/user/user.vue

@@ -1,6 +1,8 @@
 <template>
 	<view class="content">
-		我的
+		<view class="" @click="updateUserInfo">
+			{{loginInfo.nickName?loginInfo.nickName:'点击刷新'}}
+		</view>
 		
 	</view>
 </template>
@@ -9,62 +11,42 @@
 	export default {
 		data() {
 			return {
-				shopId: '',
-				url:'',
+				loginInfo:'',
+				extdata:'',
+				opendata:'',
 			}
 		},
 		onLoad() {
-			 this.$common.getExtStoreId()
-			 var ext=this.$common.getExtStoreId();
-			console.log(ext)
-			this.shopId=ext.shopId;
-			this.url=ext.url;
-			this.uniLogin()
+			this.loginInfo = uni.getStorageInfoSync(userInfo);
+			this.extdata=uni.getStorageInfoSync(extdata);
+			this.opendata=uni.getStorageInfoSync(wxOpenData);
 		},
 		methods: {
-             wxgologin(){
-             	var that=this;
-             	uni.getUserProfile({
-             		lang:'zh_CN',
-             		desc:'登录',
-             		success:(res)=>{
-             			console.log(res);
-             			that.wxdata=res;
-             			 uni.setStorage({
-             				key: 'wxdata',
-             				data: res,
-             				 success: function () {
-             				     that.uniLogin()
-             				 
-             				 }
-             			}); 
-             		},
-             		fail:(res)=>{
-             			console.log(res)
-             		}
-             	});
-             },
-			 uniLogin(){
-				 uni.login({
-				   provider: 'weixin',
-				   success: function (loginRes) {
-				     console.log(loginRes);
-				   }
-				 });
-			 }
+            updateUserInfo(){
+				return false;
+				var that=this;
+				 this.$http('miniApp2/sys/updateUserInfo', {
+				   openId:this.opendata.openid,
+				   shopId:this.extdata.shopId,
+				   
+				  },'POST').then(res => {
+				 	this.wxOpenData=res.data;
+					//that.wxPhoneLogin()
+					uni.setStorage({
+						key: 'wxOpenData',
+						data: that.wxOpenData,
+						 success: function () {
+						    // that.uniLogin()
+						 
+						 }
+					}); 
+					
+				  })
+			}
 		}
 	}
 </script>
 
 <style>
 	
-	.logo {
-		height: 200rpx;
-		width: 200rpx;
-		margin-top: 200rpx;
-		margin-left: auto;
-		margin-right: auto;
-		margin-bottom: 50rpx;
-	}
-
 </style>