SimplePageContentLoader.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view
  3. v-if="loader?.loadStatus.value == 'loading'"
  4. class="loader-view center"
  5. >
  6. <LoadingPage loadingText="加载中" textSize="18" />
  7. </view>
  8. <view
  9. v-else-if="loader?.loadStatus.value == 'error'"
  10. class="loader-view"
  11. >
  12. <Empty
  13. image="error"
  14. :description="loader.loadError.value"
  15. >
  16. <Height :height="20" />
  17. <Button type="primary" text="刷新" @click="handleRetry" />
  18. </Empty>
  19. </view>
  20. <view
  21. v-if="showEmpty || loader?.loadStatus.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 type { ISimplePageContentLoader } from '../composeabe/SimplePageContentLoader';
  50. import Empty from '@/components/feedback/Empty.vue';
  51. import Button from '@/components/basic/Button.vue';
  52. import LoadingPage from '@/components/display/loading/LoadingPage.vue';
  53. import Height from '@/components/layout/space/Height.vue';
  54. const props = defineProps({
  55. loader: {
  56. type: Object as PropType<ISimplePageContentLoader<any, 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. emptyView: {
  72. type: Object as PropType<{
  73. text: string,
  74. buttonText?: string,
  75. button?: boolean,
  76. buttonClick?: () => void,
  77. }>,
  78. default: null,
  79. },
  80. })
  81. const loaded = ref(false);
  82. onMounted(() => {
  83. loaded.value = false;
  84. if (props.autoLoad)
  85. handleLoad();
  86. });
  87. function handleRetry() {
  88. props.loader.loadData(undefined);
  89. }
  90. function handleLoad() {
  91. if (loaded.value)
  92. return;
  93. loaded.value = true;
  94. props.loader.loadData(undefined);
  95. }
  96. </script>
  97. <style lang="scss">
  98. .loader-view {
  99. min-height: 200rpx;
  100. &.center {
  101. display: flex;
  102. justify-content: center;
  103. align-items: center;
  104. }
  105. }
  106. </style>