gui-page-loading.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view
  3. class="gui-page-loading gui-flex gui-nowrap gui-align-items-center gui-justify-content-center gui-page-loading-bg"
  4. @tap.stop="stopfun"
  5. @touchmove.stop.prevent="stopfun"
  6. v-if="isLoading">
  7. <!-- #ifndef APP-NVUE -->
  8. <view class="gui-page-loading-point gui-flex gui-rows gui-justify-content-center">
  9. <view class="gui-page-loading-points animate1 gui-page-loading-color"></view>
  10. <view class="gui-page-loading-points animate2 gui-page-loading-color"></view>
  11. <view class="gui-page-loading-points animate3 gui-page-loading-color"></view>
  12. </view>
  13. <!-- #endif -->
  14. <!-- #ifdef APP-NVUE -->
  15. <view class="gui-page-loading-point gui-flex gui-rows gui-justify-content-center">
  16. <view class="gui-page-loading-points gui-page-loading-color" ref="loadingPoints1"></view>
  17. <view class="gui-page-loading-points gui-page-loading-color" ref="loadingPoints2"></view>
  18. <view class="gui-page-loading-points gui-page-loading-color" ref="loadingPoints3"></view>
  19. </view>
  20. <!-- #endif -->
  21. </view>
  22. </template>
  23. <script>
  24. // #ifdef APP-NVUE
  25. const BindingX = uni.requireNativePlugin('bindingx');
  26. // #endif
  27. export default{
  28. name : "gui-page-loading",
  29. props : {},
  30. data() {
  31. return {
  32. isLoading : false,
  33. BindingXObjs : [null,null,null],
  34. AnimateObjs : [null,null,null],
  35. animateTimer : 800,
  36. intervalID : null
  37. }
  38. },
  39. watch:{
  40. // #ifdef APP-NVUE
  41. isLoading : function (val) {
  42. if(val){
  43. setTimeout(()=>{
  44. this.getRefs('loadingPoints1', 0, (refs)=>{
  45. this.BindingXObjs = [
  46. refs.ref,
  47. this.$refs.loadingPoints2.ref,
  48. this.$refs.loadingPoints3.ref
  49. ];
  50. this.startAnimate();
  51. });
  52. }, 100);
  53. this.intervalID = setInterval(()=>{
  54. if(this.isLoading){
  55. this.startAnimate();
  56. }else{
  57. clearInterval(this.intervalID);
  58. }
  59. }, 2000);
  60. }
  61. }
  62. // #endif
  63. },
  64. methods:{
  65. // #ifdef APP-NVUE
  66. startAnimate : function(){
  67. this.loadingAnimate(0);
  68. setTimeout(()=>{this.loadingAnimate(1);},300);
  69. setTimeout(()=>{this.loadingAnimate(2);},600);
  70. },
  71. loadingAnimate : function (id) {
  72. this.AnimateObjs[id] = BindingX.bind({
  73. eventType : 'timing',
  74. exitExpression : 't>'+this.animateTimer,
  75. props : [
  76. {
  77. element : this.BindingXObjs[id],
  78. property : 'transform.scale',
  79. expression : "1+t/"+this.animateTimer+"/3"
  80. },
  81. {
  82. element : this.BindingXObjs[id],
  83. property : 'opacity',
  84. expression : "0.6+t/"+this.animateTimer
  85. }
  86. ]
  87. }, (e)=>{
  88. if(e.state === 'exit') {
  89. BindingX.unbind({
  90. token : this.AnimateObjs[id].token,
  91. eventType: 'timing'
  92. });
  93. this.AnimateObjs[id] = BindingX.bind({
  94. eventType : 'timing',
  95. exitExpression : 't>'+this.animateTimer,
  96. props : [
  97. {
  98. element : this.BindingXObjs[id],
  99. property : 'transform.scale',
  100. expression : "1.35-t/"+this.animateTimer+"/3"
  101. },
  102. {
  103. element : this.BindingXObjs[id],
  104. property : 'opacity',
  105. expression : "1.6-t/"+this.animateTimer
  106. }
  107. ]
  108. }, (e)=>{
  109. if(e.state === 'exit') {
  110. BindingX.unbind({
  111. token : this.AnimateObjs[id].token,
  112. eventType: 'timing'
  113. });
  114. }
  115. });
  116. }
  117. });
  118. },
  119. // #endif
  120. stopfun : function(e){e.stopPropagation(); return null;},
  121. open : function(){ this.isLoading = true; },
  122. close : function(){
  123. setTimeout(()=>{
  124. this.isLoading = false;
  125. },100);
  126. },
  127. getRefs : function(ref, count, fun){
  128. if(count >= 50){
  129. fun(this.$refs[ref]);
  130. return false;
  131. }
  132. var refReturn = this.$refs[ref];
  133. if(refReturn){
  134. // #ifdef APP-NVUE
  135. fun(refReturn);
  136. return;
  137. // #endif
  138. // #ifndef APP-NVUE
  139. if(refReturn._data){
  140. fun(refReturn);
  141. return;
  142. }
  143. // #endif
  144. }else{
  145. count++;
  146. setTimeout(()=>{
  147. this.getRefs(ref, count, fun);
  148. }, 100);
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style scoped>
  155. .gui-page-loading{width:750rpx; position:fixed; left:0; top:0; bottom:0; flex:1; z-index:99999;}
  156. .gui-page-loading-points{width:20rpx; height:20rpx; border-radius:50rpx; margin:10rpx; opacity:0.5;}
  157. /* #ifndef APP-NVUE */
  158. @keyframes pageLoading1{0% {opacity:0.5; transform:scale(1);} 40% {opacity:1; transform:scale(1.5);} 60%{opacity:0.5; transform:scale(1);}}
  159. @keyframes pageLoading2{20% {opacity:0.5; transform:scale(1);} 60% {opacity:1; transform:scale(1.5);} 80% {opacity:0.5; transform:scale(1);}}
  160. @keyframes pageLoading3{40% {opacity:0.5; transform:scale(1);} 80% {opacity:1; transform:scale(1.5);} 100% {opacity:0.5; transform:scale(1);}}
  161. .animate1{animation:pageLoading1 1.2s infinite linear;}
  162. .animate2{animation:pageLoading2 1.2s infinite linear;}
  163. .animate3{animation:pageLoading3 1.2s infinite linear;}
  164. /* #endif */
  165. </style>