user.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // pages/user/user.js
  2. const app = getApp()
  3. let userInfo = app.globalData.userInfo;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. },
  10. onLoad: function (options) {
  11. var that = this;
  12. //获得设备信息
  13. wx.getSystemInfo({
  14. success (res) {
  15. console.log(res.windowHeight);
  16. that.setData({
  17. phoneHeight: res.windowHeight,
  18. })
  19. }
  20. })
  21. // 查看是否授权
  22. if (app.globalData.userInfo === null) {
  23. that.setData({
  24. login: true
  25. })
  26. } else {
  27. that.setData({
  28. login: false,
  29. avatarUrl: app.globalData.userInfo.avatarUrl,
  30. nickName: app.globalData.userInfo.nickName
  31. })
  32. }
  33. },
  34. // 获取用户的头像和昵称信息
  35. bindGetUserInfo(e) {
  36. var that = this;
  37. wx.getUserInfo({
  38. success: function(res) {
  39. console.log(e.detail.userInfo);
  40. app.globalData.userInfo = e.detail.userInfo;
  41. that.setData({
  42. login: false,
  43. avatarUrl: e.detail.userInfo.avatarUrl,
  44. nickName: e.detail.userInfo.nickName
  45. })
  46. }
  47. })
  48. },
  49. phoneLogin:function(){
  50. wx.navigateTo({
  51. url: './phoneLogin/phoneLogin',
  52. });
  53. },
  54. gotoLogin(){
  55. wx.navigateTo({
  56. url: './phoneLogin/phoneLogin',
  57. });
  58. },
  59. openSwitch:function(){
  60. var that = this;
  61. that.setData({
  62. show:true
  63. })
  64. },
  65. close:function(){
  66. var that = this;
  67. that.setData({
  68. show:false
  69. })
  70. }
  71. })