wxLogin.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef MP -->
  4. <image class="bg-img" src="/static/img/img09.png" mode=" scaleToFill"></image>
  5. <view class="logo-img-box">
  6. <image class="logo-img" src="/static/img/img10.png" mode=" aspectFit"></image>
  7. <button class="userInfo" type="warn" open-type="getUserInfo" @getuserinfo="userInfoData">
  8. <text class="iconfont iconweixin"></text>
  9. <text>微信授权登录</text>
  10. </button>
  11. </view>
  12. <!-- #endif -->
  13. </view>
  14. </template>
  15. <script>
  16. // #ifdef H5
  17. import { loginWinxin } from '@/utils/wxAuthorized';
  18. // #endif
  19. // #ifdef MP-WEIXIN
  20. import { loginWinxinMp } from '@/utils/wxMinProgram';
  21. // #endif
  22. import { mapMutations } from 'vuex';
  23. export default {
  24. data() {
  25. return {
  26. userInfo: {}, //授权用户信息
  27. code: '' //授权code
  28. };
  29. },
  30. onLoad(option) {
  31. this.loadData();
  32. },
  33. methods: {
  34. loadData() {
  35. // #ifdef H5
  36. loginWinxin();
  37. // #endif
  38. // #ifdef MP-WEIXIN
  39. loginWinxinMp({}).then(e => {
  40. this.code = e.code;
  41. });
  42. // #endif
  43. },
  44. // 用户确认授权
  45. userInfoData(e) {
  46. console.log(e);
  47. this.userInfo = e;
  48. uni.navigateTo({
  49. url: '/pages/redirect/redirect?code=' + this.code
  50. });
  51. }
  52. }
  53. };
  54. </script>
  55. <style lang="scss">
  56. page,
  57. .content {
  58. height: 100%;
  59. }
  60. .bg-img,
  61. .logo-img-box {
  62. position: absolute;
  63. top: 0;
  64. left: 0;
  65. width: 100%;
  66. height: 100%;
  67. }
  68. .logo-img {
  69. margin-top: 20vh;
  70. margin-left: 176rpx;
  71. width: 385rpx;
  72. height: 394rpx;
  73. }
  74. .userInfo {
  75. margin: 0 100rpx;
  76. margin-top: 50rpx;
  77. color: #ffffff;
  78. border-radius: 99rpx;
  79. background-color: $base-color;
  80. }
  81. </style>