Loading.vue 3.6 KB

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