SimplePageContentLoader.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view
  3. v-if="loader?.loadStatus.value == 'loading'"
  4. style="min-height: 200rpx;display: flex;justify-content: center;align-items: center;"
  5. >
  6. <u-loading-icon text="加载中" textSize="18" />
  7. </view>
  8. <view
  9. v-else-if="loader?.loadStatus.value == 'error'"
  10. style="min-height: 200rpx"
  11. >
  12. <u-empty
  13. mode="page"
  14. :text="loader.loadError.value"
  15. />
  16. <view style="margin-top: 20rpx">
  17. <u-row justify="center">
  18. <u-col span="3">
  19. <u-button text="重试" @click="handleRetry" />
  20. </u-col>
  21. </u-row>
  22. </view>
  23. </view>
  24. <template v-else-if="loader?.loadStatus.value == 'finished' || loader?.loadStatus.value == 'nomore'">
  25. <slot />
  26. </template>
  27. <view
  28. v-if="showEmpty || loader?.loadStatus.value == 'nomore'"
  29. style="min-height: 200rpx"
  30. >
  31. <u-empty
  32. mode="data"
  33. :text="emptyView?.text ?? '暂无数据'"
  34. />
  35. <view v-if="emptyView?.button" style="margin-top: 20rpx">
  36. <u-row justify="center">
  37. <u-col span="3">
  38. <u-button
  39. :text="emptyView?.buttonText ?? '刷新'"
  40. @click="emptyView?.buttonClick ?? handleRetry"
  41. />
  42. </u-col>
  43. </u-row>
  44. </view>
  45. </view>
  46. <image
  47. v-if="lazy && !loaded"
  48. :lazy-load="true"
  49. @load="handleLoad"
  50. @error="handleLoad"
  51. src="https://mn.wenlvti.net/uploads/20250313/46adb2f039c6f23a3e69149526eb7e61.png"
  52. style="width:0px;height:0px"
  53. />
  54. </template>
  55. <script setup lang="ts">
  56. import { onMounted, ref, type PropType } from 'vue';
  57. import type { ISimplePageContentLoader } from '../composeabe/SimplePageContentLoader';
  58. const props = defineProps({
  59. loader: {
  60. type: Object as PropType<ISimplePageContentLoader<any, any>>,
  61. default: null,
  62. },
  63. lazy: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. autoLoad: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. auotEmpty: {
  72. type: Boolean,
  73. default: false,
  74. },
  75. showEmpty: {
  76. type: Boolean,
  77. default: false,
  78. },
  79. emptyView: {
  80. type: Object as PropType<{
  81. text: string,
  82. buttonText: string,
  83. button: boolean,
  84. buttonClick: () => void,
  85. }>,
  86. default: null,
  87. },
  88. })
  89. const loaded = ref(false);
  90. onMounted(() => {
  91. loaded.value = false;
  92. if (props.autoLoad)
  93. handleLoad();
  94. });
  95. function handleRetry() {
  96. props.loader.loadData(undefined);
  97. }
  98. function handleLoad() {
  99. if (loaded.value)
  100. return;
  101. loaded.value = true;
  102. props.loader.loadData(undefined);
  103. }
  104. </script>