fs-readmore.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view
  3. class="fs-readmore"
  4. :style="{height: isOpen ? 'auto' : `${height + 70}rpx`,paddingBottom: isOpen ? '70rpx' : 0,color}"
  5. >
  6. <view class="fs-readmore-content layout-box" :style="{backgroundColor:bgColor}">
  7. <slot></slot>
  8. </view>
  9. <view class="fs-readmore-footer" :style="{backgroundColor:bgColor}" @click="handleToggle" v-if="visible">
  10. <view>{{isOpen ? '收起' : label}}</view>
  11. <fs-icon class="fs-readmore-icon" type="icon-d-down" size="26rpx" :class="{isOpen}"></fs-icon>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. // 限定多高时展示更多按钮
  19. maxHeight: {
  20. type: Number,
  21. default: 100
  22. },
  23. label: {
  24. type: String,
  25. default: '展开更多'
  26. },
  27. open: Boolean,
  28. bgColor: {
  29. type: String,
  30. default: '#fff'
  31. },
  32. color: {
  33. type: String,
  34. default: '#666666'
  35. }
  36. },
  37. data() {
  38. return {
  39. isOpen: false,
  40. visible: false
  41. }
  42. },
  43. mounted() {
  44. uni.createSelectorQuery().in(this).select('.fs-readmore-content').boundingClientRect(data => {
  45. this.visible = data.height > this.height
  46. }).exec()
  47. },
  48. computed: {
  49. height() {
  50. return parseFloat(this.maxHeight)
  51. }
  52. },
  53. methods: {
  54. handleToggle() {
  55. this.isOpen = !this.isOpen
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .fs-readmore{
  62. position: relative;
  63. overflow: hidden;
  64. &-content{
  65. overflow: hidden;
  66. }
  67. &-footer{
  68. display: flex;
  69. align-items: center;
  70. justify-content: center;
  71. position: absolute;
  72. z-index: 10;
  73. width: 100%;
  74. bottom: 0;
  75. font-size: 13px;
  76. height: 70rpx;
  77. line-height: 70rpx;
  78. // box-shadow: 0 -6rpx 2rpx rgba(65, 65, 70, 0.2);
  79. }
  80. &-icon{
  81. transition: all .2s;
  82. margin-left: 6rpx;
  83. }
  84. .isOpen{
  85. transform: rotate(180deg);
  86. }
  87. }
  88. </style>