1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <script>
- import Vue from 'vue';
- // 判断微信环境
- function isWeixin() {
- var ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf('micromessenger') != -1) {
- return true;
- } else {
- return false;
- }
- }
- // 解析地址栏参数
- function getQueryVariable(variable) {
- // 从?开始获取后面的所有数据
- var query = window.location.search.substring(1);
- // 从字符串&开始分隔成数组split
- var vars = query.split('&');
- // 遍历该数组
- for (var i = 0; i < vars.length; i++) {
- // 从等号部分分割成字符
- var pair = vars[i].split('=');
- // 如果第一个元素等于 传进来的参的话 就输出第二个元素
- if (pair[0] == variable) {
- return pair[1];
- }
- }
- return undefined;
- }
- export default {
- onLaunch: function() {
- if(isWeixin()){
- // 微信鉴权登入
- var isAuthorization = getQueryVariable('isAuthorization');
- if (isAuthorization) {
- alert(1)
- var url = 'https://jiasm.zfire.top/recycleh5/pages/login/indexs';
- const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd935838591c00e16&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
- window.location.href = href;
- } else {
- var code = getQueryVariable('code');
- if (code) {
- alert(code)
- uni.setStorageSync('code', code);
- } else if (!uni.getStorageSync('code')) {
- alert("重定向")
- const url = location.href;
- const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd935838591c00e16&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
- window.location.href = href;
- }
- }
- }
- },
- onShow: function() {
- // console.log('App Show')
- },
- onHide: function() {
- // console.log('App Hide')
- }
- }
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import "uview-ui/index.scss";
- @import "styles/iconfont.css";
- </style>
|