App.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <script>
  2. import Vue from 'vue';
  3. // 判断微信环境
  4. function isWeixin() {
  5. var ua = navigator.userAgent.toLowerCase();
  6. if (ua.indexOf('micromessenger') != -1) {
  7. return true;
  8. } else {
  9. return false;
  10. }
  11. }
  12. // 解析地址栏参数
  13. function getQueryVariable(variable) {
  14. // 从?开始获取后面的所有数据
  15. var query = window.location.search.substring(1);
  16. // 从字符串&开始分隔成数组split
  17. var vars = query.split('&');
  18. // 遍历该数组
  19. for (var i = 0; i < vars.length; i++) {
  20. // 从等号部分分割成字符
  21. var pair = vars[i].split('=');
  22. // 如果第一个元素等于 传进来的参的话 就输出第二个元素
  23. if (pair[0] == variable) {
  24. return pair[1];
  25. }
  26. }
  27. return undefined;
  28. }
  29. export default {
  30. onLaunch: function() {
  31. if(isWeixin()){
  32. // 微信鉴权登入
  33. var isAuthorization = getQueryVariable('isAuthorization');
  34. if (isAuthorization) {
  35. var url = 'https://jiasm.zfire.top/recycleh5/pages/login/indexs';
  36. const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaddd13c267e81e70&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
  37. window.location.href = href;
  38. } else {
  39. var code = getQueryVariable('code');
  40. if (code) {
  41. alert(code)
  42. uni.setStorageSync('code', code);
  43. } else if (!uni.getStorageSync('code')) {
  44. alert("重定向")
  45. const url = location.href;
  46. const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaddd13c267e81e70&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
  47. window.location.href = href;
  48. }
  49. }
  50. }
  51. },
  52. onShow: function() {
  53. // console.log('App Show')
  54. },
  55. onHide: function() {
  56. // console.log('App Hide')
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. /*每个页面公共css */
  62. @import "uview-ui/index.scss";
  63. @import "styles/iconfont.css";
  64. </style>