cl-empty.uvue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: getUnit(iconSize)
  16. }"
  17. mode="aspectFit"
  18. v-if="showIcon"
  19. ></image>
  20. <cl-text
  21. :pt="{
  22. className: parseClass([
  23. 'cl-empty__text text-surface-400 mt-1',
  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 { isDark, parseClass, parsePt, getUnit, t } from "@/.cool";
  36. import { computed } from "vue";
  37. // 组件属性定义
  38. const props = defineProps({
  39. // 透传样式配置
  40. pt: {
  41. type: Object,
  42. default: () => ({})
  43. },
  44. // 空状态文本
  45. text: {
  46. type: String,
  47. default: () => t("暂无数据")
  48. },
  49. // 空状态图标名称
  50. icon: {
  51. type: String,
  52. default: "comm"
  53. },
  54. // 图标尺寸
  55. iconSize: {
  56. type: [Number, String],
  57. default: 60
  58. },
  59. // 是否显示图标
  60. showIcon: {
  61. type: Boolean,
  62. default: true
  63. },
  64. // 是否固定定位
  65. fixed: {
  66. type: Boolean,
  67. default: true
  68. }
  69. });
  70. // 透传样式类型定义
  71. type PassThrough = {
  72. className?: string; // 根元素类名
  73. };
  74. // 解析透传样式配置
  75. const pt = computed(() => parsePt<PassThrough>(props.pt));
  76. </script>
  77. <style lang="scss" scoped>
  78. .cl-empty {
  79. @apply flex flex-col items-center justify-center w-full h-full;
  80. pointer-events: none;
  81. &--fixed {
  82. @apply fixed top-0 left-0;
  83. z-index: -1;
  84. // #ifdef H5
  85. z-index: 0;
  86. // #endif
  87. // #ifndef H5
  88. padding-top: -44px;
  89. // #endif
  90. }
  91. &__icon {
  92. margin-bottom: 10px;
  93. }
  94. }
  95. </style>