ls-loading.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view
  3. class="loading-wrapper"
  4. :class="{ 'loading-wrapper-embed': embed }"
  5. :style="{ top: topSize, bottom: bottomSize }"
  6. hover-stop-propagation
  7. @tap.stop.prevent="defThouch"
  8. @touchmove.stop.prevent="defMove"
  9. >
  10. <!-- 文字闪烁动画类型 twinkle-->
  11. <comb-loader :text="text" :font-size="fontSize" animation-type="twinkle" v-if="animation == 'twinkle'" />
  12. <!-- 文字聚焦动画类型 focus -->
  13. <comb-loader :text="text" :font-size="fontSize" animation-type="focus" v-else-if="animation == 'focus'" />
  14. <!-- 模拟水位上涨画类型 rise-loader -->
  15. <rise-loader :text="text" :font-size="fontSize" :under-color="underColor" :highlight-color="highlightColor" v-else-if="animation == 'rise'" />
  16. <!-- 水平进度加载动画类型 progress -->
  17. <progress-loader :text="text" :font-size="fontSize" :under-color="underColor" :highlight-color="highlightColor" v-else-if="animation == 'progress'" />
  18. <!-- 文字跳动动画类型 -->
  19. <jump-loader :text="text" :font-size="fontSize" v-else-if="animation == 'jump'"/>
  20. </view>
  21. </template>
  22. <script>
  23. /**
  24. * ls-loading 页面加载等待loading
  25. * 插件地址:https://ext.dcloud.net.cn/plugin?id=3497
  26. * @description 通常用于页面数据需要异步加载时,为避免出现数据加载完毕之前页面上出现空数据的尴尬情况,显示loading层作为页面载入过渡
  27. * @tutorial lsl
  28. * @property {Boolean} nav 是否预留出标题栏的高度,通常在自定义导航栏页面中需要设置为true (默认:false)
  29. * @property {Boolean} tab 是否预留出tabBar的高度,通常在自定义tabBar的页面中需要设置为true (默认:false)
  30. * @property {Boolean} embed 是否为嵌入模式 (默认:false)
  31. * @property {String} text 加载中的文字 (默认:正在加载)
  32. * @property {String|Number} fontSize 加载中文字大小 (默认:58, 单位rpx)
  33. * @property {String} animation 动画类型 twinkle|focus|rise|jump|progress 详见uniapp插件市场说明
  34. * @property {String} underColor 底层文字颜色 仅在animation为 jump|rise|progress下有效
  35. * @property {String} highlightColor 高亮文字颜色 仅在animation为rise|progress下有效
  36. * @example <ls-loading v-if="pageLoading"></ls-loading>
  37. */
  38. import combLoader from './components/comb-loader.vue';
  39. import riseLoader from './components/rise-loader.vue';
  40. import progressLoader from './components/progress-loader.vue';
  41. import jumpLoader from './components/jump-loader.vue';
  42. export default {
  43. name: 'ls-loading',
  44. components: { combLoader, riseLoader, progressLoader, jumpLoader },
  45. props: {
  46. // 是否预留出标题栏的高度
  47. nav: {
  48. type: Boolean,
  49. default: false
  50. },
  51. // 是否预留出tabBar的高度
  52. tab: {
  53. type: Boolean,
  54. default: false
  55. },
  56. // 加载中的文字
  57. text: {
  58. type: String,
  59. default: '正在加载'
  60. },
  61. // embed 是否为嵌入模式
  62. embed: {
  63. type: Boolean,
  64. default: false
  65. },
  66. // 加载中文字大小
  67. fontSize: {
  68. type: [String, Number],
  69. default: 58
  70. },
  71. // 动画类型 twinkle|focus|rise|jump|progress
  72. animation: {
  73. type: String,
  74. default: 'twinkle'
  75. },
  76. // 底层颜色
  77. underColor: {
  78. type: String,
  79. default: '#e8e7e8'
  80. },
  81. // 高亮部分颜色
  82. highlightColor: {
  83. type: String,
  84. default: '#00bfff'
  85. }
  86. },
  87. data() {
  88. return {
  89. topSize: ''
  90. };
  91. },
  92. computed: {
  93. bottomSize() {
  94. return this.tab ? '50px' : '0';
  95. }
  96. },
  97. created() {
  98. setTimeout(() => {
  99. const res = uni.getSystemInfoSync();
  100. this.topSize = this.nav ? `${res.statusBarHeight + 44}px` : `0px`;
  101. }, 1);
  102. },
  103. methods: {
  104. defThouch(e) {
  105. // 阻止点击穿透
  106. // #ifdef APP-NVUE
  107. e.stopPropagation();
  108. // #endif
  109. },
  110. defMove(e) {
  111. // 阻止滚动穿透
  112. // #ifdef APP-NVUE
  113. e.stopPropagation();
  114. // #endif
  115. }
  116. }
  117. };
  118. </script>
  119. <style scoped>
  120. </style>