tui-divider.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="tui-divider" :style="{ height: height + 'rpx' }">
  3. <view class="tui-divider-line" :style="{ width: width, background: getBgColor(gradual, gradualColor, dividerColor) }"></view>
  4. <view
  5. class="tui-divider-text"
  6. :style="{ color: color, fontSize: size + 'rpx', lineHeight: size + 'rpx', backgroundColor: backgroundColor, fontWeight: bold ? 'bold' : 'normal' }"
  7. >
  8. <slot></slot>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'tuiDivider',
  15. props: {
  16. //divider占据高度
  17. height: {
  18. type: Number,
  19. default: 100
  20. },
  21. //divider宽度,可填写具体长度,如400rpx
  22. width: {
  23. type: String,
  24. default: '100%'
  25. },
  26. //divider颜色,如果为渐变线条,此属性失效
  27. dividerColor: {
  28. type: String,
  29. default: '#e5e5e5'
  30. },
  31. //文字颜色
  32. color: {
  33. type: String,
  34. default: '#999'
  35. },
  36. //文字大小 rpx
  37. size: {
  38. type: Number,
  39. default: 24
  40. },
  41. bold: {
  42. type: Boolean,
  43. default: false
  44. },
  45. //背景颜色,和当前页面背景色保持一致
  46. backgroundColor: {
  47. type: String,
  48. default: '#fafafa'
  49. },
  50. //是否为渐变线条,为true,divideColor失效
  51. gradual: {
  52. type: Boolean,
  53. default: false
  54. },
  55. //渐变色值,to right ,提供两个色值即可,由浅至深
  56. gradualColor: {
  57. type: Array,
  58. default: function() {
  59. return ['#eee', '#ccc'];
  60. }
  61. }
  62. },
  63. methods: {
  64. getBgColor: function(gradual, gradualColor, dividerColor) {
  65. let bgColor = dividerColor;
  66. if (gradual) {
  67. bgColor = 'linear-gradient(to right,' + gradualColor[0] + ',' + gradualColor[1] + ',' + gradualColor[1] + ',' + gradualColor[0] + ')';
  68. }
  69. return bgColor;
  70. }
  71. }
  72. };
  73. </script>
  74. <style scoped>
  75. .tui-divider {
  76. width: 100%;
  77. position: relative;
  78. text-align: center;
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. box-sizing: border-box;
  83. overflow: hidden;
  84. }
  85. .tui-divider-line {
  86. position: absolute;
  87. height: 1rpx;
  88. top: 50%;
  89. left: 50%;
  90. -webkit-transform: scaleY(0.5) translateX(-50%) translateZ(0);
  91. transform: scaleY(0.5) translateX(-50%) translateZ(0);
  92. }
  93. .tui-divider-text {
  94. position: relative;
  95. text-align: center;
  96. padding: 0 18rpx;
  97. z-index: 1;
  98. }
  99. </style>