gui-refresh.vue 3.5 KB

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