Loading.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <teleport to="body">
  3. <div :key="id" class="loading">
  4. <input
  5. ref="focusInput"
  6. autocomplete="off"
  7. class="focus-input"
  8. />
  9. <div
  10. class="spinner"
  11. >
  12. <div class="circ1" />
  13. <div class="circ2" />
  14. <div class="circ3" />
  15. <div class="circ4" />
  16. <h4>{{ text }}</h4>
  17. </div>
  18. </div>
  19. </teleport>
  20. </template>
  21. <script>
  22. import UUID from '../../common/Uuid.js';
  23. export default {
  24. // eslint-disable-next-line
  25. name: 'Loading',
  26. props: {
  27. 'text': {
  28. type: String,
  29. default: '',
  30. },
  31. },
  32. data: function () {
  33. return {
  34. 'id': 'loading_' + UUID.createUUID(),
  35. };
  36. },
  37. mounted: function () {
  38. var _self = this;
  39. // 获取焦点对象
  40. _self.activeElement = document.activeElement;
  41. _self.$nextTick(function () {
  42. _self.$refs.focusInput.focus();
  43. });
  44. },
  45. beforeUnmount: function(){
  46. var _self = this;
  47. // 恢复焦点对象
  48. if(_self.activeElement != null){
  49. _self.activeElement.focus();
  50. _self.activeElement = null;
  51. }
  52. },
  53. methods: {
  54. // 居中显示
  55. // centerLoader: function () {
  56. // var _self = this;
  57. // var winW = $(window).width();
  58. // var winH = $(window).height();
  59. // var id = '#' + _self.id;
  60. // var spinnerW = $(id).outerWidth();
  61. // var spinnerH = $(id).outerHeight();
  62. // $(id).css({
  63. // 'position': 'absolute',
  64. // 'left': ((winW / 2) - (spinnerW / 2)) + 'px',
  65. // 'top': ((winH / 2) - (spinnerH / 2)) + 'px',
  66. // });
  67. // },
  68. },
  69. };
  70. </script>
  71. <style scoped>
  72. .loading {
  73. display: block;
  74. position: fixed;
  75. width: 100%;
  76. height: 100%;
  77. top: 0px;
  78. left: 0px;
  79. z-index: 99999;
  80. background-color: #2ecc71;
  81. opacity: 0.5;
  82. }
  83. .circle1 {
  84. top: 0;
  85. left: 0;
  86. }
  87. .circle2 {
  88. top: 0;
  89. right: 0;
  90. }
  91. .circle3 {
  92. right: 0;
  93. bottom: 0;
  94. }
  95. .circle4 {
  96. left: 0;
  97. bottom: 0;
  98. }
  99. .spinner {
  100. width: 90px;
  101. height: 30px;
  102. text-align: center;
  103. position: fixed;
  104. left: calc(50% - 45px);
  105. top: calc(50% - 15px);
  106. }
  107. .spinner > div {
  108. background-color: #fff;
  109. height: 15px;
  110. width: 15px;
  111. margin-left: 3px;
  112. border-radius: 50%;
  113. display: inline-block;
  114. -webkit-animation: stretchdelay 0.7s infinite ease-in-out;
  115. animation: stretchdelay 0.7s infinite ease-in-out;
  116. }
  117. .spinner .circ2 {
  118. -webkit-animation-delay: -0.6s;
  119. animation-delay: -0.6s;
  120. }
  121. .spinner .circ3 {
  122. -webkit-animation-delay: -0.5s;
  123. animation-delay: -0.5s;
  124. }
  125. .spinner .circ4 {
  126. -webkit-animation-delay: -0.4s;
  127. animation-delay: -0.4s;
  128. }
  129. .spinner .circ5 {
  130. -webkit-animation-delay: -0.3s;
  131. animation-delay: -0.3s;
  132. }
  133. @-webkit-keyframes stretchdelay {
  134. 0%,
  135. 40%,
  136. 100% {
  137. -webkit-transform: translateY(-10px);
  138. }
  139. 20% {
  140. -webkit-transform: translateY(-20px);
  141. }
  142. }
  143. @keyframes stretchdelay {
  144. 0%,
  145. 40%,
  146. 100% {
  147. transform: translateY(-10px);
  148. -webkit-transform: translateY(-10px);
  149. }
  150. 20% {
  151. transform: translateY(-20px);
  152. -webkit-transform: translateY(-20px);
  153. }
  154. }
  155. .focus-input {
  156. position: absolute;
  157. left: -10px;
  158. top: -10px;
  159. width: 0px;
  160. height: 0px;
  161. }
  162. </style>