index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // pages/login/login.js
  2. const app = getApp();
  3. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '消息', leftArrow: false, useBar: true },
  10. // 主体高度
  11. infoHeight: '',
  12. avatarUrl: defaultAvatarUrl,
  13. userInfo: {},
  14. routerList: []
  15. },
  16. // 获取头像
  17. onChooseAvatar(e) {
  18. const { avatarUrl } = e.detail;
  19. this.setData({ avatarUrl })
  20. },
  21. // 跳转页面
  22. tabPath: function (e) {
  23. const { detail } = e.detail;
  24. wx.navigateTo({ url: `/pages/${detail}/index` })
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. // 查询用户是否登录
  31. wx.getStorage({
  32. key: 'token',
  33. success: res => {
  34. if (res.data) {
  35. let userInfo = app.globalData.userInfo;
  36. if (userInfo) this.setData({ userInfo: userInfo });
  37. } else {
  38. wx.redirectTo({ url: '/pages/login/index', })
  39. }
  40. }
  41. })
  42. // 计算高度
  43. this.searchHeight();
  44. },
  45. // 计算高度
  46. searchHeight: function () {
  47. let frameStyle = this.data.frameStyle;
  48. let client = app.globalData.client;
  49. // 减去状态栏
  50. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  51. // 是否减去底部菜单
  52. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  53. if (infoHeight) this.setData({ infoHeight: infoHeight })
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function () {
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. }
  90. })