浏览代码

login new

zizhong.wang 2 年之前
父节点
当前提交
6cffc51736
共有 5 个文件被更改,包括 71 次插入23 次删除
  1. 47 4
      App.vue
  2. 11 1
      pages/auth/index.vue
  3. 1 1
      pages/heatingPage/pay.vue
  4. 9 17
      pages/index/index.vue
  5. 3 0
      pages/selfCenter/index.vue

+ 47 - 4
App.vue

@@ -16,6 +16,7 @@ export default {
 	user_phone:'',
 	user_headUrl:'',
 	globalAuth:false,
+	isAuth : false,
 	session_key: '',
 	contact_name:'',
 	company_name:'',
@@ -102,9 +103,8 @@ export default {
 		  return str;
 	  },
 	  loginRequest(codeRes){
-	  	let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
-	  	let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&source=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
-	  	uni.request({
+	  	let url = getApp().makeApiUrl("user",'user','login');
+		uni.request({
 	  		url:url,
 	  		method: 'POST',
 	  		header: {
@@ -121,6 +121,13 @@ export default {
 					getApp().globalData.user_status = res.data.data.status;
 					getApp().globalData.user_phone = res.data.data.phone;
 					getApp().globalData.nowTime = this.getNowTime();
+					if (res.data.data.phone === ''){
+						//必须有手机号才算登录成功,系统才可用。
+						getApp().globalData.isAuth = false;
+					}
+					else{
+						getApp().globalData.isAuth = true;
+					}
 					uni.setStorageSync('openId', res.data.data.openid);
 				//	uni.hideLoading() 
 	  			}
@@ -130,7 +137,43 @@ export default {
 	  		}
 	  	});
 	  },
-	  
+	  getPhoneNumber(e){
+	  	 if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
+	  	 console.log(e.detail);
+	  	  getApp().phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
+		  return true;
+	  	} else { //
+	  	  return false;
+	  	}
+	  },
+	  phoneRequest(myIv,myEncryptedData,sKey){
+	  	let url = getApp().makeApiUrl('user','user','phone');
+		uni.request({
+	  		url:url,
+	  		method: 'POST',
+	  		header: {
+	  			'content-type': 'application/x-www-form-urlencoded'
+	  		},
+	  		data: {
+	  			iv:myIv,
+	  			sessionKey:sKey,
+	  			encryptedData:myEncryptedData,
+	  			openId:getApp().globalData.open_id
+	  		},
+	  		success: (res) => {
+	  			console.log(res)
+	  			if(res.data.code === 200){
+	  				getApp().globalData.user_phone = res.data.data;
+					if (res.data.data != ""){
+						getApp().globalData.isAuth = true;
+					}
+	  			}
+	  		},
+	  		fail: () => {
+	  			console.log("连接失败");
+	  		}
+	  	});
+	  },
   }
 };
 </script>

+ 11 - 1
pages/auth/index.vue

@@ -9,9 +9,13 @@
 		
 		<view class="margin-top-3">
 			<button type='default' class="refuse" @click="refuseBtn">暂不授权</button>
+			<!--
 			<button type='primary' class="allow" @click="getUserInfo()" v-if="!isAuth">登录授权</button>
 			<button type="primary" class="allow"  open-type="getPhoneNumber"  style="font-size: 12px;"
 			@getphonenumber="getPhoneNumber" v-if="isAuth && !isNeedPhone">手机号码授权</button> 
+			!-->
+			
+			<button type='primary' class="allow" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="!isAuth">登录授权</button>
 		</view>
 		
 	</view>
@@ -77,7 +81,8 @@
 						this.isAuth = true;
 						getApp().globalData.isAuth = true; 
 						getApp().globalData.globalAuth = true; 
-						this.loginUserInfo()
+						this.loginUserInfo();
+						
 					},
 					fail:(err)=> {
 						getApp().globalData.isAuth = false;
@@ -98,6 +103,9 @@
 				// }
 			},
 			getPhoneNumber(e){
+				//this.getUserInfo();
+				let res = getApp().getPhoneNumber(e);
+				/*
 				let that = this;
 				 if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
 				 console.log(e.detail)
@@ -105,6 +113,7 @@
 				} else { //
 				      that.isNeedPhone = false;
 				}
+				*/
 			},
 			phoneRequest(myIv,myEncryptedData,sKey){
 				let that = this;
@@ -167,6 +176,7 @@
 							// getApp().globalData.user_phone = res.data.msg.phone;
 							// that.isNeedPhone = res.data.msg.phone;
 							// that.isAuth = getApp().globalData.isAuth;
+							
 						}
 						else {
 							uni.showToast({

+ 1 - 1
pages/heatingPage/pay.vue

@@ -272,7 +272,7 @@ export default {
 		  			  return;
 		  }
 		  
-		  if (this.invoicePhone === '' && this.invoiceEmail){
+		  if (this.invoicePhone === '' && this.invoiceEmail === ''){
 			  uni.showToast({
 			    title: '手机号和邮箱至少填写一项!',
 			    icon: "none",

+ 9 - 17
pages/index/index.vue

@@ -98,7 +98,7 @@
 		 <view>{{!isAuth ? '未登录': '未关联'}}</view>
 		 <view>{{!isAuth ? '请先完成授权登录': '请先完成关联住房'}}</view>
 		 <view class="withHouseBtn" @click="goHouse" v-show="isAuth">关联住房</view>
-		 <view class="withHouseBtn" @click="goAuth" v-show="!isAuth">授权登录</view>
+		 <button type='primary' class="withHouseBtn" v-show="!isAuth" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权登录</button>
 	 </view>
     </view>
    
@@ -174,6 +174,12 @@ export default {
       }
   },
   methods: {
+	getPhoneNumber(e){
+		let res = getApp().getPhoneNumber(e);
+		if (res){
+			this.goHouse();
+		}
+	},
     swiperChange(e) {
       this.swiperCurrent = e.detail.current;
     },
@@ -184,22 +190,8 @@ export default {
 	},
     getSwiperList() {
 	  let that = this;
-      let md5Sign = md5(
-        "method=" +
-          "common" +
-          "&timestamp=" +
-          getApp().globalData.globalTimestamp +
-          "&secret=" +
-          getApp().globalData.secret
-      );
-      let url =
-        getApp().globalData.shareUrl +
-        "api/api.php" +
-        "?method=common&source=main_pics&action=list&timestamp=" +
-        getApp().globalData.globalTimestamp +
-        "&sign=" +
-        md5Sign;
-		
+      
+	  let url = getApp().makeApiUrl("common","main_pics","list");
 	   
       uni.request({
         url: url,

+ 3 - 0
pages/selfCenter/index.vue

@@ -100,9 +100,12 @@ export default {
   },
   methods: {
     goAuthPage() {
+	  
       uni.navigateTo({
         url: "../auth/index",
       });
+	  
+	 
     },
 	goWithHouse(){
 		if (this.isWith == 0)