TitleDescBlock.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="TitleDescBlock">
  3. <h3>{{ title }}</h3>
  4. <span v-if="date" class="time">{{ date }}</span>
  5. <p :class="expand?'expand':''" v-html="desc"></p>
  6. <slot name="addon" />
  7. <div class="footer">
  8. <div v-if="showExpand" :class="'expand'+(expand?' on':'')" @click="expand=!expand">
  9. {{expand?'折叠':'展开'}}
  10. <img src="@/assets/images/IconArrowRight.png" />
  11. </div>
  12. <div v-if="more" class="more" @click="emit('moreClick')">
  13. 更多
  14. <img src="@/assets/images/IconArrowRight.png" alt="更多" />
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script setup lang="ts">
  20. import { ref } from 'vue';
  21. const props = defineProps({
  22. title : {
  23. type: String,
  24. default: '',
  25. },
  26. desc: {
  27. type: String,
  28. default: '',
  29. },
  30. descLines: {
  31. type: Number,
  32. default: 3,
  33. },
  34. more: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. showExpand: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. date: {
  43. type: String,
  44. default: '',
  45. },
  46. })
  47. const expand = ref(false)
  48. const emit = defineEmits([
  49. "moreClick"
  50. ])
  51. </script>
  52. <style lang="scss">
  53. @use '@/assets/scss/colors.scss' as *;
  54. .TitleDescBlock {
  55. display: flex;
  56. flex-direction: column;
  57. justify-content: center;
  58. h3 {
  59. color: $text-content-color;
  60. font-size: 1.2rem;
  61. margin-top: 0;
  62. margin-bottom: 8px;
  63. }
  64. p,
  65. .time {
  66. color: $text-content-second-color;
  67. font-size: 0.85rem;
  68. }
  69. .time {
  70. margin-bottom: 16px;
  71. }
  72. p {
  73. display: -webkit-box;
  74. -webkit-box-orient: vertical;
  75. -webkit-line-clamp: 6;
  76. line-clamp: 6;
  77. margin: 0;
  78. overflow: hidden;
  79. text-overflow: ellipsis;
  80. &.expand {
  81. -webkit-line-clamp: 100;
  82. line-clamp: 100;
  83. }
  84. }
  85. .footer {
  86. display: flex;
  87. flex-direction: row;
  88. align-items: center;
  89. justify-content: space-between;
  90. > div {
  91. display: flex;
  92. flex-direction: row;
  93. align-items: center;
  94. color: $text-content-second-color;
  95. font-size: 0.85rem;
  96. margin-top: 25px;
  97. cursor: pointer;
  98. &:hover {
  99. color: $primary-color;
  100. }
  101. }
  102. }
  103. .expand {
  104. img {
  105. width: 16px;
  106. height: 16px;
  107. transform: rotate(90deg);
  108. }
  109. &.on {
  110. img {
  111. transform: rotate(270deg);
  112. }
  113. }
  114. }
  115. .more {
  116. img {
  117. width: 16px;
  118. height: 16px;
  119. margin-left: 8px;
  120. }
  121. }
  122. }
  123. </style>