gui-page-loading.vue 4.5 KB

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