user.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // pages/user/user.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. /**
  9. * 生命周期函数--监听页面加载
  10. */
  11. onLoad: function (options) {
  12. var that = this;
  13. //获得设备信息
  14. wx.getSystemInfo({
  15. success (res) {
  16. console.log(res.windowHeight);
  17. that.setData({
  18. phoneHeight:res.windowHeight,
  19. })
  20. }
  21. })
  22. // 查看是否授权
  23. wx.getSetting({
  24. success(res) {
  25. if (res.authSetting['scope.userInfo']) {
  26. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  27. wx.getUserInfo({
  28. success: function (res) {
  29. console.log(res.userInfo);
  30. that.setData({
  31. login:true,
  32. avatarUrl:res.userInfo.avatarUrl,
  33. nickName:res.userInfo.nickName
  34. })
  35. }
  36. })
  37. }
  38. }
  39. })
  40. },
  41. // 获取用户的头像和昵称信息
  42. bindGetUserInfo(e) {
  43. var that = this;
  44. console.log(e.detail.userInfo)
  45. that.setData({
  46. login:true,
  47. avatarUrl:e.detail.userInfo.avatarUrl,
  48. nickName:e.detail.userInfo.nickName
  49. })
  50. },
  51. /**
  52. * 用户点击右上角分享
  53. */
  54. onShareAppMessage: function () {
  55. }
  56. })