graceReload.nvue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view>
  3. <view class="grace-reload" ref="guiReload" :style="{backgroundColor:reloadBgColor[reloadStatus], width:width, marginLeft:marginLeft}">
  4. <text class="grace-reload-icon grace-icons" v-if="reloadStatus == 0" :style="{color:reloadColor[reloadStatus]}">&#xe633;</text>
  5. <view ref="loadingIcon" v-if="reloadStatus == 1"><text class="grace-reload-icon grace-icons" :style="{color:reloadColor[reloadStatus]}">&#xe9db;</text></view>
  6. <text class="grace-reload-icon grace-icons" v-if="reloadStatus == 2" :style="{color:reloadColor[reloadStatus]}">&#xe7f8;</text>
  7. <text class="grace-reload-text" :style="{color:reloadColor[reloadStatus]}">{{reloadTxt[reloadStatus]}}</text>
  8. </view>
  9. <!-- view class="grace-reload-shade" @tap.stop="" @touchstart.stop="" @touchmove.stop.prevent="" v-if="reloadStatus != 5"></view -->
  10. </view>
  11. </template>
  12. <script>
  13. var animation = null;
  14. export default{
  15. props:{
  16. reloadTxt : {
  17. type : Array,
  18. default : function(){
  19. return ['松开手指开始刷新', '数据刷新中', '数据已经刷新']
  20. }
  21. },
  22. reloadBgColor : {
  23. type : Array,
  24. default : function(){
  25. return ['', '', '#63D2BC']
  26. }
  27. },
  28. reloadColor : {
  29. type : Array,
  30. default : function(){
  31. return ['#999999', '#63D2BC', '#FFFFFF']
  32. }
  33. },
  34. width : {
  35. type : String,
  36. default:'750rpx'
  37. },
  38. marginLeft : {
  39. type : String,
  40. default:'0rpx'
  41. }
  42. },
  43. data() {
  44. return {
  45. reloadStatus : 5,
  46. height : 0,
  47. startY : 0,
  48. startTime : 0,
  49. el:null
  50. }
  51. },
  52. watch:{
  53. reloadStatus : function (nval, oval) {
  54. if(nval == 1){
  55. setTimeout(()=>{this.rotate360();}, 300);
  56. }else if(nval == 0){
  57. var el = this.$refs.guiReload;
  58. animation = weex.requireModule('animation');
  59. animation.transition(el, {
  60. styles: {height:'50px', opacity:1},
  61. duration: 200,
  62. timingFunction: 'ease-in',
  63. needLayout:true,
  64. delay: 0
  65. });
  66. }else if(nval == 2){
  67. var el = this.$refs.guiReload;
  68. animation = weex.requireModule('animation');
  69. animation.transition(el, {
  70. styles: {height:'0', opacity:0},
  71. duration: 200,
  72. timingFunction: 'ease-in',
  73. needLayout:true,
  74. delay: 500
  75. });
  76. }
  77. }
  78. },
  79. methods:{
  80. /*
  81. 刷新状态 :
  82. 5 无状态可以 进行下拉
  83. 0 继续下拉刷新
  84. 1 刷新中
  85. 2 刷新结束
  86. 3 不确认状态但下拉动作已经在执行
  87. */
  88. touchstart:function (e) {
  89. // 如果滚动条位置不在最顶部禁止刷新
  90. if(e.scrollTop > 0){return ;}
  91. if(this.reloadStatus != 5){return ;}
  92. // 开始准备下拉
  93. this.reloadStatus = 3;
  94. this.startY = e.moveY;
  95. this.startTime = new Date().getTime();
  96. },
  97. touchmove:function (e) {
  98. if(this.reloadStatus == 3){
  99. // 检查时间是否够长
  100. var timer = new Date().getTime() - this.startTime;
  101. if(timer < 200){return ;}
  102. var moveY = e.moveY - this.startY;
  103. if(moveY > 100){
  104. this.reloadStatus = 0;
  105. this.height = 100;
  106. }
  107. }
  108. },
  109. touchend:function (e) {
  110. switch(this.reloadStatus){
  111. case 0 :
  112. this.reloadStatus = 1; this.$emit('reload');
  113. break;
  114. case 1 :
  115. break;
  116. case 2 :
  117. break;
  118. case 3 :
  119. this.reloadStatus = 5;
  120. break;
  121. }
  122. },
  123. endReload : function(){
  124. this.reloadStatus = 2;
  125. setTimeout(()=>{
  126. this.height = 0;
  127. this.reloadStatus = 5;
  128. },1000)
  129. },
  130. rotate360 : function(){
  131. this.el = this.$refs.loadingIcon;
  132. animation = weex.requireModule('animation');
  133. animation.transition(this.el, {
  134. styles: {transform: 'rotate(7200deg)'},
  135. duration: 20000,
  136. timingFunction: 'linear',
  137. needLayout:false,
  138. delay: 0
  139. }
  140. );
  141. },
  142. stopReload : function () {
  143. this.height = 0;
  144. this.reloadStatus = 5;
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. .grace-reload{width:750rpx; height:0px; overflow:hidden; flex-direction:row; justify-content:center; align-items:center; opacity:0;}
  151. .grace-reload-icon{width:50rpx; height:50rpx; text-align:center; line-height:50rpx; font-size:44rpx;}
  152. .grace-reload-text{margin-left:16rpx; line-height:50rpx; font-size:26rpx;}
  153. .grace-reload-shade{position:fixed; width:750rpx; flex:1; left:0; top:0; bottom:0; background-color:rgba(255, 255, 255, 0); justify-content:center; align-items:center;}
  154. </style>