SimplePageContentLoader.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view
  3. v-if="loader?.status.value == 'loading'"
  4. class="loader-view center"
  5. >
  6. <LoadingPage v-if="showLoading" loadingText="加载中" textSize="18" />
  7. </view>
  8. <view
  9. v-else-if="loader?.status.value == 'error'"
  10. class="loader-view"
  11. >
  12. <Empty
  13. image="error"
  14. :description="loader.error.value"
  15. >
  16. <Height :height="20" />
  17. <Button type="primary" text="刷新" @click="handleRetry" />
  18. </Empty>
  19. </view>
  20. <view
  21. v-if="showEmpty || loader?.status.value == 'nomore'"
  22. class="loader-view"
  23. >
  24. <Empty
  25. image="search"
  26. :description="emptyView?.text ?? '暂无数据'"
  27. >
  28. <Height :height="20" />
  29. <Button
  30. v-if="emptyView?.button"
  31. type="primary"
  32. :text="emptyView?.buttonText ?? '刷新'"
  33. @click="() => emptyView?.buttonClick ? emptyView?.buttonClick() : handleRetry()"
  34. />
  35. </Empty>
  36. </view>
  37. <image
  38. v-if="lazy && !loaded"
  39. :lazy-load="true"
  40. @load="handleLoad"
  41. @error="handleLoad"
  42. src="https://mn.wenlvti.net/app_static/empty.jpg"
  43. style="width:0px;height:0px"
  44. />
  45. <slot />
  46. </template>
  47. <script setup lang="ts">
  48. import { onMounted, ref, type PropType } from 'vue';
  49. import Empty from '@/components/feedback/Empty.vue';
  50. import Button from '@/components/basic/Button.vue';
  51. import LoadingPage from '@/components/display/loading/LoadingPage.vue';
  52. import Height from '@/components/layout/space/Height.vue';
  53. import type { ILoaderCommon } from '../composeabe/loader/LoaderCommon';
  54. const props = defineProps({
  55. loader: {
  56. type: Object as PropType<ILoaderCommon<any>>,
  57. default: null,
  58. },
  59. lazy: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. autoLoad: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. showEmpty: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. showLoading: {
  72. type: Boolean,
  73. default: true,
  74. },
  75. emptyView: {
  76. type: Object as PropType<{
  77. text: string,
  78. buttonText?: string,
  79. button?: boolean,
  80. buttonClick?: () => void,
  81. }>,
  82. default: null,
  83. },
  84. })
  85. const loaded = ref(false);
  86. onMounted(() => {
  87. loaded.value = false;
  88. if (props.autoLoad)
  89. handleLoad();
  90. });
  91. function handleRetry() {
  92. props.loader.reload();
  93. }
  94. function handleLoad() {
  95. if (loaded.value)
  96. return;
  97. loaded.value = true;
  98. props.loader.reload();
  99. }
  100. </script>
  101. <style lang="scss">
  102. .loader-view {
  103. position: relative;
  104. min-height: 200rpx;
  105. &.center {
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. }
  110. }
  111. </style>