graceReload.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="">
  3. <view class="grace-reload"
  4. :class="[reloadStatus == 0 ? 'gload-show' : '', reloadStatus == 2 ? 'gload-hide' : '']"
  5. :style="{background:reloadBgColor[reloadStatus], height:height+'rpx', width:width, marginLeft:marginLeft}">
  6. <text class="grace-reload-icon icon-pulldown" v-if="reloadStatus == 0" :style="{color:reloadColor[reloadStatus]}"></text>
  7. <text class="grace-reload-icon icon-loading grace-rotate360" v-if="reloadStatus == 1" :style="{color:reloadColor[reloadStatus]}"></text>
  8. <text class="grace-reload-icon icon-ok" v-if="reloadStatus == 2" :style="{color:reloadColor[reloadStatus]}"></text>
  9. <text class="grace-reload-text" :style="{color:reloadColor[reloadStatus]}">{{reloadTxt[reloadStatus]}}</text>
  10. </view>
  11. <!-- view class="grace-reload-shade" @tap.stop="" @touchstart.stop="" @touchmove.stop.prevent="" v-if="reloadStatus != 5"></view -->
  12. </view>
  13. </template>
  14. <script>
  15. export default{
  16. props:{
  17. reloadTxt : {
  18. type : Array,
  19. default : function(){
  20. return ['松开手指开始刷新', '数据刷新中', '数据已经刷新']
  21. }
  22. },
  23. reloadBgColor : {
  24. type : Array,
  25. default : function(){
  26. return ['', '', '#63D2BC']
  27. }
  28. },
  29. reloadColor : {
  30. type : Array,
  31. default : function(){
  32. return ['#999999', '#63D2BC', '#FFFFFF']
  33. }
  34. },
  35. width : {
  36. type : String,
  37. default:'750rpx'
  38. },
  39. marginLeft : {
  40. type : String,
  41. default:'0rpx'
  42. }
  43. },
  44. data() {
  45. return {
  46. reloadStatus : 5,
  47. height : 0,
  48. startY : 0,
  49. startTime : 0
  50. }
  51. },
  52. methods:{
  53. /*
  54. 刷新状态 :
  55. 5 无状态可以 进行下拉
  56. 0 继续下拉刷新
  57. 1 刷新中
  58. 2 刷新结束
  59. 3 不确认状态但下拉动作已经在执行
  60. */
  61. touchstart:function (e) {
  62. // 如果滚动条位置不在最顶部禁止刷新
  63. if(e.scrollTop > 0){return ;}
  64. if(this.reloadStatus != 5){return ;}
  65. // 开始准备下拉
  66. this.reloadStatus = 3;
  67. this.startY = e.moveY;
  68. this.startTime = new Date().getTime();
  69. },
  70. touchmove:function (e) {
  71. if(this.reloadStatus == 3){
  72. // 检查时间是否够长
  73. var timer = new Date().getTime() - this.startTime;
  74. if(timer < 200){return ;}
  75. var moveY = e.moveY - this.startY;
  76. if(moveY > 100){
  77. this.reloadStatus = 0;
  78. this.height = 100;
  79. }
  80. }
  81. },
  82. touchend:function (e) {
  83. switch(this.reloadStatus){
  84. case 0 :
  85. this.reloadStatus = 1; this.$emit('reload');
  86. break;
  87. case 1 :
  88. break;
  89. case 2 :
  90. break;
  91. case 3 :
  92. this.reloadStatus = 5;
  93. break;
  94. }
  95. },
  96. endReload : function(){
  97. this.reloadStatus = 2;
  98. setTimeout(()=>{
  99. this.height = 0;
  100. this.reloadStatus = 5;
  101. },1000);
  102. },
  103. stopReload : function () {
  104. this.height = 0;
  105. this.reloadStatus = 5;
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. .grace-reload{width:100%; height:0px; overflow:hidden; display:flex; flex-direction:row; justify-content:center; align-items:center;}
  112. .grace-reload-icon{width:50rpx; height:50rpx; text-align:center; line-height:50rpx; display:block; font-family:"grace-iconfont"; font-size:44rpx;}
  113. .icon-pulldown:before{content:"\e633";}
  114. .icon-loading:before{content:"\e9db";}
  115. .icon-ok:before{content:"\e7f8";}
  116. .grace-reload-text{margin-left:16rpx; line-height:50rpx; font-size:26rpx;}
  117. @keyframes gload-show{0%{opacity:0; height:0;} 100%{opacity:1; height:100rpx;}}
  118. .gload-show{animation:gload-show 300ms linear;}
  119. @keyframes gload-hide{0%{opacity:1; height:100rpx;} 65%{opacity:1; height:100rpx;} 100%{opacity:0; height:0rpx;}}
  120. .gload-hide{animation:gload-hide 1000ms linear;}
  121. @keyframes grace-rotate360{0%{transform:rotate(0deg);} 50%{transform:rotate(180deg);} 100%{transform:rotate(360deg);}}
  122. .grace-rotate360{animation:grace-rotate360 1200ms infinite linear;}
  123. .grace-reload-shade{position:fixed; width:100%; height:100%; left:0; top:0; bottom:0; z-index:9999; background:rgba(255, 255, 255, 0); display:flex; justify-content:center; align-items:center;}
  124. </style>