u-divider.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="u-divider" :style="[$u.addStyle(customStyle)]" @tap="click">
  3. <u-line :color="lineColor" :customStyle="leftLineStyle" :hairline="hairline" :dashed="dashed"></u-line>
  4. <text v-if="dot" class="u-divider__dot">●</text>
  5. <text v-else-if="text" class="u-divider__text" :style="[textStyle]">{{ text }}</text>
  6. <slot></slot>
  7. <u-line :color="lineColor" :customStyle="rightLineStyle" :hairline="hairline" :dashed="dashed"></u-line>
  8. </view>
  9. </template>
  10. <script>
  11. import props from './props.js';
  12. import mixin from '../../libs/mixin/mixin'
  13. import mpMixin from '../../libs/mixin/mpMixin';
  14. /**
  15. * divider 分割线
  16. * @description 区隔内容的分割线,一般用于页面底部"没有更多"的提示。
  17. * @tutorial https://uview.d3u.cn/components/divider.html
  18. * @property {Boolean} dashed 是否虚线 (默认 false )
  19. * @property {Boolean} hairline 是否细线 (默认 true )
  20. * @property {Boolean} dot 是否以点替代文字,优先于text字段起作用 (默认 false )
  21. * @property {String} position 内容文本的位置,left-左边,center-中间,right-右边 (默认 'center' )
  22. * @property {String | Number} text 文本内容
  23. * @property {Boolean} bold 是否加粗 (默认 false )
  24. * @property {String | Number} size 文本大小 (默认 14)
  25. * @property {String} color 文本颜色 (默认 '#909399' )
  26. * @property {String} lineColor 线条颜色 (默认 '#dcdfe6' )
  27. * @property {Object} customStyle 定义需要用到的外部样式
  28. *
  29. * @event {Function} click divider组件被点击时触发
  30. * @example <u-divider :color="color">锦瑟无端五十弦</u-divider>
  31. */
  32. export default {
  33. name: 'u-divider',
  34. mixins: [mpMixin, mixin, props],
  35. computed: {
  36. textStyle() {
  37. const style = {}
  38. style.fontSize = uni.$u.addUnit(this.size)
  39. style.color = this.color
  40. style.fontWeight = this.bold ? 'bold' : 'normal'
  41. return style
  42. },
  43. // 左边线条的的样式
  44. leftLineStyle() {
  45. const style = {}
  46. // 如果是在左边,设置左边的宽度为固定值
  47. if (this.position === 'left') {
  48. style.width = '80rpx'
  49. } else {
  50. style.flex = 1
  51. }
  52. return style
  53. },
  54. // 右边线条的的样式
  55. rightLineStyle() {
  56. const style = {}
  57. // 如果是在右边,设置右边的宽度为固定值
  58. if (this.position === 'right') {
  59. style.width = '80rpx'
  60. } else {
  61. style.flex = 1
  62. }
  63. return style
  64. }
  65. },
  66. // #ifdef VUE3
  67. emits: ["click"],
  68. // #endif
  69. methods: {
  70. // divider组件被点击时触发
  71. click() {
  72. this.$emit('click');
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. @import '../../libs/css/components.scss';
  79. $u-divider-margin: 15px 0 !default;
  80. $u-divider-text-margin: 0 15px !default;
  81. $u-divider-dot-font-size: 12px !default;
  82. $u-divider-dot-margin: 0 12px !default;
  83. $u-divider-dot-color: #c0c4cc !default;
  84. .u-divider {
  85. @include flex;
  86. flex-direction: row;
  87. align-items: center;
  88. margin: $u-divider-margin;
  89. &__text {
  90. margin: $u-divider-text-margin;
  91. }
  92. &__dot {
  93. font-size: $u-divider-dot-font-size;
  94. margin: $u-divider-dot-margin;
  95. color: $u-divider-dot-color;
  96. }
  97. }
  98. </style>