u-divider.vue 3.1 KB

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