u-divider.vue 3.2 KB

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