Browse Source

添加授权页及手机授权

wzz 3 years ago
parent
commit
9ce30a2614
4 changed files with 292 additions and 246 deletions
  1. 2 2
      pages.json
  2. 261 0
      pages/index/auth/index.vue
  3. 29 54
      pages/index/index.vue
  4. 0 190
      pages/index/scanCode/index.vue

+ 2 - 2
pages.json

@@ -25,10 +25,10 @@
             
         },
         {
-            "path" : "pages/index/scanCode/index",
+            "path" : "pages/index/auth/index",
             "style" :                                                                                    
             {
-                "navigationBarTitleText": "扫一扫",
+                "navigationBarTitleText": "农工笔记",
                 "enablePullDownRefresh": false
             }
             

+ 261 - 0
pages/index/auth/index.vue

@@ -0,0 +1,261 @@
+<template>
+	<view class="auth">
+		
+		<image src="/static/logo.jpg" mode="aspectFill"></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" @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> 
+		</view>
+		
+	</view>
+</template>
+
+<script>
+	import md5 from '@/common/md5.js';
+	export default {
+		data(){
+			return {
+				iv:'',
+				encryptedData:'',
+				isNeedPhone:getApp().globalData.user_phone,
+			    isAuth:getApp().globalData.isAuth
+			}
+		},
+		onLoad() {
+			this.getUserInfoData() 
+		},
+		methods:{
+			getUserInfoData(){
+				let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
+				let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&action=info_by_openid&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
+				uni.request({
+					url:url,
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					},
+					data: {
+							openId:getApp().globalData.open_id
+					},
+					success: (res) => {
+						if(res.data.code === 200){
+								if(res.data.data.nickname){
+									getApp().globalData.isAuth = true;
+									getApp().globalData.globalAuth = true;
+									getApp().globalData.user_phone = false;
+									getApp().globalData.user_name = res.data.data.nickname;
+									this.isAuth = true;
+									this.isNeedPhone = false;
+								}else{
+									getApp().globalData.user_name = '';
+									getApp().globalData.isAuth = false;
+									getApp().globalData.globalAuth = false; 
+									this.isAuth = false;
+								}
+						}
+					},
+					fail: () => {
+						console.log("连接失败");
+					}
+				});
+			},
+			getUserInfo() {
+				uni.getUserProfile({
+					desc:'登录',
+					success:(res)=> {
+						getApp().globalData.user_headUrl = res.userInfo.avatarUrl;
+						getApp().globalData.user_name = res.userInfo.nickName;
+						this.iv = res.iv;
+						this.encryptedData = res.encryptedData;
+						this.isAuth = true;
+						getApp().globalData.isAuth = true; 
+						getApp().globalData.globalAuth = true; 
+						this.loginUserInfo()
+					},
+					fail:(err)=> {
+						getApp().globalData.isAuth = false;
+						getApp().globalData.globalAuth = false; 
+						this.isAuth = false;
+					}
+				})
+				// if (e.detail.errMsg == "getUserInfo:ok") {
+				// 	getApp().globalData.user_headUrl = e.detail.userInfo.avatarUrl;
+				// 	getApp().globalData.user_name = e.detail.userInfo.nickName;
+				// 	this.iv = e.detail.iv;
+				// 	this.encryptedData = e.detail.encryptedData;
+				// 	console.log(e.detail)
+				// 	//this.loginUserInfo()
+				// } else {
+				// 	console.log("用户信息授权失败");
+				// 	getApp().globalData.isAuth = false;
+				// }
+			},
+			getPhoneNumber(e){
+				let that = this;
+				 if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
+				 console.log(e.detail)
+				  that.phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key)
+				} else { //
+				      that.isNeedPhone = false;
+				}
+			},
+			phoneRequest(myIv,myEncryptedData,sKey){
+				let that = this;
+				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=phone&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
+				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;
+							setTimeout(()=>{
+								that.refuseBtn();
+							},300)
+						}
+					},
+					fail: () => {
+						console.log("连接失败");
+					}
+				});
+			},
+			refuseBtn(){
+				uni.navigateBack({
+				});
+			},
+			loginUserInfo(){
+				let md5Sign = md5(
+				  "method=" +
+					"user" +
+					"&timestamp=" +
+					getApp().globalData.globalTimestamp +
+					"&secret=" +
+					getApp().globalData.secret
+				);
+				let url =
+				  getApp().globalData.shareUrl +
+				  "api/api.php" +
+				  "?method=user&action=update&timestamp=" +
+				  getApp().globalData.globalTimestamp +
+				  "&sign=" +
+				  md5Sign;
+				uni.request({
+				  url: url,
+				  method: "POST",
+				  header: {
+					"content-type": "application/x-www-form-urlencoded",
+				  },
+				  data: {
+					nickname:getApp().globalData.user_name,
+					headimg:getApp().globalData.user_headUrl,
+					openid:getApp().globalData.open_id
+				  },
+				  success: (res) => {
+					if (res.data.code === 200) {
+					}
+				  },
+				  fail: () => {
+					console.log("连接失败");
+				  },
+				});
+			},
+		}
+	}
+</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>

+ 29 - 54
pages/index/index.vue

@@ -7,7 +7,7 @@
       </div>
       <view class="img-name-box" v-if="!isAuth">
 		<image src="/static/auth-icon.png" class="heade-img" mode="aspectFill"></image>
-        <button @click="getAuth()" class="auth-btn">授权登录</button>
+        <button @click="goAuthPage()" class="auth-btn">授权登录</button>
       </view>
       <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image>
     </div>
@@ -52,7 +52,7 @@ export default {
 		 {
 		   icon: "/static/scan.png", 
 		   name: "扫一扫" ,
-		   url: "/pages/index/scanCode/index",
+		   // url: "/pages/index/scanCode/index",
 		   isShow:true,
 		  },
       ],
@@ -68,6 +68,11 @@ export default {
   onShow() {
   },
   methods: {
+	goAuthPage() {
+		uni.navigateTo({
+		  url: "./auth/index",
+		});
+	},
 	goUpload(){
 		let that = this;
 		if(!that.isAuth){
@@ -82,7 +87,6 @@ export default {
 				url: "/pages/index/upload/upload",
 			})
 		}
-	
 	},
 	getUserInfo() {
 	    let md5Sign = md5(
@@ -117,8 +121,9 @@ export default {
 				  this.userNickName = res.data.data.nickname;
 				  getApp().globalData.user_department = res.data.data.department;
 				  getApp().globalData.user_real_name = res.data.data.real_name;
-				} else {
+				}else {
 				  this.isAuth = false;
+				  getApp().globalData.globalAuth  = false;
 				}
 	        }
 	      },
@@ -128,58 +133,28 @@ export default {
 	    });
 	  },
 	uploadUserInfo(name,head){
-		let md5Sign = md5(
-		  "method=" +
-		    "user" +
-		    "&timestamp=" +
-		    getApp().globalData.globalTimestamp +
-		    "&secret=" +
-		    getApp().globalData.secret
-		);
-		let url =
-		  getApp().globalData.shareUrl +
-		  "api/api.php" +
-		  "?method=user&action=update&timestamp=" +
-		  getApp().globalData.globalTimestamp +
-		  "&sign=" +
-		  md5Sign;
-		uni.request({
-		  url: url,
-		  method: "POST",
-		  header: {
-		    "content-type": "application/x-www-form-urlencoded",
-		  },
-		  data: {
-			nickname:name,
-			headimg:head,
-			openid:getApp().globalData.open_id
-		  },
-		  success: (res) => {
-		    if (res.data.code === 200) {
-		    }
-		  },
-		  fail: () => {
-		    console.log("连接失败");
-		  },
-		});
+
 	},
 	getAuth() {
-		uni.getUserProfile({
-			desc:'登录',
-			success:(res)=> {
-				this.userHeadImg = res.userInfo.avatarUrl;
-				this.userNickName = res.userInfo.nickName;
-				this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
-				this.isAuth = true;
-				getApp().globalData.isAuth = true; 
-			},
-			fail:(err)=> {
-				console.log(err)
-				getApp().globalData.isAuth = false;
-				getApp().globalData.globalAuth = false; 
-				this.isAuth = false;
-			}
-		})
+		// uni.getUserProfile({
+		// 	desc:'登录',
+		// 	success:(res)=> {
+		// 		this.userHeadImg = res.userInfo.avatarUrl;
+		// 		this.userNickName = res.userInfo.nickName;
+		// 		this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
+		// 		this.isAuth = true;
+		// 		getApp().globalData.isAuth = true; 
+		// 	},
+		// 	fail:(err)=> {
+		// 		console.log(err)
+		// 		getApp().globalData.isAuth = false;
+		// 		getApp().globalData.globalAuth = false; 
+		// 		this.isAuth = false;
+		// 	}
+		// })
+	},
+	getUserPhone(){
+		
 	},
     codeReg(strs){
 			let reg = /\[(.*?)\]/gi;

+ 0 - 190
pages/index/scanCode/index.vue

@@ -1,190 +0,0 @@
-<template>
-  <view class="content">
-    <view class="details" v-for="item in pageList" :key="item.id">
-		<view class="view">
-		  <!-- <span class="label">发布时间:</span> -->
-		  <span style="width: 80%;color: darkgray;">{{ item.addtime }}</span>
-		</view>
-      <view class="view">
-        <!-- <span class="label">详情:</span> -->
-        <span>{{ item.content }}</span>
-      </view>
-      <view class="view">
-        <!-- <span class="label">图片:</span> -->
-        <view class="flex-box">
-          <view v-if="item.attach_list.length == 0">-</view>
-          <image :src="globalUrl + item1" v-for="(item1,index) in item.attach_list" :key="index" mode="aspectFit" @click="showlarge(item.attach_list,index)"/>
-        </view>
-      </view>
-    </view>
-  </view>
-</template>
-
-
-<script>
-import md5 from "@/common/md5.js";
-export default {
-  data() {
-    return {
-      id: "",
-      details: "",
-      imageList: [],
-      time: "",
-	  globalUrl:getApp().globalData.shareUrl,
-	  pageList:[
-		  // {
-			 //  id:'1',
-			 //  content:'从现在起直到21世纪中叶的30年,将有可能成为“人类命运共同体”在世界范围逐步实现的关键阶段。随着“人类命运共同体”在世界范围逐步成为现实,大国关系包含中美关系经过种种曲折,逐步转化到一个相互尊重、平等相待、和平共处、合作共赢的轨道上来,这才是人心所向',
-			 //  imgList:[],
-			 //  publishTime:'2021.12.25 14:15:00'
-		  // },
-		  // {
-			 //   id:'2',
-			 //  content:'从现在起直到21世纪中叶的30年,将有可能成为“人类命运共同体”在世界范围逐步实现的关键阶段。随着“人类命运共同体”在世界范围逐步成为现实,大国关系包含中美关系经过种种曲折,逐步转化到一个相互尊重、平等相待、和平共处、合作共赢的轨道上来,这才是人心所向',
-			 //  imgList:[],
-			 //  publishTime:'2021.12.26 12:11:00'
-		  // },
-		  // {
-			 //  id:'3',
-			 //  content:'从现在起直到21世纪中叶的30年,将有可能成为“人类命运共同体”在世界范围逐步实现的关键阶段。随着“人类命运共同体”在世界范围逐步成为现实,大国关系包含中美关系经过种种曲折,逐步转化到一个相互尊重、平等相待、和平共处、合作共赢的轨道上来,这才是人心所向',
-			 //  imgList:[],
-			 //  publishTime:'2021.12.27 13:35:00'
-		  // },
-	  ]
-    };
-  },
-  onLoad() {
-    this.getRecordList();
-  },
-  methods: {
-	showlarge(list,index){
-		//src = this.globalUrl + src
-	   let photoList = list.map((item)=>{
-			return getApp().globalData.shareUrl + item
-		})
-		console.log(photoList)
-		uni.previewImage({
-		  current:index,
-		  urls: photoList,
-		  longPressActions: {
-		    itemList: ["发送给朋友", "保存图片"],
-		    success: function (data) {},
-		    fail: function (err) {
-		      console.log(err.errMsg);
-		    },
-		  },
-		});
-	},
-	filterData(list){
-		list.forEach((item)=>{
-			 let time = this.$options.filters["globalTime"](item.addtime);
-			 let timeSecond = this.$options.filters["globalTimeSecond"](item.addtime);
-			 item.addtime = time + " " + timeSecond;
-		})
-	},
-    getRecordList() {
-      let md5Sign = md5(
-        "method=" +
-          "activity" +
-          "&timestamp=" +
-          getApp().globalData.globalTimestamp +
-          "&secret=" +
-          getApp().globalData.secret
-      );
-      let url =
-        getApp().globalData.shareUrl +
-        "api/api.php" +
-        "?method=activity&action=my_process&timestamp=" +
-        getApp().globalData.globalTimestamp +
-        "&sign=" +
-        md5Sign;
-      let postData = {
-        // id: this.id,
-         openid : getApp().globalData.open_id,
-      };
-      //获取文章
-      uni.request({
-        url: url,
-        method: "POST",
-        header: {
-          "content-type": "application/x-www-form-urlencoded",
-        },
-        data: postData,
-        success: (res) => {
-          console.log(res.data.data);
-          if (res.data.code === 200) {
-			this.pageList = res.data.data.list;
-			this.filterData(this.pageList)
-          }
-        },
-        fail: () => {
-          console.log("连接失败");
-        },
-      });
-    },
-  },
-};
-</script>
-<style lang="scss" scoped>
-.flex-box {
-  display: flex;
-  flex-wrap: wrap;
-  width: 100%;
-}
-.view {
-  display: flex;
-}
-.content {
-  font-size: 32rpx;
-  .title {
-    margin: 4% 5%;
-  }
-  .details {
-    font-size: 28rpx;
-    width: 90%;
-    margin: 0 2%;
-    padding: 2% 3%;
-	border-bottom: 3px solid #f2f2f2;
-    // border-radius: 50rpx;
-    // box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 14rpx;
-    image {
-      width: 180rpx;
-      height: 150rpx;
-      border-radius: 30rpx;
-      margin: 0 2%;
-    }
-    .view {
-      margin: 3% 0;
-    }
-    .label {
-      display: inline-block;
-      width:150rpx;
-      vertical-align: middle;
-      margin-right: 10rpx;
-    }
-  }
-  .info {
-    font-size: 28rpx;
-    width: 90%;
-    margin: 4% 2%;
-    padding: 2% 3%;
-    border-radius: 40rpx;
-    box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 14rpx;
-    .title {
-      margin: 4% 0;
-      font-size: 32rpx;
-    }
-    .view {
-      display: flex;
-      align-items: center;
-      margin: 5% 0;
-    }
-    .label {
-      display: inline-block;
-      width: 150rpx;
-      vertical-align: middle;
-      margin-right: 10rpx;
-    }
-  }
-}
-</style>