u-divider.vue 4.2 KB

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