Loading.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. var UUID = require('../../common/Uuid.js').default;
  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. _self.$nextTick(function () {
  40. _self.$refs.focusInput.focus();
  41. });
  42. },
  43. methods: {
  44. // 居中显示
  45. // centerLoader: function () {
  46. // var _self = this;
  47. // var winW = $(window).width();
  48. // var winH = $(window).height();
  49. // var id = '#' + _self.id;
  50. // var spinnerW = $(id).outerWidth();
  51. // var spinnerH = $(id).outerHeight();
  52. // $(id).css({
  53. // 'position': 'absolute',
  54. // 'left': ((winW / 2) - (spinnerW / 2)) + 'px',
  55. // 'top': ((winH / 2) - (spinnerH / 2)) + 'px',
  56. // });
  57. // },
  58. },
  59. };
  60. </script>
  61. <style scoped>
  62. .loading {
  63. display: block;
  64. position: fixed;
  65. width: 100%;
  66. height: 100%;
  67. top: 0px;
  68. left: 0px;
  69. z-index: 99999;
  70. background-color: #2ecc71;
  71. opacity: 0.5;
  72. }
  73. .circle1 {
  74. top: 0;
  75. left: 0;
  76. }
  77. .circle2 {
  78. top: 0;
  79. right: 0;
  80. }
  81. .circle3 {
  82. right: 0;
  83. bottom: 0;
  84. }
  85. .circle4 {
  86. left: 0;
  87. bottom: 0;
  88. }
  89. .spinner {
  90. width: 90px;
  91. height: 30px;
  92. text-align: center;
  93. position: fixed;
  94. left: calc(50% - 45px);
  95. top: calc(50% - 15px);
  96. }
  97. .spinner > div {
  98. background-color: #fff;
  99. height: 15px;
  100. width: 15px;
  101. margin-left: 3px;
  102. border-radius: 50%;
  103. display: inline-block;
  104. -webkit-animation: stretchdelay 0.7s infinite ease-in-out;
  105. animation: stretchdelay 0.7s infinite ease-in-out;
  106. }
  107. .spinner .circ2 {
  108. -webkit-animation-delay: -0.6s;
  109. animation-delay: -0.6s;
  110. }
  111. .spinner .circ3 {
  112. -webkit-animation-delay: -0.5s;
  113. animation-delay: -0.5s;
  114. }
  115. .spinner .circ4 {
  116. -webkit-animation-delay: -0.4s;
  117. animation-delay: -0.4s;
  118. }
  119. .spinner .circ5 {
  120. -webkit-animation-delay: -0.3s;
  121. animation-delay: -0.3s;
  122. }
  123. @-webkit-keyframes stretchdelay {
  124. 0%,
  125. 40%,
  126. 100% {
  127. -webkit-transform: translateY(-10px);
  128. }
  129. 20% {
  130. -webkit-transform: translateY(-20px);
  131. }
  132. }
  133. @keyframes stretchdelay {
  134. 0%,
  135. 40%,
  136. 100% {
  137. transform: translateY(-10px);
  138. -webkit-transform: translateY(-10px);
  139. }
  140. 20% {
  141. transform: translateY(-20px);
  142. -webkit-transform: translateY(-20px);
  143. }
  144. }
  145. .focus-input {
  146. position: absolute;
  147. left: -10px;
  148. top: -10px;
  149. width: 0px;
  150. height: 0px;
  151. }
  152. </style>