customPage.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const { isEmpty } = require("../../utils/util")
  2. // components/customPage/customPage.js
  3. Component({
  4. options:{
  5. multipleSlots: true
  6. },
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. headBgImage: {
  12. type: String,
  13. value: ''
  14. },
  15. headBgColor: {
  16. type: String,
  17. value: ''
  18. }
  19. },
  20. /**
  21. * 组件的初始数据
  22. */
  23. data: {
  24. bodyImageHeight: 0
  25. },
  26. attached: function() {
  27. let dwObj = wx.getMenuButtonBoundingClientRect()
  28. let navHeight_ = (dwObj.top + dwObj.height)
  29. let capsuleTop_ = dwObj.top
  30. const systemInfoSync = wx.getSystemInfoSync()
  31. const windowHeight = systemInfoSync.windowHeight
  32. const windowWidth = systemInfoSync.windowWidth;
  33. navHeight_ += capsuleTop_ / 8;
  34. let headStyle = "height:" + navHeight_ + "px;";
  35. if (this.data.headBgColor) {
  36. headStyle += "background-color:" + this.data.headBgColor +";"
  37. }
  38. console.log(windowWidth, systemInfoSync)
  39. this.setData({
  40. navHeight: navHeight_,
  41. capsuleTop:capsuleTop_,
  42. capHeight: dwObj.height,
  43. bodyHeight: windowHeight - navHeight_,
  44. windowWidth,
  45. windowHeight,
  46. headStyle,
  47. });
  48. },
  49. /**
  50. * 组件的方法列表
  51. */
  52. methods: {
  53. loadImage(e) {
  54. let { detail: {width, height} } = e
  55. let wB = this.data.windowWidth / width
  56. this.setData({
  57. bodyImageHeight: height * wB - this.data.navHeight
  58. })
  59. },
  60. handleReachBottom(e) {
  61. this.triggerEvent("reachbottom", e)
  62. }
  63. }
  64. })