userInfo.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view class="">
  3. <view class="top-img">
  4. <view class="logo-img">
  5. <!-- <image src="" mode=""></image> -->
  6. </view>
  7. </view>
  8. <button open-type="getUserInfo" class="authorize" @click="shouquan">授权登陆</button>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. }
  16. },
  17. onLoad() {
  18. },
  19. methods: {
  20. shouquan: function(e) {
  21. wx.getUserInfo({
  22. success: function(res) {
  23. console.log("调用成功")
  24. // var userInfo = res.userInfo
  25. getApp().globalData.nickName =res.userInfo.nickName
  26. getApp().globalData.avatarUrl =res.userInfo.avatarUrl
  27. getApp().globalData.gender = res.userInfo.gender //性别 0:未知、1:男、2:女
  28. getApp().globalData.province = res.userInfo.province
  29. getApp().globalData.city = res.userInfo.city
  30. getApp().globalData.country = res.userInfo.country
  31. console.log(res, "这是用户信息")
  32. wx.switchTab({
  33. url: '../index/index',
  34. })
  35. },
  36. fail: function(err) {
  37. console.log("授权失败", err)
  38. }
  39. })
  40. }
  41. }
  42. }
  43. </script>
  44. <style>
  45. .top-img {
  46. height: 300rpx;
  47. background-color: #007AFF;
  48. padding-top: 15%;
  49. padding-bottom: 15%;
  50. }
  51. .logo-img {
  52. height: 300rpx;
  53. width: 300rpx;
  54. background-color: #55ff00;
  55. border-radius: 50%;
  56. align-items: center;
  57. justify-content: center;
  58. /* margin-top: 300rpx; */
  59. margin-left: 30%;
  60. }
  61. .authorize {
  62. margin-top: 100rpx;
  63. margin: 100rpx 20rpx 0 20rpx;
  64. }
  65. </style>