index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view :class="'custom-class van-loading ' + (vertical ? 'van-loading--vertical' : '')">
  3. <view :class="'van-loading__spinner van-loading__spinner--' + type" :style="'color: ' + color + '; width: ' + sizeWithUnit + '; height: ' + sizeWithUnit">
  4. <view :wx:if="type === 'spinner'" wx:for="item in 12" wx:key="index" class="van-loading__dot" />
  5. </view>
  6. <view class="van-loading__text" :style="'font-size: ' + textSizeWithUnit + ';'">
  7. <slot />
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import { VantComponent } from '../common/component';
  13. import { addUnit } from '../common/utils';
  14. export default {
  15. data() {
  16. return {
  17. sizeWithUnit: '',
  18. textSizeWithUnit: ''
  19. };
  20. },
  21. props: {
  22. color: String,
  23. vertical: Boolean,
  24. type: {
  25. type: String,
  26. default: 'circular'
  27. },
  28. size: {
  29. type: String
  30. },
  31. textSize: {
  32. type: String
  33. }
  34. },
  35. methods: {
  36. setSizeWithUnit(size) {
  37. this.setData({
  38. sizeWithUnit: addUnit(size)
  39. });
  40. },
  41. setTextSizeWithUnit(size) {
  42. this.set({
  43. textSizeWithUnit: addUnit(size)
  44. });
  45. }
  46. },
  47. watch: {
  48. size: {
  49. handler: function (size) {
  50. this.setData({
  51. sizeWithUnit: addUnit(size)
  52. });
  53. },
  54. immediate: true
  55. },
  56. textSize: {
  57. handler: function (size) {
  58. this.set({
  59. textSizeWithUnit: addUnit(size)
  60. });
  61. },
  62. immediate: true
  63. }
  64. }
  65. };
  66. </script>
  67. <style>
  68. @import '../common/index.ttss';
  69. :host {
  70. font-size: 0;
  71. line-height: 1;
  72. }
  73. .van-loading {
  74. display: -webkit-inline-flex;
  75. display: inline-flex;
  76. -webkit-align-items: center;
  77. align-items: center;
  78. -webkit-justify-content: center;
  79. justify-content: center;
  80. color: #c8c9cc;
  81. color: var(--loading-spinner-color, #c8c9cc);
  82. }
  83. .van-loading__spinner {
  84. position: relative;
  85. box-sizing: border-box;
  86. width: 30px;
  87. width: var(--loading-spinner-size, 30px);
  88. max-width: 100%;
  89. max-height: 100%;
  90. height: 30px;
  91. height: var(--loading-spinner-size, 30px);
  92. -webkit-animation: van-rotate 0.8s linear infinite;
  93. animation: van-rotate 0.8s linear infinite;
  94. -webkit-animation: van-rotate var(--loading-spinner-animation-duration, 0.8s) linear infinite;
  95. animation: van-rotate var(--loading-spinner-animation-duration, 0.8s) linear infinite;
  96. }
  97. .van-loading__spinner--spinner {
  98. -webkit-animation-timing-function: steps(12);
  99. animation-timing-function: steps(12);
  100. }
  101. .van-loading__spinner--circular {
  102. border: 1px solid transparent;
  103. border-top-color: initial;
  104. border-radius: 100%;
  105. }
  106. .van-loading__text {
  107. margin-left: 8px;
  108. margin-left: var(--padding-xs, 8px);
  109. color: #969799;
  110. color: var(--loading-text-color, #969799);
  111. font-size: 14px;
  112. font-size: var(--loading-text-font-size, 14px);
  113. line-height: 20px;
  114. line-height: var(--loading-text-line-height, 20px);
  115. }
  116. .van-loading__text:empty {
  117. display: none;
  118. }
  119. .van-loading--vertical {
  120. -webkit-flex-direction: column;
  121. flex-direction: column;
  122. }
  123. .van-loading--vertical .van-loading__text {
  124. margin: 8px 0 0;
  125. margin: var(--padding-xs, 8px) 0 0;
  126. }
  127. .van-loading__dot {
  128. position: absolute;
  129. top: 0;
  130. left: 0;
  131. width: 100%;
  132. height: 100%;
  133. }
  134. .van-loading__dot:before {
  135. display: block;
  136. width: 2px;
  137. height: 25%;
  138. margin: 0 auto;
  139. background-color: currentColor;
  140. border-radius: 40%;
  141. content: ' ';
  142. }
  143. .van-loading__dot:first-of-type {
  144. -webkit-transform: rotate(30deg);
  145. transform: rotate(30deg);
  146. opacity: 1;
  147. }
  148. .van-loading__dot:nth-of-type(2) {
  149. -webkit-transform: rotate(60deg);
  150. transform: rotate(60deg);
  151. opacity: 0.9375;
  152. }
  153. .van-loading__dot:nth-of-type(3) {
  154. -webkit-transform: rotate(90deg);
  155. transform: rotate(90deg);
  156. opacity: 0.875;
  157. }
  158. .van-loading__dot:nth-of-type(4) {
  159. -webkit-transform: rotate(120deg);
  160. transform: rotate(120deg);
  161. opacity: 0.8125;
  162. }
  163. .van-loading__dot:nth-of-type(5) {
  164. -webkit-transform: rotate(150deg);
  165. transform: rotate(150deg);
  166. opacity: 0.75;
  167. }
  168. .van-loading__dot:nth-of-type(6) {
  169. -webkit-transform: rotate(180deg);
  170. transform: rotate(180deg);
  171. opacity: 0.6875;
  172. }
  173. .van-loading__dot:nth-of-type(7) {
  174. -webkit-transform: rotate(210deg);
  175. transform: rotate(210deg);
  176. opacity: 0.625;
  177. }
  178. .van-loading__dot:nth-of-type(8) {
  179. -webkit-transform: rotate(240deg);
  180. transform: rotate(240deg);
  181. opacity: 0.5625;
  182. }
  183. .van-loading__dot:nth-of-type(9) {
  184. -webkit-transform: rotate(270deg);
  185. transform: rotate(270deg);
  186. opacity: 0.5;
  187. }
  188. .van-loading__dot:nth-of-type(10) {
  189. -webkit-transform: rotate(300deg);
  190. transform: rotate(300deg);
  191. opacity: 0.4375;
  192. }
  193. .van-loading__dot:nth-of-type(11) {
  194. -webkit-transform: rotate(330deg);
  195. transform: rotate(330deg);
  196. opacity: 0.375;
  197. }
  198. .van-loading__dot:nth-of-type(12) {
  199. -webkit-transform: rotate(1turn);
  200. transform: rotate(1turn);
  201. opacity: 0.3125;
  202. }
  203. @-webkit-keyframes van-rotate {
  204. 0% {
  205. -webkit-transform: rotate(0deg);
  206. transform: rotate(0deg);
  207. }
  208. to {
  209. -webkit-transform: rotate(1turn);
  210. transform: rotate(1turn);
  211. }
  212. }
  213. @keyframes van-rotate {
  214. 0% {
  215. -webkit-transform: rotate(0deg);
  216. transform: rotate(0deg);
  217. }
  218. to {
  219. -webkit-transform: rotate(1turn);
  220. transform: rotate(1turn);
  221. }
  222. }
  223. </style>