uni-loading.uvue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!-- 如果没有插槽,则使用 load-inline 样式 -->
  3. <view class="uni-loading-main" :class="{'load-inline':$slots['default'] == null}">
  4. <template v-if="loading">
  5. <slot></slot>
  6. <template v-if="$slots['default'] == null">
  7. <LoadingCircle :speed="16" :size="loadWidth" :color="color"></LoadingCircle>
  8. <text v-if="text" class="inline-text" :style=" { color: color }">{{text}}</text>
  9. </template>
  10. <template v-else>
  11. <view class="uni-loading-mask" :style="{backgroundColor:background}">
  12. <LoadingCircle :speed="16" :size="loadWidth" :color="color"></LoadingCircle>
  13. <text v-if="text" class="block-text" :style=" { color: color }">{{text}}</text>
  14. </view>
  15. </template>
  16. </template>
  17. <template v-else>
  18. <slot></slot>
  19. </template>
  20. </view>
  21. </template>
  22. <script>
  23. import LoadingCircle from './loading-circle.uvue'
  24. // TODO 性能问题,其他类型暂时不对外开放
  25. // import Icon from './icon.uvue'
  26. // import UniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.uvue'
  27. // import { img_load_base } from './load-img.uts'
  28. /**
  29. * Loading-x 加载动画
  30. * @description 用于数据加载场景,使用loading等待数据返回
  31. * @tutorial https://ext.dcloud.net.cn/plugin?name=uni-loading-x
  32. * @property {Boolean} loading 是否显示加载动画,默认:true
  33. * @property {String} type = [snow|circle|icon] 加载图标显示,默认:circle
  34. * @value snow 显示雪花加载动画,性能问题暂时不支持
  35. * @value circle 显示圆形加载动画
  36. * @value icon 自定义图标 ,暂时不支持
  37. * @property {String} background 加载遮罩颜色,支持 rgba 色值,默认:rgba(255,255,255,0.6)
  38. * @property {String} color 加载图标以及加载文字颜色,默认:#333333
  39. * @property {String} size 加载图标大小,默认:20
  40. * @property {String} text 加载文本,默认:不显示
  41. * @property {String} iconType 自定义图标类型,参考 uni-icons ,当前版本暂不支持
  42. */
  43. export default {
  44. name: "uni-loading",
  45. components: { LoadingCircle },
  46. props: {
  47. loading: {
  48. type: Boolean,
  49. default: true,
  50. },
  51. type: {
  52. type: String,
  53. default: ''
  54. },
  55. iconType: {
  56. type: String,
  57. default: 'gear-filled'
  58. },
  59. size: {
  60. type: Number,
  61. default: 0
  62. },
  63. text: {
  64. type: String,
  65. default: ''
  66. },
  67. background: {
  68. type: String,
  69. default: 'rgba(255,255,255,0.6)'
  70. },
  71. color: {
  72. type: String,
  73. default: '#333'
  74. }
  75. },
  76. data() {
  77. return {};
  78. },
  79. computed: {
  80. loadWidth() : number {
  81. let width = this.size
  82. if (width == 0) {
  83. return 20
  84. }
  85. return width
  86. },
  87. styles() : string {
  88. return `width:${this.loadWidth}px;height:${this.loadWidth}px;`
  89. }
  90. },
  91. created() {},
  92. methods: {}
  93. }
  94. </script>
  95. <style scoped>
  96. .uni-loading-main {
  97. position: relative;
  98. }
  99. .uni-loading-main.load-inline {
  100. display: flex;
  101. flex-direction: row;
  102. align-items: center;
  103. }
  104. .block-text {
  105. margin-top: 8px;
  106. font-size: 14px;
  107. }
  108. .inline-text {
  109. margin-left: 8px;
  110. font-size: 14px;
  111. }
  112. .uni-loading-mask {
  113. position: absolute;
  114. width: 100%;
  115. height: 100%;
  116. top: 0;
  117. left: 0;
  118. display: flex;
  119. justify-content: center;
  120. align-items: center;
  121. justify-content: center;
  122. }
  123. .uni-loading-mask {
  124. background-color: rgba(0, 0, 0, 0.3);
  125. z-index: 2;
  126. }
  127. .uni-load {
  128. display: flex;
  129. flex-direction: row;
  130. justify-content: center;
  131. align-items: center;
  132. }
  133. .load-text {
  134. font-size: 14px;
  135. color: #fff;
  136. margin-top: 12px;
  137. }
  138. .uni-load .image,
  139. .load-image {
  140. width: 100%;
  141. height: 100%;
  142. }
  143. .load-ani {
  144. transition-property: transform;
  145. transition-duration: 0.1s;
  146. transition-timing-function: linear;
  147. transform: rotate(0deg);
  148. }
  149. </style>