tm-divider.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="tm-divider ">
  3. <view class="flex-center tm-divider-wk" :class="[
  4. vertical?' flex-col flexVer ':'',setpsClass
  5. ]" >
  6. <view :style="{
  7. borderBottomStyle:model,
  8. height:vertical?height/2+'px':'1rpx',
  9. width:vertical?'1rpx':'50%',
  10. }" class="tm-divider-left" :class="[vertical?color_tmeme:`border-${color_tmeme}-b-1`]">
  11. </view>
  12. <view v-if="text" :class="[
  13. vertical?'py-20':'px-20'
  14. ]" class="tm-divider-text text-size-xs" :style="{color:'grey'}">{{text}}</view>
  15. <!-- 点位符。 -->
  16. <text v-if="!text"></text>
  17. <view :style="{
  18. borderBottomStyle:model,
  19. height:vertical?(height/2+'px'):'1rpx',
  20. width:vertical?'1rpx':'50%',
  21. }" class="tm-divider-right" :class="[vertical?color_tmeme:`border-${color_tmeme}-b-1`]"></view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. /**
  27. * 分割线
  28. * @property {String} text = [] 默认:'',显示的文本。
  29. * @property {String} color = [] 默认:'#eeeeee',线的颜色16进制或者rgb,rgba
  30. * @property {Number} height = [] 默认:0, 竖向高度时,起作用。
  31. * @property {Boolean} vertical = [] 默认:false, 是否竖向
  32. * @property {String} model = [solid|dashed|dotted] 默认:solid, 线的类型。
  33. * @example <tm-divider text="我是分割线"></tm-divider>
  34. */
  35. export default {
  36. name: "tm-divider",
  37. props: {
  38. // 不为空时,显示文本。
  39. text: {
  40. type: String,
  41. default: ''
  42. },
  43. // 颜色16进制或者rgb,rgba
  44. color: {
  45. type: String,
  46. default: 'grey'
  47. },
  48. // 竖向高度时,起作用。
  49. height: {
  50. type: Number,
  51. default: 100
  52. },
  53. // 竖向高度时,起作用。
  54. width: {
  55. type: Number,
  56. default: 0
  57. },
  58. // 是否竖
  59. vertical: {
  60. type: Boolean,
  61. default: false
  62. },
  63. // solid|dashed|dotted
  64. model: {
  65. type: String,
  66. default: 'solid'
  67. },
  68. // 跟随主题色的改变而改变。
  69. fllowTheme: {
  70. type: Boolean | String,
  71. default: false
  72. }
  73. },
  74. computed: {
  75. wd: {
  76. get: function() {
  77. if (this.width) return this.width;
  78. return this.width_s;
  79. },
  80. set: function(val) {
  81. this.width_s = val;
  82. }
  83. },
  84. color_tmeme: function() {
  85. if (this.$tm.vx.state().tmVuetify.color !== null && this.$tm.vx.state().tmVuetify.color && this
  86. .fllowTheme) {
  87. return this.$tm.vx.state().tmVuetify.color;
  88. }
  89. return this.color;
  90. },
  91. },
  92. data() {
  93. return {
  94. width_s: 0,
  95. height_s: 0,
  96. setpsClass: ''
  97. };
  98. },
  99. async mounted() {
  100. await this.init();
  101. },
  102. methods: {
  103. async init() {
  104. this.$nextTick(async function() {
  105. let tbs = await this.$Querey(".tm-divider");
  106. this.wd = tbs[0].width ? tbs[0].width : this.wd;
  107. })
  108. },
  109. setWidth(width) {
  110. this.$nextTick(async function() {
  111. this.wd = width;
  112. this.setpsClass = 'setpsClass'
  113. if (this.text) {
  114. let tbs_text = await this.$Querey(".tm-divider-text");
  115. this.wd = this.wd - tbs_text[0].width;
  116. }
  117. })
  118. }
  119. },
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .tm-divider {
  124. display: block;
  125. width: auto;
  126. position: relative;
  127. .tm-divider-wk {
  128. &.setpsClass {
  129. position: absolute;
  130. // left: -100upx;
  131. line-height: 0;
  132. // left: 0;
  133. }
  134. }
  135. .flexVer {
  136. width: 1px;
  137. }
  138. .tm-divider-text {
  139. flex-shrink: 0;
  140. }
  141. .tm-divider-left,
  142. .tm-divider-right {
  143. width: 50%;
  144. height: 1px;
  145. border-bottom-width: 1px;
  146. }
  147. }
  148. </style>