gui-refresh.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view
  3. class="gui-page-refresh gui-flex gui-column gui-justify-content-center"
  4. :style="{height:refreshHeight+'px'}">
  5. <view
  6. :style="{height:refreshFontSize+'rpx'}"
  7. class="gui-flex gui-row gui-justify-content-center gui-align-items-center">
  8. <text
  9. class="gui-icons gui-block"
  10. v-if="refreshStatus == 0 || refreshStatus == 1"
  11. :class="customClass[refreshStatus]"
  12. :style="{
  13. fontSize:refreshFontSize+'rpx',
  14. width:refreshFontSize+'rpx',
  15. height:refreshFontSize+'rpx',
  16. lineHeight:refreshFontSize+'rpx'
  17. }">&#xe66c;</text>
  18. <text
  19. ref="loadingIcon"
  20. v-if="refreshStatus == 2"
  21. class="gui-icons gui-block gui-text-center gui-rotate360"
  22. :class="customClass[refreshStatus]"
  23. :style="{
  24. fontSize:refreshFontSize+'rpx',
  25. width:refreshFontSize+'rpx',
  26. height:refreshFontSize+'rpx',
  27. lineHeight:refreshFontSize+'rpx'
  28. }">&#xe95a;</text>
  29. <text
  30. class="gui-icons"
  31. :class="customClass[refreshStatus]"
  32. v-if="refreshStatus == 3"
  33. :style="{
  34. fontSize:refreshFontSize+'rpx',
  35. width:refreshFontSize+'rpx',
  36. height:refreshFontSize+'rpx',
  37. lineHeight:refreshFontSize+'rpx'
  38. }">&#xe7f8;</text>
  39. <text
  40. style="margin-left:12rpx;"
  41. class="gui-page-refresh-text gui-block"
  42. :class="customClass[refreshStatus]"
  43. :style="{fontSize:refreshFontSize+'rpx'}">{{refreshText[refreshStatus]}}</text>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. // #ifdef APP-NVUE
  49. var animation = weex.requireModule('animation');
  50. const dom = weex.requireModule('dom');
  51. // #endif
  52. export default{
  53. name : "gui-refresh",
  54. props : {
  55. refreshText : {type:Array, default:function () {
  56. return ['继续下拉刷新','松开手指开始刷新','数据刷新中','数据已刷新'];
  57. }},
  58. customClass : {type:Array, default:function () {
  59. return [
  60. ['gui-color-gray'],
  61. ['gui-color-gray'],
  62. ['gui-primary-text'],
  63. ['gui-color-green'],
  64. ];
  65. }},
  66. refreshFontSize : {type:Number, default:28},
  67. triggerHeight : {type:Number, default:50}
  68. },
  69. data() {
  70. return {
  71. reScrollTop : 0,
  72. refreshHeight : 0,
  73. refreshY : 0,
  74. refreshStatus : 0,
  75. refreshTimer : 0
  76. }
  77. },
  78. methods:{
  79. touchstart : function (e){
  80. if(this.reScrollTop > 10){return ;}
  81. this.refreshY = e.changedTouches[0].pageY;
  82. },
  83. touchmove : function(e){
  84. if(this.refreshStatus >= 1){ return null;}
  85. if(this.reScrollTop > 10){return ;}
  86. var moveY = e.changedTouches[0].pageY - this.refreshY;
  87. moveY = moveY / 2;
  88. if(moveY >= this.triggerHeight){
  89. moveY = this.triggerHeight;
  90. this.refreshStatus = 1;
  91. }
  92. if(moveY > 15){this.refreshHeight = moveY;}
  93. },
  94. touchend : function (e) {
  95. if(this.reScrollTop > 10){return ;}
  96. if(this.refreshStatus < 1){
  97. return this.resetFresh();
  98. }else if(this.refreshStatus == 1){
  99. this.refreshStatus = 2;
  100. // #ifdef APP-NVUE
  101. setTimeout(()=>{
  102. this.rotate360();
  103. }, 200);
  104. // #endif
  105. this.$emit('reload');
  106. }
  107. },
  108. scroll:function(e){
  109. this.reScrollTop = e.detail.scrollTop;
  110. },
  111. endReload : function(){
  112. this.refreshStatus = 3;
  113. setTimeout(()=>{this.resetFresh()}, 1000);
  114. },
  115. resetFresh : function () {
  116. this.refreshHeight = 0;
  117. this.refreshStatus = 0;
  118. return null;
  119. },
  120. rotate360 : function(){
  121. var el = this.$refs.loadingIcon;
  122. animation.transition(el, {
  123. styles : {
  124. transform: 'rotate(7200deg)',
  125. transformOrigin :'center'
  126. },
  127. duration : 20000,
  128. timingFunction: 'linear',
  129. needLayout :false,
  130. delay: 0
  131. });
  132. }
  133. },
  134. emits : ['reload']
  135. }
  136. </script>
  137. <style scoped>
  138. .gui-page-refresh{overflow:hidden}
  139. .gui-page-refresh-text{line-height:38rpx;height:38rpx;}
  140. /* #ifndef APP-NVUE */
  141. @keyframes gload-hide{0%{opacity:1; height:50px;} 70%{opacity:1; height:50px;} 100%{opacity:0; height:0px;}}
  142. .gload-hide{animation:gload-hide 1s linear;}
  143. /* #endif */
  144. </style>