BaseEmpty.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="base-empty" :class="{ 'base-empty--compact': compact }">
  3. <!-- 图标:slot > 默认内联 SVG;icon 属性为旧调用方文本兜底(不新建 emoji) -->
  4. <view class="base-empty__icon" v-if="hasIcon">
  5. <slot name="icon" v-if="$slots.icon"></slot>
  6. <svg
  7. v-else-if="!icon"
  8. class="base-empty__svg"
  9. viewBox="0 0 48 48"
  10. width="80rpx"
  11. height="80rpx"
  12. aria-hidden="true"
  13. >
  14. <circle cx="24" cy="24" r="22" fill="currentColor" opacity="0.12"></circle>
  15. <path
  16. d="M24 12c-6 0-10 4.2-10 9.6 0 6.8 6.4 11.6 10 14.4 3.6-2.8 10-7.6 10-14.4C34 16.2 30 12 24 12z"
  17. fill="currentColor"
  18. ></path>
  19. </svg>
  20. <text v-else class="base-empty__glyph">{{ icon }}</text>
  21. </view>
  22. <text class="base-empty__title" v-if="title">{{ title }}</text>
  23. <text class="base-empty__description" v-if="description">{{ description }}</text>
  24. <view class="base-empty__action" v-if="$slots.action">
  25. <slot name="action"></slot>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'BaseEmpty',
  32. props: {
  33. icon: { type: String, default: '' },
  34. title: { type: String, default: '' },
  35. description: { type: String, default: '' },
  36. compact: { type: Boolean, default: false }
  37. },
  38. computed: {
  39. hasIcon() {
  40. return !!this.icon || !!this.$slots.icon
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped lang="scss">
  46. .base-empty {
  47. display: flex;
  48. flex-direction: column;
  49. align-items: center;
  50. justify-content: center;
  51. padding: 80rpx 32rpx;
  52. min-height: 400rpx;
  53. }
  54. .base-empty--compact {
  55. padding: 48rpx 32rpx;
  56. min-height: auto;
  57. }
  58. .base-empty__icon {
  59. margin-bottom: 24rpx;
  60. color: $uni-primary;
  61. }
  62. .base-empty__svg {
  63. display: block;
  64. }
  65. .base-empty__glyph {
  66. font-size: calc(80rpx * var(--font-scale, 1));
  67. display: block;
  68. text-align: center;
  69. }
  70. .base-empty__title {
  71. font-size: calc(30rpx * var(--font-scale, 1));
  72. font-weight: 600;
  73. color: $uni-text-color;
  74. margin-bottom: 12rpx;
  75. text-align: center;
  76. }
  77. .base-empty__description {
  78. font-size: calc(26rpx * var(--font-scale, 1));
  79. color: $uni-text-color-secondary;
  80. text-align: center;
  81. line-height: 1.6;
  82. max-width: 500rpx;
  83. }
  84. .base-empty__action {
  85. margin-top: 32rpx;
  86. }
  87. </style>