divider.vue 2.2 KB

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