index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {
  2. getHeight
  3. } from "../../utils/getHeight";
  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. },
  25. lifetimes: {
  26. attached: function () {
  27. if (this.data.automatic) this.automaticSetHei()
  28. },
  29. },
  30. data: {
  31. inRefresh: false, //下拉开启自定义项
  32. },
  33. methods: {
  34. /* 下拉刷新 */
  35. pullToRefresh() {
  36. this.setData({
  37. inRefresh: true
  38. })
  39. this.triggerEvent("getlist", true)
  40. },
  41. /* 刷新完成 */
  42. RefreshToComplete() {
  43. setTimeout(() => {
  44. this.setData({
  45. inRefresh: false
  46. })
  47. }, 500)
  48. },
  49. /* 加载分页 */
  50. loadThePage() {
  51. this.triggerEvent("getlist", false)
  52. },
  53. automaticSetHei(mode, num) {
  54. this.setHeight("#mylisttop", this, mode, num)
  55. },
  56. /* 设置组件高度 */
  57. setHeight(element, that, mode, num) {
  58. return new Promise((resolve) => {
  59. getHeight(element, that).then(res => {
  60. let height = res;
  61. switch (mode) {
  62. case 'add':
  63. height = (res - 0) + (num - 0);
  64. break;
  65. case 'minus':
  66. height = res - num;
  67. break;
  68. }
  69. this.setData({
  70. height
  71. })
  72. resolve(height)
  73. })
  74. });
  75. }
  76. }
  77. })