App.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. alert(1)
  36. var url = 'https://jiasm.zfire.top/recycleh5/pages/login/indexs';
  37. const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd935838591c00e16&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
  38. window.location.href = href;
  39. } else {
  40. var code = getQueryVariable('code');
  41. if (code) {
  42. alert(code)
  43. uni.setStorageSync('code', code);
  44. } else if (!uni.getStorageSync('code')) {
  45. alert("重定向")
  46. const url = location.href;
  47. const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd935838591c00e16&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo#wechat_redirect`;
  48. window.location.href = href;
  49. }
  50. }
  51. }
  52. },
  53. onShow: function() {
  54. // console.log('App Show')
  55. },
  56. onHide: function() {
  57. // console.log('App Hide')
  58. }
  59. }
  60. </script>
  61. <style lang="scss">
  62. /*每个页面公共css */
  63. @import "uview-ui/index.scss";
  64. @import "styles/iconfont.css";
  65. </style>