user.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. wx.getUserInfo({
  45. success: function(res) {
  46. console.log(e.detail.userInfo);
  47. that.setData({
  48. login:true,
  49. avatarUrl:e.detail.userInfo.avatarUrl,
  50. nickName:e.detail.userInfo.nickName
  51. })
  52. }
  53. })
  54. },
  55. /**
  56. * 用户点击右上角分享
  57. */
  58. onShareAppMessage: function () {
  59. }
  60. })