综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uv-empty.vue 3.9KB

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