graceReload.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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="" 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. touchstart:function (e) {
  54. this.startY = e.moveY;
  55. this.startTime = new Date().getTime();
  56. },
  57. touchmove:function (e) {
  58. if(this.scrollTop > 0){return ;}
  59. if(this.height > 0){return;}
  60. // 检查时间
  61. var timer = new Date().getTime() - this.startTime;
  62. if(timer < 100){return ;}
  63. var moveY = e.moveY - this.startY;
  64. if(moveY > 100){this.reloadStatus = 0; this.height = 100;}
  65. },
  66. touchend:function (e) {
  67. if(this.height > 80){
  68. this.reloadStatus = 1;
  69. this.$emit('reload');
  70. }else{
  71. this.reloadStatus = 5;
  72. this.height = 0;
  73. }
  74. },
  75. endReload : function(){
  76. this.reloadStatus = 2;
  77. setTimeout(()=>{
  78. this.height = 0;
  79. this.reloadStatus = 5;
  80. },1000)
  81. },
  82. stopReload : function () {
  83. this.height = 0;
  84. this.reloadStatus = 5;
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. .grace-reload{width:100%; height:0px; overflow:hidden; display:flex; flex-direction:row; justify-content:center; align-items:center;}
  91. .grace-reload-icon{width:50rpx; height:50rpx; text-align:center; line-height:50rpx; display:block; font-family:"grace-iconfont"; font-size:44rpx;}
  92. .icon-pulldown:before{content:"\e633";}
  93. .icon-loading:before{content:"\e9db";}
  94. .icon-ok:before{content:"\e7f8";}
  95. .grace-reload-text{margin-left:16rpx; line-height:50rpx; font-size:26rpx;}
  96. @keyframes gload-show{0%{opacity:0; height:0;} 100%{opacity:1; height:100rpx;}}
  97. .gload-show{animation:gload-show 300ms linear;}
  98. @keyframes gload-hide{0%{opacity:1; height:100rpx;} 65%{opacity:1; height:100rpx;} 100%{opacity:0; height:0rpx;}}
  99. .gload-hide{animation:gload-hide 1000ms linear;}
  100. @keyframes grace-rotate360{0%{transform:rotate(0deg);} 50%{transform:rotate(180deg);} 100%{transform:rotate(360deg);}}
  101. .grace-rotate360{animation:grace-rotate360 1200ms infinite linear;}
  102. .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;}
  103. </style>