di-card.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="di-card" :class="{'u-border-bottom' : true}" @click.native="handleClick">
  3. <!-- 多图卡片 -->
  4. <view v-if="mode === 'multiple'" class="card mode-multiple">
  5. <view class="card-content">
  6. <view class="card-content__title">
  7. <slot name="title">
  8. <text>{{title}}</text>
  9. </slot>
  10. </view>
  11. <view class="card-image">
  12. <view class="card-image__item" v-for="(item, index) in imageList" :key="index">
  13. <image class="el-image" :src="item" mode="aspectFill"></image>
  14. </view>
  15. </view>
  16. <view class="card-content__footer">
  17. <slot name="footer"></slot>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- 大图模式/左图右文字模式 -->
  22. <view v-else class="card" :class="{'mode-picture-card': mode === 'pictureCard'}">
  23. <view class="card-image">
  24. <image class="el-image" :src="imageList[0]" mode="aspectFill"></image>
  25. </view>
  26. <view class="card-content">
  27. <view class="card-content__title">
  28. <slot name="title">
  29. <text>{{title}}</text>
  30. </slot>
  31. </view>
  32. <view class="card-content__footer">
  33. <slot name="footer"></slot>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. /**
  41. * 图片卡片组件
  42. * @description 适合文章列表的图片卡片组件
  43. * @property {String Number} index 卡片唯一值
  44. * @property {String} title 卡片标题
  45. * @property {Array} image-list 卡片图片
  46. * @property {String} mode = [default|pictureCard|multiple] 模式选择,"default"- 左图右文字(默认),"pictureCard"-大图模式,"multiple"-多图模式
  47. * @event {Function} click
  48. */
  49. export default {
  50. methods: {
  51. handleClick() {
  52. this.$emit('click', this.index)
  53. }
  54. },
  55. props: {
  56. index: {
  57. type: [String, Number],
  58. require: true
  59. },
  60. // 模式
  61. mode: {
  62. type: String,
  63. default: 'default'
  64. },
  65. title: {
  66. type: String,
  67. require: true
  68. },
  69. imageList: {
  70. type: Array,
  71. require: true
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .di-card {
  78. .card {
  79. display: flex;
  80. margin: 5px;
  81. padding: 10px;
  82. box-sizing: border-box;
  83. .card-image {
  84. width: 64px;
  85. height: 64px;
  86. border-radius: 5px;
  87. overflow: hidden;
  88. //避免挤压
  89. flex-shrink: 0;
  90. image {
  91. height: 100%;
  92. width: 100%;
  93. }
  94. }
  95. .card-content {
  96. display: flex;
  97. flex-direction: column;
  98. padding-left: 10px;
  99. width: 100%;
  100. justify-content: space-between;
  101. .card-content__title {
  102. position: relative;
  103. font-size: 28rpx;
  104. font-weight: 400;
  105. color: #333;
  106. line-height: 1.2;
  107. //超过两行溢出隐藏
  108. text {
  109. overflow: hidden;
  110. text-overflow: ellipsis;
  111. display: -webkit-box;
  112. -webkit-line-clamp: 2;
  113. -webkit-box-orient: vertical;
  114. }
  115. }
  116. .card-content__footer {
  117. display: flex;
  118. justify-content: flex-end;
  119. align-items: center;
  120. font-size: 24rpx;
  121. }
  122. }
  123. &.mode-multiple {
  124. .card-content {
  125. padding-left: 0;
  126. width: 100%;
  127. }
  128. .card-image {
  129. display: flex;
  130. width: 100%;
  131. height: 70px;
  132. margin: 10px 0px;
  133. .card-image__item {
  134. display: flex;
  135. width: 100%;
  136. box-sizing: border-box;
  137. border-radius: 5px;
  138. margin-left: 10px;
  139. &:first-child {
  140. margin-left: 0;
  141. }
  142. .el-image {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. }
  147. }
  148. }
  149. // 大图模式
  150. &.mode-picture-card {
  151. flex-direction: column;
  152. .card-image {
  153. width: 100% ;
  154. height: 100px;
  155. }
  156. .card-content {
  157. margin-top: 10px;
  158. padding-left: 0;
  159. .card-content__footer {
  160. margin-top: 10px;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. </style>