gui-submit-button.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="gui-sbutton-in"
  3. :class="[
  4. baseClass,
  5. status == 1 ? defaultClass : '' ,
  6. status == 2 ? loadingClass : '' ,
  7. status == 3 ? successClass : '',
  8. status >= 3 ? 'gui-btn-fade-in' : '',
  9. status == 4 ? failClass : '',]">
  10. <view class="gui-sbutton" v-if="status == 1">
  11. <slot name="default"></slot>
  12. </view>
  13. <view
  14. class="gui-sbutton gui-flex gui-rows gui-nowrap gui-justify-content-center gui-align-items-center"
  15. :class="[baseClass]"
  16. v-if="status == 2">
  17. <view ref="loadingPoints1" :class="[loaingPointClass, 'gui-sbutton-loading1']"></view>
  18. <view ref="loadingPoints2" :class="[loaingPointClass, 'gui-sbutton-loading2']"></view>
  19. <view ref="loadingPoints3" :class="[loaingPointClass, 'gui-sbutton-loading3']"></view>
  20. </view>
  21. <view class="gui-sbutton" v-if="status == 3">
  22. <slot name="success"></slot>
  23. </view>
  24. <view class="gui-sbutton" v-if="status == 4">
  25. <slot name="error"></slot>
  26. </view>
  27. <view class="gui-sbutton gui-sbutton-slot"><slot name="realBtn"></slot></view>
  28. </view>
  29. </template>
  30. <script>
  31. // #ifdef APP-NVUE
  32. const BindingX = uni.requireNativePlugin('bindingx');
  33. // #endif
  34. export default{
  35. name : "gui-submit-button",
  36. props : {
  37. titleClass : {type:String, default : 'gui-sbutton-text'},
  38. loaingPointClass : {type:String, default : 'gui-sbutton-loading-point'},
  39. baseClass : {type:String, default : 'gui-sbutton'},
  40. defaultClass : {type:String, default : 'gui-sbutton-default'},
  41. loadingClass : {type:String, default : 'gui-sbutton-loading'},
  42. successClass : {type:String, default : 'gui-sbutton-success'},
  43. failClass : {type:String, default : 'gui-sbutton-fail'}
  44. },
  45. data() {
  46. return {
  47. status : 1,
  48. animateTimer : 800,
  49. BindingXObjs : [null,null,null],
  50. AnimateObjs : [null,null,null],
  51. intervalID : null
  52. }
  53. },
  54. // #ifdef APP-NVUE
  55. watch:{
  56. status:function(val){
  57. switch(val){
  58. case 1 :
  59. clearInterval(this.intervalID);
  60. break;
  61. case 2 :
  62. setTimeout(()=>{
  63. this.getRefs('loadingPoints1', 0, (refs)=>{
  64. this.BindingXObjs = [
  65. refs.ref,
  66. this.$refs.loadingPoints2.ref,
  67. this.$refs.loadingPoints3.ref
  68. ];
  69. this.startAnimate();
  70. });
  71. }, 100);
  72. this.intervalID = setInterval(()=>{
  73. this.startAnimate();
  74. }, 1000);
  75. break;
  76. case 3 :
  77. clearInterval(this.intervalID);
  78. break;
  79. case 4 :
  80. clearInterval(this.intervalID);
  81. break;
  82. default :
  83. clearInterval(this.intervalID);
  84. }
  85. }
  86. },
  87. // #endif
  88. methods : {
  89. reset : function () {
  90. this.status = 1;
  91. },
  92. loading : function () {
  93. this.status = 2;
  94. },
  95. success : function () {
  96. this.status = 3;
  97. },
  98. fail : function () {
  99. this.status = 4;
  100. },
  101. // #ifdef APP-NVUE
  102. startAnimate : function(){
  103. this.loadingAnimate(0);
  104. setTimeout(()=>{this.loadingAnimate(1);},300);
  105. setTimeout(()=>{this.loadingAnimate(2);},600);
  106. },
  107. loadingAnimate : function (id) {
  108. this.AnimateObjs[id] = BindingX.bind({
  109. eventType : 'timing',
  110. exitExpression : 't>'+this.animateTimer,
  111. props : [
  112. {
  113. element : this.BindingXObjs[id],
  114. property : 'transform.scale',
  115. expression : "1+t/"+this.animateTimer+"/3"
  116. },
  117. {
  118. element : this.BindingXObjs[id],
  119. property : 'opacity',
  120. expression : "0.6+t/"+this.animateTimer
  121. }
  122. ]
  123. }, (e)=>{
  124. if(e.state === 'exit') {
  125. BindingX.unbind({
  126. token : this.AnimateObjs[id].token,
  127. eventType: 'timing'
  128. });
  129. this.AnimateObjs[id] = BindingX.bind({
  130. eventType : 'timing',
  131. exitExpression : 't>'+this.animateTimer,
  132. props : [
  133. {
  134. element : this.BindingXObjs[id],
  135. property : 'transform.scale',
  136. expression : "1.35-t/"+this.animateTimer+"/3"
  137. },
  138. {
  139. element : this.BindingXObjs[id],
  140. property : 'opacity',
  141. expression : "1.6-t/"+this.animateTimer
  142. }
  143. ]
  144. }, (e)=>{
  145. if(e.state === 'exit') {
  146. BindingX.unbind({
  147. token : this.AnimateObjs[id].token,
  148. eventType: 'timing'
  149. });
  150. }
  151. });
  152. }
  153. });
  154. },
  155. // #endif
  156. getRefs : function(ref, count, fun){
  157. if(count >= 30){return null;}
  158. var refReturn = this.$refs[ref];
  159. if(refReturn){
  160. fun(refReturn);
  161. return;
  162. }else{
  163. count++;
  164. setTimeout(()=>{
  165. this.getRefs(ref, count, fun);
  166. }, 50);
  167. }
  168. }
  169. }
  170. }
  171. </script>
  172. <style>
  173. .gui-sbutton-in{position:relative; overflow:hidden;}
  174. .gui-sbutton-slot{opacity:0; position:absolute; left:0; top:0; z-index:1;}
  175. /* #ifndef APP-NVUE */
  176. .gui-sbutton-loading1{animation:gui-sbutton-loading1 1200ms ease-in infinite;}
  177. @keyframes gui-sbutton-loading1{
  178. 0%{transform: translateY(0px);}
  179. 25%{transform: translateY(2px);}
  180. 100%{transform: translateY(0px);}
  181. }
  182. .gui-sbutton-loading2{animation:gui-sbutton-loading2 1200ms ease-in infinite;}
  183. @keyframes gui-sbutton-loading2{
  184. 0%{transform: translateY(0px);}
  185. 25%{transform: translateY(0px);}
  186. 50%{transform: translateY(2px);}
  187. 75%{transform: translateY(2px);}
  188. 100%{transform: translateY(0px);}
  189. }
  190. .gui-sbutton-loading3{animation:gui-sbutton-loading3 1200ms ease-in infinite;}
  191. @keyframes gui-sbutton-loading3{
  192. 0%{transform: translateY(0px);}
  193. 25%{transform: translateY(0px);}
  194. 50%{transform: translateY(0px);}
  195. 75%{transform: translateY(2px);}
  196. 100%{transform: translateY(0px);}
  197. }
  198. @keyframes gui-btn-fade-in{0%{opacity:0.5;} 100%{opacity:1;}}
  199. .gui-btn-fade-in{animation:gui-btn-fade-in 350ms ease-in forwards;}
  200. /* #endif */
  201. </style>