u-divider.vue 3.2 KB

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