u-divider.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view>
  3. <view @tap="click"
  4. class="carNone" v-if="isnone" >
  5. <!-- <img src="@/assets/img/暂无数据-缺省页.png" alt=""> -->
  6. <view :style=" 'margin-top: '+nonetop+'px; margin-bottom: 40px;'">
  7. <u-empty :text="nonetext" mode="search"></u-empty>
  8. </view>
  9. <!-- <p v-text="nonetext" ></p> -->
  10. </view>
  11. <view class="u-divider" v-else :style="{
  12. height: height == 'auto' ? 'auto' : height + 'rpx',
  13. backgroundColor: bgColor,
  14. marginBottom: marginBottom + 'rpx',
  15. marginTop: marginTop + 'rpx'
  16. }" @tap="click">
  17. <view class="u-divider-line" :class="[type ? 'u-divider-line--bordercolor--' + type : '']" :style="[lineStyle]"></view>
  18. <view v-if="useSlot" class="u-divider-text" :style="{
  19. color: color,
  20. fontSize: fontSize + 'rpx'
  21. }"><slot /></view>
  22. <view class="u-divider-line" :class="[type ? 'u-divider-line--bordercolor--' + type : '']" :style="[lineStyle]"></view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. /**
  28. * divider 分割线
  29. * @description 区隔内容的分割线,一般用于页面底部"没有更多"的提示。
  30. * @tutorial https://www.uviewui.com/components/divider.html
  31. * @property {String Number} half-width 文字左或右边线条宽度,数值或百分比,数值时单位为rpx
  32. * @property {String} border-color 线条颜色,优先级高于type(默认#dcdfe6)
  33. * @property {String} color 文字颜色(默认#909399)
  34. * @property {String Number} fontSize 字体大小,单位rpx(默认26)
  35. * @property {String} bg-color 整个divider的背景颜色(默认呢#ffffff)
  36. * @property {String Number} height 整个divider的高度,单位rpx(默认40)
  37. * @property {String} type 将线条设置主题色(默认primary)
  38. * @property {Boolean} useSlot 是否使用slot传入内容,如果不传入,中间不会有空隙(默认true)
  39. * @property {String Number} margin-top 与前一个组件的距离,单位rpx(默认0)
  40. * @property {String Number} margin-bottom 与后一个组件的距离,单位rpx(0)
  41. * @event {Function} click divider组件被点击时触发
  42. * @example <u-divider color="#fa3534">长河落日圆</u-divider>
  43. */
  44. export default {
  45. name: 'u-divider',
  46. props: {
  47. isnone:{
  48. //是否列表显示为空
  49. type: Boolean,
  50. default:false,
  51. },
  52. nonetext: {
  53. //列表显示为空显示文字
  54. type: String,
  55. default: '没有找到相关内容'
  56. },
  57. nonetop: {
  58. //列表显示为空显示文字
  59. type: Number,
  60. default: 80
  61. },
  62. // 单一边divider横线的宽度(数值),单位rpx。或者百分比
  63. halfWidth: {
  64. type: [Number, String],
  65. default: 150
  66. },
  67. // divider横线的颜色,如设置,
  68. borderColor: {
  69. type: String,
  70. default: '#dcdfe6'
  71. },
  72. // 主题色,可以是primary|info|success|warning|error之一值
  73. type: {
  74. type: String,
  75. default: 'primary'
  76. },
  77. // 文字颜色
  78. color: {
  79. type: String,
  80. default: '#909399'
  81. },
  82. // 文字大小,单位rpx
  83. fontSize: {
  84. type: [Number, String],
  85. default: 26
  86. },
  87. // 整个divider的背景颜色
  88. bgColor: {
  89. type: String,
  90. default: ''
  91. },
  92. // 整个divider的高度单位rpx
  93. height: {
  94. type: [Number, String],
  95. default: 'auto'
  96. },
  97. // 上边距
  98. marginTop: {
  99. type: [String, Number],
  100. default: 0
  101. },
  102. // 下边距
  103. marginBottom: {
  104. type: [String, Number],
  105. default: 0
  106. },
  107. // 是否使用slot传入内容,如果不用slot传入内容,先的中间就不会有空隙
  108. useSlot: {
  109. type: Boolean,
  110. default: true
  111. }
  112. },
  113. computed: {
  114. lineStyle() {
  115. let style = {};
  116. if(String(this.halfWidth).indexOf('%') != -1) style.width = this.halfWidth;
  117. else style.width = this.halfWidth + 'rpx';
  118. // borderColor优先级高于type值
  119. if(this.borderColor) style.borderColor = this.borderColor;
  120. return style;
  121. }
  122. },
  123. methods: {
  124. click() {
  125. this.$emit('click');
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. @import "../../libs/css/style.components.scss";
  132. .u-divider {
  133. width: 100%;
  134. position: relative;
  135. text-align: center;
  136. @include vue-flex;
  137. justify-content: center;
  138. align-items: center;
  139. overflow: hidden;
  140. flex-direction: row;
  141. }
  142. .u-divider-line {
  143. border-bottom: 1px solid $u-border-color;
  144. transform: scale(1, 0.5);
  145. transform-origin: center;
  146. &--bordercolor--primary {
  147. border-color: $u-type-primary;
  148. }
  149. &--bordercolor--success {
  150. border-color: $u-type-success;
  151. }
  152. &--bordercolor--error {
  153. border-color: $u-type-primary;
  154. }
  155. &--bordercolor--info {
  156. border-color: $u-type-info;
  157. }
  158. &--bordercolor--warning {
  159. border-color: $u-type-warning;
  160. }
  161. }
  162. .u-divider-text {
  163. white-space: nowrap;
  164. padding: 0 16rpx;
  165. /* #ifndef APP-NVUE */
  166. display: inline-flex;
  167. /* #endif */
  168. }
  169. .carNone{
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. align-items: center;
  174. img{
  175. width: 100%;
  176. height: 100%;
  177. }
  178. p{
  179. margin-top: -60px;
  180. }
  181. }
  182. </style>