index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, 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. // 减去状态栏
  37. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  38. // 是否减去底部菜单
  39. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  40. if (infoHeight) this.setData({ infoHeight: infoHeight })
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload: function () {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. }
  77. })