uni-events-helper-wx
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.0 KiB

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