uv-empty.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="uv-empty" :style="[emptyStyle]" v-if="show">
  3. <uv-icon v-if="!isImg" :name="mode === 'message' ? 'chat' : `empty-${mode}`" :size="iconSize" :color="iconColor"
  4. margin-top="14"></uv-icon>
  5. <image v-else :style="{
  6. width: $uv.addUnit(width),
  7. height: $uv.addUnit(height)
  8. }" :src="icon" mode="widthFix"></image>
  9. <text class="uv-empty__text" :style="[textStyle]">{{text ? text : icons[mode]}}</text>
  10. <view class="uv-empty__wrap">
  11. <slot />
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  17. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  18. import props from './props.js';
  19. /**
  20. * empty 内容为空
  21. * @description 该组件用于需要加载内容,但是加载的第一页数据就为空,提示一个"没有内容"的场景, 我们精心挑选了十几个场景的图标,方便您使用。
  22. * @tutorial https://www.uvui.cn/components/empty.html
  23. * @property {String} icon 内置图标名称,或图片路径,建议绝对路径
  24. * @property {String} text 提示文字
  25. * @property {String} textColor 文字颜色 (默认 '#c0c4cc' )
  26. * @property {String | Number} textSize 文字大小 (默认 14 )
  27. * @property {String} iconColor 图标的颜色 (默认 '#c0c4cc' )
  28. * @property {String | Number} iconSize 图标的大小 (默认 90 )
  29. * @property {String} mode 选择预置的图标类型 (默认 'data' )
  30. * @property {String | Number} width 图标宽度,单位px (默认 160 )
  31. * @property {String | Number} height 图标高度,单位px (默认 160 )
  32. * @property {Boolean} show 是否显示组件 (默认 true )
  33. * @property {String | Number} marginTop 组件距离上一个元素之间的距离,默认px单位 (默认 0 )
  34. * @property {Object} customStyle 定义需要用到的外部样式
  35. *
  36. * @event {Function} click 点击组件时触发
  37. * @event {Function} close 点击关闭按钮时触发
  38. * @example <uv-empty text="所谓伊人,在水一方" mode="list"></uv-empty>
  39. */
  40. export default {
  41. name: "uv-empty",
  42. mixins: [mpMixin, mixin, props],
  43. data() {
  44. return {
  45. icons: {
  46. car: '购物车为空',
  47. page: '页面不存在',
  48. search: '没有搜索结果',
  49. address: '没有收货地址',
  50. 'wifi-off': '没有WiFi',
  51. order: '订单为空',
  52. coupon: '没有优惠券',
  53. favor: '暂无收藏',
  54. permission: '无权限',
  55. history: '无历史记录',
  56. news: '无新闻列表',
  57. message: '消息列表为空',
  58. list: '列表为空',
  59. data: '数据为空',
  60. comment: '暂无评论',
  61. }
  62. }
  63. },
  64. computed: {
  65. // 组件样式
  66. emptyStyle() {
  67. const style = {}
  68. style.marginTop = this.$uv.addUnit(this.marginTop)
  69. // 合并customStyle样式,此参数通过mixin中的props传递
  70. return this.$uv.deepMerge(style, this.$uv.addStyle(this.customStyle))
  71. },
  72. // 文本样式
  73. textStyle() {
  74. const style = {}
  75. style.color = this.textColor
  76. style.fontSize = this.$uv.addUnit(this.textSize)
  77. return style
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  84. $uv-empty-text-margin-top: 20rpx !default;
  85. $uv-empty-slot-margin-top: 20rpx !default;
  86. .uv-empty {
  87. @include flex;
  88. flex-direction: column;
  89. justify-content: center;
  90. align-items: center;
  91. &__text {
  92. @include flex;
  93. justify-content: center;
  94. align-items: center;
  95. margin-top: $uv-empty-text-margin-top;
  96. }
  97. }
  98. .uv-slot-wrap {
  99. @include flex;
  100. justify-content: center;
  101. align-items: center;
  102. margin-top: $uv-empty-slot-margin-top;
  103. }
  104. </style>