sss.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <list :id="parentListId" class="page" :bounce="false" isSwiperList="true">
  3. <refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown"
  4. :display="refreshing ? 'show' : 'hide'">
  5. <div class="refresh-view">
  6. <text class="loading-text">{{refreshText}}</text>
  7. </div>
  8. </refresh>
  9. <cell>
  10. <view id="head" class="header">
  11. <text class="header-title">header</text>
  12. </view>
  13. </cell>
  14. <cell>
  15. <view class="main-content" :style="'height:' + pageHeight + 'px'">
  16. <view class="sticky-view">
  17. <text class="sticky-title">Sticky view</text>
  18. </view>
  19. <list ref="sublist" class="list" :offset-accuracy="5" :bounce="false" isSwiperList="true">
  20. <cell v-for="(item, index) in dataList" :key="item.id" :ref="'item'+index" @click="onclick">
  21. <view class="list-item">
  22. <text>{{item.name}}</text>
  23. </view>
  24. </cell>
  25. </list>
  26. </view>
  27. </cell>
  28. </list>
  29. </template>
  30. <script>
  31. // #ifdef APP-PLUS
  32. const dom = weex.requireModule('dom');
  33. // #endif
  34. export default {
  35. data() {
  36. return {
  37. parentListId: "parentListId",
  38. pageHeight: 300,
  39. dataList: [],
  40. refreshing: false,
  41. refreshText: "",
  42. refreshFlag: false
  43. }
  44. },
  45. created() {
  46. for (var i = 1; i <= 32; i++) {
  47. this.dataList.push({
  48. id: i,
  49. name: i
  50. });
  51. }
  52. },
  53. onReady() {
  54. this.pageHeight = uni.getSystemInfoSync().windowHeight;
  55. uni.createSelectorQuery().in(this).select('#head').boundingClientRect().exec(rect => {
  56. this.$refs.sublist.setSpecialEffects({
  57. id: this.parentListId,
  58. headerHeight: rect[0].height
  59. });
  60. });
  61. },
  62. methods: {
  63. onrefresh(e) {
  64. this.refreshing = true;
  65. this.refreshText = "刷新中...";
  66. setTimeout(() => {
  67. this.refreshing = false;
  68. this.refreshFlag = false;
  69. this.refreshText = "已刷新";
  70. }, 2000)
  71. },
  72. onpullingdown(e) {
  73. if (this.refreshing) {
  74. return;
  75. }
  76. this.pulling = false;
  77. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  78. this.refreshFlag = true;
  79. this.refreshText = "释放立即刷新";
  80. } else {
  81. this.refreshFlag = false;
  82. this.refreshText = "下拉可以刷新";
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style>
  89. /* #ifndef APP-PLUS */
  90. page {
  91. width: 100%;
  92. min-height: 100%;
  93. display: flex;
  94. }
  95. /* #endif */
  96. .page {
  97. flex: 1;
  98. }
  99. .refresh-view {
  100. width: 750rpx;
  101. height: 80px;
  102. flex-direction: row;
  103. align-items: center;
  104. justify-content: center;
  105. }
  106. .header {
  107. height: 160px;
  108. flex-direction: row;
  109. align-items: center;
  110. justify-content: center;
  111. background-color: #f4f4f4;
  112. }
  113. .header-title {
  114. font-size: 30px;
  115. font-weight: bold;
  116. color: #444;
  117. }
  118. .sticky-view {
  119. margin-left: 12px;
  120. margin-right: 12px;
  121. padding: 20px;
  122. background-color: #EBEBEB;
  123. border-radius: 5px;
  124. }
  125. .list {
  126. flex: 1;
  127. }
  128. .list-item {
  129. margin-left: 12px;
  130. margin-right: 12px;
  131. margin-top: 12px;
  132. padding: 20px;
  133. background-color: #fff;
  134. border-radius: 5px;
  135. }
  136. </style>