index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="empty-state" :style="containerStyle">
  3. <!-- 空状态图标 -->
  4. <view class="empty-icon-box" :style="iconBoxStyle">
  5. <image
  6. v-if="image"
  7. class="empty-image"
  8. :src="image"
  9. mode="aspectFit"
  10. />
  11. <uni-icons
  12. v-else
  13. :type="icon"
  14. :size="iconSize"
  15. :color="iconColor"
  16. ></uni-icons>
  17. </view>
  18. <!-- 提示文字 -->
  19. <text class="empty-text" :style="textStyle">{{ text }}</text>
  20. <!-- 副文字(可选) -->
  21. <text v-if="subText" class="empty-sub-text">{{ subText }}</text>
  22. <!-- 操作按钮(可选) -->
  23. <view v-if="showBtn" class="empty-btn" :style="btnStyle" @click="handleClick">
  24. <text class="empty-btn-text">{{ btnText }}</text>
  25. </view>
  26. </view>
  27. </template>
  28. <script setup>
  29. import { computed } from 'vue'
  30. const props = defineProps({
  31. // 提示文字
  32. text: {
  33. type: String,
  34. default: '暂无数据'
  35. },
  36. // 副文字
  37. subText: {
  38. type: String,
  39. default: ''
  40. },
  41. // 图标名称(uni-icons type)
  42. icon: {
  43. type: String,
  44. default: 'list'
  45. },
  46. // 图标大小
  47. iconSize: {
  48. type: Number,
  49. default: 80
  50. },
  51. // 图标颜色
  52. iconColor: {
  53. type: String,
  54. default: '#CCCCCC'
  55. },
  56. // 自定义图片(优先级高于icon)
  57. image: {
  58. type: String,
  59. default: '/static/image/public/no-data.png'
  60. },
  61. // 是否显示按钮
  62. showBtn: {
  63. type: Boolean,
  64. default: false
  65. },
  66. // 按钮文字
  67. btnText: {
  68. type: String,
  69. default: '刷新'
  70. },
  71. // 按钮颜色
  72. btnColor: {
  73. type: String,
  74. default: '#4080FF'
  75. },
  76. // 上边距(rpx)
  77. marginTop: {
  78. type: Number,
  79. default: 120
  80. },
  81. // 下边距(rpx)
  82. marginBottom: {
  83. type: Number,
  84. default: 0
  85. }
  86. })
  87. const emit = defineEmits(['click'])
  88. const containerStyle = computed(() => {
  89. return {
  90. marginTop: (props.marginTop / 2) + 'px',
  91. marginBottom: (props.marginBottom / 2) + 'px'
  92. }
  93. })
  94. const iconBoxStyle = computed(() => {
  95. return {
  96. width: (props.iconSize * 1.5 / 2) + 'px',
  97. height: (props.iconSize * 1.5 / 2) + 'px'
  98. }
  99. })
  100. const textStyle = computed(() => {
  101. return {
  102. color: '#999999'
  103. }
  104. })
  105. const btnStyle = computed(() => {
  106. return {
  107. backgroundColor: props.btnColor
  108. }
  109. })
  110. const handleClick = () => {
  111. emit('click')
  112. }
  113. </script>
  114. <style scoped>
  115. .empty-state {
  116. display: flex;
  117. flex-direction: column;
  118. align-items: center;
  119. justify-content: center;
  120. padding: 60rpx 40rpx;
  121. }
  122. .empty-icon-box {
  123. display: flex;
  124. align-items: center;
  125. justify-content: center;
  126. margin-bottom: 32rpx;
  127. border-radius: 50%;
  128. background: #f5f6f8;
  129. }
  130. .empty-image {
  131. width: 100%;
  132. height: 100%;
  133. }
  134. .empty-text {
  135. font-size: 28rpx;
  136. color: #999999;
  137. line-height: 1.5;
  138. text-align: center;
  139. }
  140. .empty-sub-text {
  141. font-size: 24rpx;
  142. color: #BBBBBB;
  143. margin-top: 12rpx;
  144. text-align: center;
  145. line-height: 1.5;
  146. }
  147. .empty-btn {
  148. margin-top: 40rpx;
  149. padding: 16rpx 56rpx;
  150. border-radius: 40rpx;
  151. display: flex;
  152. align-items: center;
  153. justify-content: center;
  154. }
  155. .empty-btn-text {
  156. font-size: 28rpx;
  157. color: #FFFFFF;
  158. font-weight: 500;
  159. }
  160. </style>