tui-divider.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="tui-divider" :style="{ height: height + 'rpx' }">
  3. <view class="tui-divider-line"
  4. :style="{ width: width, background: getBgColor(gradual, gradualColor, dividerColor) }"></view>
  5. <view class="tui-divider-text"
  6. :style="{ color: color, fontSize: size + 'rpx', lineHeight: size + 'rpx', backgroundColor: backgroundColor, fontWeight: bold ? 'bold' : 'normal' }">
  7. <slot></slot>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'tuiDivider',
  14. props: {
  15. //divider占据高度
  16. height: {
  17. type: Number,
  18. default: 100
  19. },
  20. //divider宽度,可填写具体长度,如400rpx
  21. width: {
  22. type: String,
  23. default: '100%'
  24. },
  25. //divider颜色,如果为渐变线条,此属性失效
  26. dividerColor: {
  27. type: String,
  28. default: '#e5e5e5'
  29. },
  30. //文字颜色
  31. color: {
  32. type: String,
  33. default: '#999'
  34. },
  35. //文字大小 rpx
  36. size: {
  37. type: Number,
  38. default: 24
  39. },
  40. bold: {
  41. type: Boolean,
  42. default: false
  43. },
  44. //背景颜色,和当前页面背景色保持一致
  45. backgroundColor: {
  46. type: String,
  47. default: '#fafafa'
  48. },
  49. //是否为渐变线条,为true,divideColor失效
  50. gradual: {
  51. type: Boolean,
  52. default: false
  53. },
  54. //渐变色值,to right ,提供两个色值即可,由浅至深
  55. gradualColor: {
  56. type: Array,
  57. default: function() {
  58. return ['#eee', '#ccc'];
  59. }
  60. }
  61. },
  62. methods: {
  63. getBgColor: function(gradual, gradualColor, dividerColor) {
  64. let bgColor = dividerColor;
  65. if (gradual) {
  66. bgColor = 'linear-gradient(to right,' + gradualColor[0] + ',' + gradualColor[1] + ',' +
  67. 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: 1px;
  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>