o-empty.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view :class="['o-empty']" :style="Bg+Height">
  3. <image :style="ImgSize" :src="Img" mode="aspectFit"></image>
  4. <view class="text">{{text}}</view>
  5. <view class="slot" v-if="$slots.default">
  6. <slot></slot>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'oEmpty',
  13. // #ifdef MP-WEIXIN
  14. options: {
  15. virtualHost: true
  16. },
  17. // #endif
  18. props: {
  19. // img:缺省图片,可选值 error network search,支持传入图片URL
  20. // imgSize:缺省图尺寸,
  21. // text:描述文字,
  22. // bg:背景色
  23. // height:组件占位高度
  24. img: {
  25. type: String,
  26. default: 'e'
  27. },
  28. imgSize: {
  29. type: [String, Number],
  30. default: '320'
  31. },
  32. text: {
  33. type: String,
  34. default: '暂无数据'
  35. },
  36. bg: {
  37. type: String,
  38. default: '#fff'
  39. },
  40. height: {
  41. type: String,
  42. default: 'calc(100vh - 210px)'
  43. }
  44. },
  45. data() {
  46. return {
  47. }
  48. },
  49. methods: {
  50. },
  51. computed: {
  52. Bg() {
  53. return 'backgroundColor:' + this.bg + ';'
  54. },
  55. Height() {
  56. return 'minHeight:' + this.height
  57. },
  58. Img() {
  59. if (['error', 'network', 'search'].includes(this.img)) return require('@/uni_modules/o-empty/static/' +
  60. this.img + '.svg');
  61. else if (this.img.endsWith('.jpg') || this.img.endsWith('.png') || this.img.endsWith('.svg')) return this
  62. .img;
  63. else return require('@/uni_modules/o-empty/static/empty.svg')
  64. },
  65. ImgSize() {
  66. return 'width:' + this.imgSize + 'rpx; height:' + this.imgSize + 'rpx;'
  67. }
  68. },
  69. }
  70. </script>
  71. <style lang="scss">
  72. .o-empty {
  73. // min-height:350rpx;
  74. display: flex;
  75. flex-direction: column;
  76. padding: 64rpx 0 !important;
  77. align-items: center;
  78. justify-content: center;
  79. box-sizing: border-box;
  80. }
  81. .center {
  82. text-align: center;
  83. }
  84. .text {
  85. color: #969798;
  86. padding: 20rpx 0;
  87. }
  88. .slot {
  89. padding-top: 20rpx;
  90. }
  91. </style>