tm-more.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view
  3. class="tm-more relative"
  4. :style="{
  5. height: downOpen ? 'auto !important' : `${hs + 40}px`,
  6. paddingBottom: (downOpen && isRemovBar == false) || (show && !isRemovBar) ? '30px' : 0
  7. }"
  8. >
  9. <view class="tm-more-content"><slot></slot></view>
  10. <view v-if="!downOpen&&show&&showMask" :class="[black_tmeme?'bl':'']" class="tm-more-maskbody absolute"></view>
  11. <view
  12. @click="openMore"
  13. v-if="(!downOpen || isRemovBar == false) && show"
  14. :class="[bgColor,'text-'+iconColor,black_tmeme?'bk':'']"
  15. class="tm-more-mask absolute text-align-center text-size-s text-grey flex-center"
  16. >
  17. <slot name="more" :data="downOpen">
  18. <view class="fulled-height flex-center">
  19. <text>{{downOpen?openLabel:label}}</text>
  20. <view class="tm-more-btn px-24" :class="[downOpen?'on':'']">
  21. <tm-icons :size="24" :color="iconColor" name="icon-angle-down"></tm-icons>
  22. </view>
  23. </view>
  24. </slot>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. /**
  30. * 展开更多
  31. * @property {Number} maxHeight = [] 默认:100,限定多高时展示更多按钮,单位upx
  32. * @property {Boolean} disabled = [] 默认:false,是否禁用,禁用后无法展开更多
  33. * @property {Boolean} showMask = [] 默认:false,是否显示内容遮罩。
  34. * @property {Boolean} open = [] 默认:false,需要open.sync,是否展开更多,可不必填此。此值主要是用来手动控制展开和关闭。
  35. * @property {Boolean} isRemovBar = [] 默认:false,打开后,是否隐藏展开更多
  36. * @property {String} icon-color = [] 默认:grey,展开更多的图标颜色。
  37. * @property {String} bg-color = [] 默认:white,展开更多的背景颜色。
  38. * @property {String} label = [] 默认:展开阅读更多,更多的提示文字。
  39. * @property {String} open-label = [] 默认:收缩阅读更多,更多的提示文字。
  40. * @property {Function} click 点击展开更多时触发。
  41. * @property {Function} change 展开更多变换时触发。
  42. */
  43. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  44. export default {
  45. components:{tmIcons},
  46. name: 'tm-more',
  47. props: {
  48. // 限定多高时展示更多按钮。
  49. maxHeight: {
  50. type: Number,
  51. default: 100
  52. },
  53. disabled: {
  54. type: Boolean,
  55. default: false
  56. },
  57. black: {
  58. type: Boolean|String,
  59. default: null
  60. },
  61. // 是否默认打开.可使用open.sync双向绑定。
  62. open: {
  63. type: Boolean,
  64. default: false
  65. },
  66. // 打开后,是否隐藏展开更多
  67. isRemovBar: {
  68. type: Boolean,
  69. default: false
  70. },
  71. iconColor: {
  72. type: String,
  73. default: 'grey'
  74. },
  75. // 展开更多 的背景色彩。
  76. bgColor: {
  77. type: String,
  78. default: 'white'
  79. },
  80. label:{
  81. type: String,
  82. default: '展开阅读更多'
  83. },
  84. openLabel:{
  85. type: String,
  86. default: '收缩阅读更多'
  87. },
  88. showMask:{
  89. type: Boolean|String,
  90. default: false
  91. }
  92. },
  93. watch: {
  94. open: function() {
  95. this.downOpen = this.open;
  96. }
  97. },
  98. data() {
  99. return {
  100. downOpen: false,
  101. show: true
  102. };
  103. },
  104. mounted() {
  105. this.$nextTick(function(){
  106. this.downOpen = this.open;
  107. let t = this;
  108. t.$Querey('.tm-more-content',t).then(syninfo=>{
  109. if (syninfo[0].height - 40 <= t.hs) {
  110. t.show = false;
  111. }
  112. }).catch(e => {});
  113. })
  114. },
  115. computed: {
  116. hs: function() {
  117. return uni.upx2px(this.maxHeight) || 100;
  118. },
  119. black_tmeme: function() {
  120. if (this.black !== null) return this.black;
  121. return this.$tm.vx.state().tmVuetify.black;
  122. }
  123. },
  124. methods: {
  125. openMore() {
  126. this.$emit('click');
  127. if (this.disabled) return;
  128. this.downOpen = !this.downOpen;
  129. this.$emit('change', this.downOpen);
  130. this.$emit('update:open', this.downOpen);
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="less" scoped>
  136. .tm-more {
  137. overflow: hidden;
  138. .tm-more-content {
  139. overflow: hidden;
  140. }
  141. .tm-more-maskbody{
  142. height: calc(100% - 40px);
  143. bottom: 40px;
  144. z-index: 10;
  145. width: 100%;
  146. background-image: linear-gradient(rgba(255,255,255,0) ,rgba(255,255,255,1));
  147. &.bl{
  148. background-image: linear-gradient(rgba(0,0,0,0) 30%,rgba(0,0,0,1)) !important;
  149. }
  150. }
  151. .tm-more-mask {
  152. bottom: 0;
  153. width: 100%;
  154. height: 40px;
  155. z-index: 10;
  156. .tm-more-btn{
  157. &.on{
  158. transition: all 0.35s;
  159. transform: rotate(180deg);
  160. }
  161. }
  162. }
  163. }
  164. </style>