cl-loading.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view
  3. class="cl-loading"
  4. :class="[`cl-loading--${theme}`]"
  5. :style="{ height: size + 'px', width: size + 'px' }"
  6. >
  7. <!-- 菊花 -->
  8. <template v-if="theme == 'spin'">
  9. <view class="cl-loading__spin" v-for="i in 2" :key="i">
  10. <text
  11. class="cl-loading__spin-item"
  12. :style="[
  13. spinStyle,
  14. {
  15. top: 0,
  16. left: `calc(50% - ${rw}px)`,
  17. },
  18. ]"
  19. ></text>
  20. <text
  21. class="cl-loading__spin-item"
  22. :style="[
  23. spinStyle,
  24. {
  25. top: `calc(50% - ${rh}px)`,
  26. right: `${rh - rw}px`,
  27. transform: 'rotate(90deg)',
  28. },
  29. ]"
  30. ></text>
  31. <text
  32. class="cl-loading__spin-item"
  33. :style="[
  34. spinStyle,
  35. {
  36. left: `calc(50% - ${rw}px)`,
  37. bottom: 0,
  38. },
  39. ]"
  40. ></text>
  41. <text
  42. class="cl-loading__spin-item"
  43. :style="[
  44. spinStyle,
  45. {
  46. left: `${rh - rw}px`,
  47. top: `calc(50% - ${rh}px)`,
  48. transform: 'rotate(90deg)',
  49. },
  50. ]"
  51. ></text>
  52. </view>
  53. </template>
  54. <!-- 默认 -->
  55. <view
  56. class="cl-loading__inner"
  57. :style="{
  58. color,
  59. borderColor,
  60. borderWidth,
  61. 'border-bottom': `${borderWidth} solid currentColor`,
  62. }"
  63. v-else
  64. >
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. /**
  70. * loading 加载图标
  71. * @description 加载图标
  72. * @tutorial https://docs.cool-js.com/uni/components/feedback/loading.html
  73. * @property {String} color 图标颜色
  74. * @property {Number} size 图标大小
  75. * @property {String} theme 主题,default | spin
  76. * @example <cl-loading></cl-loading>
  77. */
  78. export default {
  79. name: "cl-loading",
  80. props: {
  81. color: String,
  82. borderColor: {
  83. type: String,
  84. default: "rgba(0, 0, 0, 0.1)",
  85. },
  86. borderWidth: {
  87. type: String,
  88. default: "4rpx",
  89. },
  90. theme: {
  91. type: String,
  92. default: "default",
  93. },
  94. size: {
  95. type: Number,
  96. default: 25,
  97. },
  98. },
  99. computed: {
  100. rh() {
  101. return this.size / 8;
  102. },
  103. rw() {
  104. return this.size / 20;
  105. },
  106. spinStyle() {
  107. return {
  108. height: this.rh * 2 + "px",
  109. width: this.rw * 2 + "px",
  110. color: this.color,
  111. };
  112. },
  113. },
  114. };
  115. </script>