<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) {
          var url = 'https://jiasm.zfire.top/recycleh5/pages/login/indexs';
          const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaddd13c267e81e70&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=wxaddd13c267e81e70&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>
