customPage.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. bodyBgImage: {
  20. type: String,
  21. value: ''
  22. }
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. bodyImageHeight: 0
  29. },
  30. attached: function() {
  31. let dwObj = wx.getMenuButtonBoundingClientRect()
  32. let navHeight_ = (dwObj.top + dwObj.height)
  33. let capsuleTop_ = dwObj.top
  34. const systemInfoSync = wx.getSystemInfoSync()
  35. const windowHeight = systemInfoSync.windowHeight
  36. const windowWidth = systemInfoSync.windowWidth;
  37. navHeight_ += capsuleTop_ / 8;
  38. let headStyle = "height:" + navHeight_ + "px;";
  39. if (this.data.headBgColor) {
  40. headStyle += "background-color:" + this.data.headBgColor +";"
  41. }
  42. this.setData({
  43. navHeight: navHeight_,
  44. capsuleTop:capsuleTop_,
  45. capHeight: dwObj.height,
  46. bodyHeight: windowHeight - navHeight_,
  47. windowWidth,
  48. windowHeight,
  49. headStyle,
  50. });
  51. },
  52. /**
  53. * 组件的方法列表
  54. */
  55. methods: {
  56. headImageLoadSuccess(e) {
  57. if (isEmpty(this.data.bodyBgImage)) {
  58. let { detail: {width, height} } = e
  59. let wB = this.data.windowWidth / width
  60. this.setData({
  61. bodyImageHeight: height * wB - this.data.navHeight
  62. })
  63. this.notifyParentView()
  64. }
  65. },
  66. bodyImageLoadSuccess(e) {
  67. let { detail: {width, height} } = e
  68. let wB = this.data.windowWidth / width
  69. this.setData({
  70. bodyImageHeight: height * wB
  71. })
  72. this.notifyParentView()
  73. },
  74. handleReachBottom(e) {
  75. this.triggerEvent("reachbottom", e)
  76. },
  77. notifyParentView() {
  78. this.triggerEvent("sizes", {
  79. headHeight: this.data.navHeight,
  80. bodyImageHeight: this.data.bodyImageHeight,
  81. windowWidth: this.data.windowWidth,
  82. windowHeight: this.data.windowHeight,
  83. capsuleTop: this.data.capsuleTop,
  84. capHeight: this.data.capHeight,
  85. bodyHeight: this.data.bodyHeight,
  86. })
  87. }
  88. }
  89. })