cl-empty.uvue 1.5 KB

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