소스 검색

登录配置

梁汉强 4 년 전
부모
커밋
52d28a1673
7개의 변경된 파일85개의 추가작업 그리고 3개의 파일을 삭제
  1. 14 0
      common/conf/config.js
  2. 11 0
      common/utils/utils.js
  3. 5 0
      components/views/mine-view.vue
  4. 9 2
      manifest.json
  5. 9 0
      pages.json
  6. 12 1
      pages/home/home.vue
  7. 25 0
      pages/webView/webView.vue

+ 14 - 0
common/conf/config.js

@@ -0,0 +1,14 @@
+//公众号ID
+ const appId = 'wx7e7a38f071b360e9';
+ //公众号密钥
+ const appSecret = '4e862f91b48ac85a91380fa0991c9fda';
+//经过编码后的回调地址
+const redireactUrl = 'https://vote.guosen-fumao.cn/vote-h5/index.html#/pages/home/home';
+//获取用户授权信息Code
+ const authUrl =  `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${encodeURIComponent(redireactUrl)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
+ //获取用户的Access-token
+const atUrl =  (code)=>{ return `https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appId}&secret=${appSecret}&code=${code}&grant_type=authorization_code`}
+ //拉取用户信息
+ const	getWXUserInfoUrl = (ACCESS_TOKEN,OPENID) =>{ return `https://api.weixin.qq.com/sns/userinfo?access_token=${ACCESS_TOKEN}&openid=${OPENID}&lang=zh_CN`} 
+ 
+ export { appId , authUrl ,atUrl,getWXUserInfoUrl };

+ 11 - 0
common/utils/utils.js

@@ -0,0 +1,11 @@
+export const getUrlParams = (url) => {
+	let theRequest = new Object();
+	if (url.indexOf("?") != -1) {
+	let str = url.substr(1);
+	let strs = str.split("&");
+	for (let i = 0; i < strs.length; i++) {
+	    theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
+	    }
+	}
+	return theRequest;
+}

+ 5 - 0
components/views/mine-view.vue

@@ -4,6 +4,7 @@
 			<view class="flex justify-between align-center" style="height: 200upx;">
 				<view class="padding-left">
 					<view class="text-black text-bold text-xl">{{name}}</view>
+					<!-- <button @click="toAuth"> 授权</button>   获取用户授权 -->   
 					<view class="flex align-center padding-top-sm">
 						<view>
 							<view class="text-black text-bold">205</view>
@@ -65,6 +66,7 @@
 </template>
 
 <script>
+	import {authUrl } from '../../common/conf/config.js'
 	export default {
 		props: {
 
@@ -88,6 +90,9 @@
 			}
 		},
 		methods: {
+			toAuth(){
+				 window.location.href = authUrl;
+			},
 			//跳转需要带参数
 			edit() {
 				uni.navigateTo({

+ 9 - 2
manifest.json

@@ -65,7 +65,14 @@
     "mp-toutiao" : {
         "usingComponents" : true
     },
-    "uniStatistics": {  
-        "enable": false
+    "uniStatistics" : {
+        "enable" : false
+    },
+    "h5" : {
+        "title" : "SoundOfMusic-H5",
+        "domain" : "vote.guosen-fumao.cn",
+        "router" : {
+            "base" : "./"
+        }
     }
 }

+ 9 - 0
pages.json

@@ -145,6 +145,15 @@
             }
             
         }
+        ,{
+            "path" : "pages/webView/webView",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "",
+                "enablePullDownRefresh": false
+            }
+            
+        }
     ],
 	"globalStyle": {
 		"navigationStyle": "custom",

+ 12 - 1
pages/home/home.vue

@@ -4,7 +4,6 @@
 		<view v-if="current == 0">
 			<activity-view :imgList="imgList"></activity-view>
 		</view>
-		
 		<!--个人中心-->
 		<view v-if="current == 2">
 			<mine-view></mine-view>
@@ -17,11 +16,16 @@
 </template>
 
 <script>
+	import {getUrlParams} from '../../common/utils/utils.js';
+	import {atUrl,getWXUserInfoUrl } from '../../common/conf/config.js';
 	import searchBar from "@/components/basic/search-bar.vue";
 	import bottomBar from "@/components/basic/bottom-bar.vue";
 	import activityView from "@/components/views/activity-view.vue";
 	import mineView from "@/components/views/mine-view.vue";
 	export default {
+		async onLoad(options) {
+			await this.authorization();
+		},
 		components: {
 			searchBar,
 			bottomBar,
@@ -39,6 +43,13 @@
 			}
 		},
 		methods: {
+		 async authorization(){
+				let params =  getUrlParams(window.location.search);
+				if(typeof params.code != 'undefined'){
+					this.current = 2;
+					console.log(params);
+				}
+			},
 			change(index) {
 				this.current = index;
 			}

+ 25 - 0
pages/webView/webView.vue

@@ -0,0 +1,25 @@
+<template>
+	<view>
+		<web-view :src="src"></web-view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				src: ''
+			}
+		},
+		onLoad(options) {
+			this.src=options.src
+		},
+		methods: {
+			
+		}
+	}
+</script>
+
+<style>
+
+</style>