u-empty.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="u-empty" v-if="show" :style="{
  3. marginTop: marginTop + 'rpx'
  4. }">
  5. <image class="u-image" :src="src ? src : icons[mode].image" mode="widthFix" :style="{
  6. width: imgWidth + 'rpx',
  7. height: imgHeight == 'auto' ? 'auto' : imgHeight + 'rpx'
  8. }"></image>
  9. <text :style="{
  10. color: color,
  11. fontSize: fontSize + 'rpx',
  12. }">
  13. {{text ? text : icons[mode].text}}
  14. </text>
  15. <view class="u-slot-wrap">
  16. <slot name="bottom"></slot>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import icon from "./icon.js";
  22. /**
  23. * empty 内容为空
  24. * @description 该组件用于需要加载内容,但是加载的第一页数据就为空,提示一个"没有内容"的场景, 我们精心挑选了十几个场景的图标,方便您使用。
  25. * @tutorial https://www.uviewui.com/components/empty.html
  26. * @property {String} color 文字颜色(默认#c0c4cc)
  27. * @property {String} text 文字提示(默认“无内容”)
  28. * @property {String} src 自定义图标路径,如定义,mode参数会失效
  29. * @property {String Number} font-size 提示文字的大小,单位rpx(默认28)
  30. * @property {String} mode 内置的图标,见官网说明(默认data)
  31. * @property {String Number} img-width 图标的宽度,单位rpx(默认240)
  32. * @property {String} img-height 图标的高度,单位rpx(默认auto)
  33. * @property {String Number} margin-top 组件距离上一个元素之间的距离(默认0)
  34. * @property {Boolean} show 是否显示组件(默认true)
  35. * @event {Function} click 点击组件时触发
  36. * @event {Function} close 点击关闭按钮时触发
  37. * @example <u-empty text="所谓伊人,在水一方" mode="list"></u-empty>
  38. */
  39. export default {
  40. name: "u-empty",
  41. props: {
  42. // 图标路径
  43. src: {
  44. type: String,
  45. default: ''
  46. },
  47. // 提示文字
  48. text: {
  49. type: String,
  50. default: ''
  51. },
  52. // 文字颜色
  53. color: {
  54. type: String,
  55. default: '#c0c4cc'
  56. },
  57. // 文字大小,单位rpx
  58. fontSize: {
  59. type: [String, Number],
  60. default: 26
  61. },
  62. // 选择预置的图标类型
  63. mode: {
  64. type: String,
  65. default: 'data'
  66. },
  67. // 图标宽度,单位rpx
  68. imgWidth: {
  69. type: [String, Number],
  70. default: 240
  71. },
  72. // 图标高度,单位rpx
  73. imgHeight: {
  74. type: [String, Number],
  75. default: 'auto'
  76. },
  77. // 是否显示组件
  78. show: {
  79. type: Boolean,
  80. default: true
  81. },
  82. // 组件距离上一个元素之间的距离
  83. marginTop: {
  84. type: [String, Number],
  85. default: 0
  86. }
  87. },
  88. data() {
  89. return {
  90. icons: icon
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .u-empty {
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: center;
  100. align-items: center;
  101. height: 100%;
  102. }
  103. .u-image {
  104. margin-bottom: 20rpx;
  105. }
  106. .u-slot-wrap {
  107. display: flex;
  108. justify-content: center;
  109. align-items: center;
  110. margin-top: 20rpx;
  111. }
  112. </style>