index.js 1.8 KB

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