fs-readmore.vue 1.7 KB

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