306132416@qq.com 6 anni fa
parent
commit
d965ea3122
4 ha cambiato i file con 223 aggiunte e 17 eliminazioni
  1. 2 2
      App.vue
  2. 13 2
      pages.json
  3. 161 0
      pages/auth/index.vue
  4. 47 13
      pages/index/index.vue

+ 2 - 2
App.vue

@@ -2,8 +2,8 @@
 	var md5 = require("./common/md5.js");
 	export default {
 		globalData: {  //https://stock.xazhima.com/
-		    shareUrl:'https://stock.xazhima.com/api/api.php',
-			//shareUrl: 'https://guolu.xazhima.com/api/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
+		    //shareUrl:'https://stock.xazhima.com/api/api.php',
+			shareUrl: 'https://guolu.xazhima.com/api/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
 			glbalHeight:'',
 			globalTimestamp: (Date.now()).toString(),
 			user_id: '',

+ 13 - 2
pages.json

@@ -1,12 +1,22 @@
 {
 	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
+		
 		{
 			"path": "pages/index/index",
 			"style": {
 					"navigationBarTitleText": "阿拉灯神丁"
 					}
-		}
-	    ,{
+		},
+		
+		{
+		    "path" : "pages/auth/index",
+		    "style": {
+		    		"navigationBarTitleText": "授权登录"
+		    		}
+		},
+		
+		
+	    {
             "path" : "pages/chat/chat",
             "style" : {} 
         }
@@ -14,6 +24,7 @@
             "path" : "pages/chat/chatDetail/chatDetail",
             "style" : {}
         }
+		
 		,{
 		    "path" : "pages/selfInfo/selfInfo",
 		    "style" : {

+ 161 - 0
pages/auth/index.vue

@@ -0,0 +1,161 @@
+<template>
+	<view class="auth">
+		
+		<image src="../../static/rabotHead.png" mode=""></image>
+		
+		<text class="margin-top-3 auth-title">欢迎使用阿拉灯神丁</text>
+		
+		<text class="margin-top-3 auth-content">此页面是微信授权页面,授权之后你可以获取更优质的服务,您的隐私将会受到保护</text>
+		
+		<view class="margin-top-3">
+			<button type='default' class="refuse" @click="refuseBtn">暂不授权</button>
+			<button type='primary' class="allow" open-type="getUserInfo" @getuserinfo="getUserInfo">允许授权</button>
+		</view>
+		
+	</view>
+</template>
+
+<script>
+	var md5 = require("../../common/md5.js");
+	export default {
+		data(){
+			return {
+				iv:'',
+				encryptedData:''
+			}
+		},
+		onLoad() {
+		},
+		methods:{
+			getUserInfo(e) {
+				console.log(e);
+				if (e.detail.errMsg == "getUserInfo:ok") {
+					
+					this.iv = e.detail.iv;
+					this.encryptedData = e.detail.encryptedData;
+					
+					this.loginUserInfo()
+				} else {
+					console.log("用户信息授权失败");
+					getApp().globalData.isAuth = false;
+				}
+			},
+			refuseBtn(){
+				uni.navigateBack({
+				});
+			},
+			loginUserInfo(){
+				let that = this;
+				uni.request({
+					url:getApp().globalData.shareUrl, //需要设置为全局
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					},
+					data: {
+						method: 'auth',
+						timestamp: getApp().globalData.globalTimestamp, //Date.now()
+						uid:getApp().globalData.user_id,
+						sign: md5('auth' + getApp().globalData.globalTimestamp),
+						nickname:getApp().globalData.user_name,
+						headimg:getApp().globalData.user_headUrl,
+						iv:that.iv,
+						session_key:getApp().globalData.session_key,
+						encryptedData:that.encryptedData
+					},
+					success: res => {
+						getApp().globalData.user_id = res.data.msg.id;
+						getApp().globalData.open_id = res.data.msg.openid;
+						getApp().globalData.isAuth = true;
+						getApp().globalData.times = res.data.msg.times;
+						getApp().globalData.total_times = res.data.msg.total_times;
+						getApp().globalData.user_headUrl = res.data.msg.headimg;
+						getApp().globalData.user_name = res.data.msg.name;
+						uni.navigateBack({
+						});
+					} 
+				});
+			},
+		}
+	}
+</script>
+
+<style>
+   .auth{
+	   margin-top: 0;
+	   text-align: center;
+	   display: flex;
+	   flex-direction: column;
+	   justify-content: center;
+	   align-items: center;
+	   padding: 100upx;
+	   vertical-align: middle;
+   }
+   .auth image{
+	   width: 200upx;
+	   height: 200upx;
+   }
+   .auth view {
+	   display: flex;
+	   width: 490upx;
+	   justify-content: space-between;
+   }
+   .auth-title {
+	   font-size: 32upx;
+   }
+   .auth-content {
+   	   font-size: 26upx;
+	   color: #a7aaa9;
+   }
+   .allow {
+	   background-color: #27BCEF;
+	   margin: 20rpx 0 200rpx;
+	   text-align: center;
+	   vertical-align: middle;
+	   touch-action: manipulation;
+	   cursor: pointer;
+	   background-image: none;
+	   white-space: nowrap;
+	   user-select: none;
+	   font-size: 14px;
+	   border: 0 !important;
+	   position: relative;
+	   text-decoration: none;
+	   height: 44px;
+	   width: 250rpx;
+	   line-height: 44px;
+	   box-shadow: inset 0 0 0 1px #27BCEF;
+	   background: #fff !important;
+	   color: #27BCEF !important;
+	   display: inline-block;
+	   border-radius: 10rpx;
+
+   }
+   .refuse {
+	   background-color: #19be6b;
+	   margin: 20rpx 20rpx 200rpx 20rpx;
+	   text-align: center;
+	   vertical-align: middle;
+	   touch-action: manipulation;
+	   cursor: pointer;
+	   background-image: none;
+	   white-space: nowrap;
+	   user-select: none;
+	   font-size: 14px;
+	   border: 0 !important;
+	   position: relative;
+	   text-decoration: none;
+	   height: 44px;
+	   width: 250rpx;
+	   line-height: 44px;
+	   box-shadow: inset 0 0 0 1px #8a8a8a;
+	   background: #fff !important;
+	   color: #8a8a8a !important;
+	   display: inline-block;
+	   border-radius: 10rpx;
+
+   }
+   .margin-top-3{
+	   margin-top: 10%;
+   }
+</style>

+ 47 - 13
pages/index/index.vue

@@ -39,7 +39,7 @@
 
 		</scroll-view>
 		<view class="send-box" :style="{ 'padding-bottom' : isShowKeyBoard + 'px'}">
-			<input type="text" class="enter-box" v-model="inputInfo" :adjust-position="true" 
+			<input type="text" class="enter-box" v-model="inputInfo" :adjust-position="true"  @focus="isNeedAuth()"
 		    :style="{'width':inputWidth}" confirm-hold='true' confirm-type='send' @confirm="sendInputInfo" />
 			<!-- @input='isInputing' -->
 			<!-- <button type="primary" class="submit-message" @click="sendInputInfo()" v-if='isShowSend'>发送</button> -->
@@ -103,6 +103,9 @@
 					mitemHeight: 0
 				},
 				isAuth:true,
+				iv:'',
+				session_key:'',
+				encryptedData:''
 			}
 		},
 		components: {
@@ -111,14 +114,23 @@
 		onPageScroll(e) {
 			this.scrollTopNav = e.scrollTop;
 		},
+		onShareAppMessage(){
+			    return {
+			      title: '阿拉灯神丁',
+			      path: '/pages/index/index'
+			    }
+		 },
+		 
 		onLoad() {
 			this.userLogin();
 			this.getEquipmentHeight();
 		},
 		onShow() {
-			this.getNowTime();
-			this.userHeadUrl = getApp().globalData.user_headUrl || '../../static/userDefault.png',
-			this.isAuth = getApp().globalData.isAuth;
+			// this.getNowTime();
+			console.log(getApp().globalData.isAuth)
+			this.userHeadUrl = getApp().globalData.user_headUrl || '../../static/userDefault.png',
+			getApp().globalData.isAuth ? this.isAuth = true : this.isAuth = false ;
+			getApp().globalData.isAuth ? this.getHistory() : this.isAuth = false ;
 		},
 		methods: {
 			userLogin(){
@@ -206,14 +218,13 @@
 						 // getApp().globalData.user_name = res.data.msg.name;
 						 // that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
 						// that.getHistory();
-							
-						var isAuth = res.data.msg.isauth === 1;
-						
-						
-						if(isAuth){
+						var isAuth = res.data.msg.isauth === 1;
+						that.session_key = res.data.msg.session_key;
+						if(isAuth){
+							 this.isAuth = true; 
 							 getApp().globalData.user_id = res.data.msg.id;
 							 getApp().globalData.open_id = res.data.msg.openid;
-					         getApp().globalData.isAuth = isAuth;
+					         getApp().globalData.isAuth = true;
 							 getApp().globalData.times = res.data.msg.times;
 							 getApp().globalData.total_times = res.data.msg.total_times;
 							 getApp().globalData.user_headUrl = res.data.msg.headimg;
@@ -222,7 +233,7 @@
 							 that.getHistory();
 						}else{
 							getApp().globalData.session_key = res.data.msg.session_key;
-							that.isAuth = isAuth;
+							that.isAuth = isAuth;
 							wx.hideLoading();
 							
 						}
@@ -265,6 +276,7 @@
 						})
 					},
 			getHistory(isShow) {
+				        // if(getApp.globalData.isAuth){this.isAuth = true}
 						let that = this;
 						uni.request({
 							url: getApp().globalData.shareUrl, //需要设置为全局
@@ -371,7 +383,20 @@
 					this.isShowSend = false;
 					this.isShowSetCenter = true;
 				}
-			},		
+			},	
+			isNeedAuth(){
+				console.log(this.isAuth)
+				if(!this.isAuth){
+					setTimeout(()=>{
+						uni.navigateTo({
+							url: '../auth/index',
+							success: res => {},
+							fail: () => {},
+							complete: () => {}
+						});
+					},500)
+				}
+			},	
 			// 滚动至底部触发的事件
 			lower() {
 				if (this.scrollRequestEnable) {
@@ -392,7 +417,16 @@
 			},
 			openModal(){
 			        // 需要在 popup 组件,指定 ref 为 popup
-			         this.$refs.popup.open();
+					if(!this.isAuth){
+						uni.navigateTo({
+							url: '../auth/index',
+							success: res => {},
+							fail: () => {},
+							complete: () => {}
+						});
+					}else {
+						this.$refs.popup.open();
+					}
 			      },
 			cancelModal(){
 				          // 需要在 popup 组件,指定 ref 为 popup