index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. getHeight
  3. } from "../../utils/GetRheRemainingHeight";
  4. Component({
  5. properties: {
  6. height: {
  7. type: Number
  8. }, //组件高度
  9. getlist: {
  10. type: Function
  11. },
  12. pullDown: { //是否开启下拉
  13. type: Boolean,
  14. value: true
  15. },
  16. safety: { //适配苹果底部安全距离
  17. type: Boolean,
  18. value: true
  19. },
  20. automatic: { //自动设置高度
  21. type: Boolean,
  22. value: true
  23. },
  24. scrollX: {
  25. type: Boolean,
  26. value: false
  27. },
  28. direction: {
  29. type: Array,
  30. value: ["bottom"]
  31. }
  32. },
  33. lifetimes: {
  34. attached: function () {
  35. if (this.data.automatic) this.automaticSetHei()
  36. },
  37. },
  38. data: {
  39. inRefresh: false, //下拉开启自定义项
  40. },
  41. methods: {
  42. /* 下拉刷新 */
  43. pullToRefresh() {
  44. this.setData({
  45. inRefresh: true
  46. })
  47. this.triggerEvent("getlist", true)
  48. },
  49. /* 刷新完成 */
  50. RefreshToComplete() {
  51. setTimeout(() => {
  52. this.setData({
  53. inRefresh: false
  54. })
  55. }, 500)
  56. },
  57. /* 加载分页 */
  58. loadThePage(e) {
  59. if (this.data.direction.includes(e.detail.direction)) this.triggerEvent("getlist", false)
  60. },
  61. automaticSetHei(mode, num) {
  62. this.setHeight("#mylisttop", this, mode, num)
  63. },
  64. /* 设置组件高度 */
  65. setHeight(element, that, mode, num) {
  66. return new Promise((resolve) => {
  67. getHeight(element, that).then(res => {
  68. let height = res;
  69. switch (mode) {
  70. case 'add':
  71. height = (res - 0) + (num - 0);
  72. break;
  73. case 'minus':
  74. height = res - num;
  75. break;
  76. }
  77. this.setData({
  78. height
  79. })
  80. resolve(height)
  81. })
  82. });
  83. }
  84. }
  85. })