cl-empty.uvue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view
  3. class="cl-empty"
  4. :class="[
  5. {
  6. 'cl-empty--fixed': fixed
  7. },
  8. pt.className
  9. ]"
  10. >
  11. <image
  12. class="cl-empty__icon"
  13. :src="`/static/empty/${icon}.png`"
  14. :style="{
  15. height: parseRpx(iconSize)
  16. }"
  17. mode="aspectFit"
  18. v-if="showIcon"
  19. ></image>
  20. <cl-text
  21. :pt="{
  22. className: parseClass([
  23. 'cl-empty__text',
  24. {
  25. 'text-surface-100': isDark
  26. }
  27. ])
  28. }"
  29. v-if="text"
  30. >{{ text }}</cl-text
  31. >
  32. </view>
  33. </template>
  34. <script lang="ts" setup>
  35. import { t } from "@/locale";
  36. import { isDark, parseClass, parsePt, parseRpx } from "@/cool";
  37. import { computed } from "vue";
  38. // 组件属性定义
  39. const props = defineProps({
  40. // 透传样式配置
  41. pt: {
  42. type: Object,
  43. default: () => ({})
  44. },
  45. // 空状态文本
  46. text: {
  47. type: String,
  48. default: () => t("暂无数据")
  49. },
  50. // 空状态图标名称
  51. icon: {
  52. type: String,
  53. default: "comm"
  54. },
  55. // 图标尺寸
  56. iconSize: {
  57. type: [Number, String],
  58. default: 120
  59. },
  60. // 是否显示图标
  61. showIcon: {
  62. type: Boolean,
  63. default: true
  64. },
  65. // 是否固定定位
  66. fixed: {
  67. type: Boolean,
  68. default: true
  69. }
  70. });
  71. // 透传样式类型定义
  72. type PassThrough = {
  73. className?: string; // 根元素类名
  74. };
  75. // 解析透传样式配置
  76. const pt = computed(() => parsePt<PassThrough>(props.pt));
  77. </script>
  78. <style lang="scss" scoped>
  79. .cl-empty {
  80. @apply flex flex-col items-center justify-center w-full h-full;
  81. pointer-events: none;
  82. &--fixed {
  83. @apply fixed top-0 left-0;
  84. z-index: -1;
  85. // #ifdef H5
  86. z-index: 0;
  87. // #endif
  88. }
  89. &__icon {
  90. margin-bottom: 20rpx;
  91. }
  92. &__text {
  93. @apply text-surface-400 text-sm;
  94. }
  95. }
  96. </style>