tn-loading.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view
  3. v-if="show"
  4. class="tn-loading-class tn-loading"
  5. :class="[
  6. `tn-loading-${mode}`,
  7. animation ? `tn-loading-${mode}--animation` : ''
  8. ]"
  9. :style="[loadStyle]"
  10. ></view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'tn-loading',
  15. props: {
  16. // 动画类型
  17. // circle 圆圈 flower 花朵形状
  18. mode: {
  19. type: String,
  20. default: 'circle'
  21. },
  22. // 是否显示
  23. show: {
  24. type: Boolean,
  25. default: true
  26. },
  27. // 是否显示加载动画
  28. animation: {
  29. type: Boolean,
  30. default: true
  31. },
  32. // 圆圈颜色
  33. color: {
  34. type: String,
  35. default: ''
  36. },
  37. // 图标大小
  38. size: {
  39. type: Number,
  40. default: 34
  41. }
  42. },
  43. computed: {
  44. // 加载动画圆圈的样式
  45. loadStyle() {
  46. let style = {}
  47. style.width = this.size + 'rpx'
  48. style.height = style.width
  49. if (this.mode === 'circle') style.borderColor = `#E6E6E6 #E6E6E6 #E6E6E6 ${this.color ? this.color : '#AAAAAA'}`
  50. return style
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .tn-loading-circle {
  57. /* #ifndef APP-NVUE */
  58. display: inline-flex;
  59. /* #endif */
  60. vertical-align: middle;
  61. width: 28rpx;
  62. height: 28rpx;
  63. background: 0 0;
  64. border-radius: 50%;
  65. border: 2px solid;
  66. border-color: #E6E6E6 #E6E6E6 #E6E6E6 #AAAAAA;
  67. &--animation {
  68. animation: tn-circle 1s linear infinite;
  69. -webkit-animation: tn-circle 1s linear infinite;
  70. }
  71. }
  72. .tn-loading-flower {
  73. display: inline-block;
  74. vertical-align: middle;
  75. width: 28rpx;
  76. height: 28rpx;
  77. background: transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL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2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=) no-repeat;;
  78. background-size: 100%;
  79. &--animation {
  80. animation: tn-flower 1s steps(12) infinite;
  81. -webkit-animation: tn-flower 1s steps(12) infinite;
  82. }
  83. }
  84. @keyframes tn-flower {
  85. 0% {
  86. transform: rotate(0deg);
  87. -webkit-transform: rotate(0deg);
  88. }
  89. to {
  90. transform: rotate(360deg);
  91. -webkit-transform: rotate(360deg);
  92. }
  93. }
  94. @keyframes tn-circle {
  95. 0% {
  96. transform: rotate(0);
  97. -webkit-transform: rotate(0);
  98. }
  99. 100% {
  100. transform: rotate(360deg);
  101. -webkit-transform: rotate(360deg);
  102. }
  103. }
  104. </style>