graceReload.nvue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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="" 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. touchstart:function (e) {
  81. this.startY = e.moveY;
  82. this.startTime = new Date().getTime();
  83. },
  84. touchmove:function (e) {
  85. if(this.scrollTop > 0){return ;}
  86. if(this.height > 0){return;}
  87. // 检查时间
  88. var timer = new Date().getTime() - this.startTime;
  89. if(timer < 300){return ;}
  90. var moveY = e.moveY - this.startY;
  91. if(moveY > 100){this.reloadStatus = 0; this.height = 100;}
  92. },
  93. touchend:function (e) {
  94. if(this.height > 80){
  95. this.reloadStatus = 1;
  96. this.$emit('reload');
  97. }else{
  98. this.reloadStatus = 5;
  99. this.height = 0;
  100. }
  101. },
  102. endReload : function(){
  103. this.reloadStatus = 2;
  104. setTimeout(()=>{
  105. this.height = 0;
  106. this.reloadStatus = 5;
  107. },1000)
  108. },
  109. rotate360 : function(){
  110. this.el = this.$refs.loadingIcon;
  111. animation = weex.requireModule('animation');
  112. animation.transition(this.el, {
  113. styles: {transform: 'rotate(7200deg)'},
  114. duration: 20000,
  115. timingFunction: 'linear',
  116. needLayout:false,
  117. delay: 0
  118. }
  119. );
  120. },
  121. stopReload : function () {
  122. this.height = 0;
  123. this.reloadStatus = 5;
  124. }
  125. }
  126. }
  127. </script>
  128. <style scoped>
  129. .grace-reload{width:750rpx; height:0px; overflow:hidden; flex-direction:row; justify-content:center; align-items:center; opacity:0;}
  130. .grace-reload-icon{width:50rpx; height:50rpx; text-align:center; line-height:50rpx; font-size:44rpx;}
  131. .grace-reload-text{margin-left:16rpx; line-height:50rpx; font-size:26rpx;}
  132. .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;}
  133. </style>