index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: false, name: '首页', leftArrow: false, useBar: false },
  8. // 主体高度
  9. infoHeight: '',
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. // 监听用户是否登录
  16. this.watchLogin();
  17. // 计算高度
  18. this.searchHeight();
  19. },
  20. // 监听用户是否登录
  21. watchLogin: function () {
  22. wx.getStorage({
  23. key: 'token',
  24. success: res => {
  25. if (res.data) wx.redirectTo({ url: '/pages/home/index', })
  26. },
  27. fail: res => {
  28. wx.redirectTo({ url: '/pages/login/index', })
  29. }
  30. })
  31. },
  32. // 计算高度
  33. searchHeight: function () {
  34. let frameStyle = this.data.frameStyle;
  35. let client = app.globalData.client;
  36. let infoHeight = client.windowHeight;
  37. // 是否去掉状态栏
  38. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  39. // 是否减去底部菜单
  40. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  41. if (infoHeight) this.setData({ infoHeight: infoHeight })
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh: function () {
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage: function () {
  77. }
  78. })