MediaCard.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <figure :class="['card', { 'row': toggle }]">
  3. <div class="card-media" @click="handLeftBtn">
  4. <video controls ref="video" v-if="cardData.type === 5 && toggle" class="card-media-content">
  5. <source :src="cardData.media_url">
  6. Your browser does not support the video tag.
  7. </video>
  8. <el-image :src="(cardData.type === 1 || cardData.type === 8) ? cardData.media_url : cardData.image"
  9. class="card-img-1" fit="contain" style="width: 100%; height: 100%" v-else>
  10. </el-image>
  11. <div class="type-icon" v-if="cardData.typeName && !toggle">{{ cardData.typeName.toUpperCase() }}
  12. </div>
  13. </div>
  14. <figcaption class="card-info">
  15. <div class="card-info-1">
  16. <h1>{{ cardData.name }}</h1>
  17. <p class="card-info-point">{{ cardData.description }}</p>
  18. <ul class="card-info-label">
  19. <li v-for="(l, index) of cardData.mapLabel" :key="index" @click="emitLabel(l)">{{ l }}</li>
  20. <nuxt-link :to="{ name: 'product-code', params: { code: item } }" v-for="(item, key) of cardData.sku" :key="key"
  21. target="_blank">
  22. <li :key="item">{{ item }}</li>
  23. </nuxt-link>
  24. </ul>
  25. </div>
  26. <div class="card-info-btn">
  27. <el-button @click="handLeftBtn" v-if="!toggle">View</el-button>
  28. <el-button @click="handRightBtn">Download</el-button>
  29. </div>
  30. </figcaption>
  31. </figure>
  32. </template>
  33. <script>
  34. export default {
  35. props: {
  36. cardData: {},
  37. toggle: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. },
  42. watch: {
  43. 'cardData.media_url': function (newVal, oldVal) {
  44. if (newVal !== oldVal && this.$refs.video) {
  45. this.$refs.video.load(); // 重新加载视频
  46. }
  47. }
  48. },
  49. data() {
  50. return {};
  51. },
  52. methods: {
  53. emitLabel(l) {
  54. this.$emit('labelEvent', l)
  55. },
  56. handLeftBtn() {
  57. this.$emit('leftBtnEvent')
  58. },
  59. handRightBtn() {
  60. this.$emit('rightBtnEvent')
  61. }
  62. },
  63. };
  64. </script>
  65. <style lang="scss" scoped>
  66. .card {
  67. display: flex;
  68. flex-direction: column;
  69. position: relative;
  70. box-shadow: 0px 0px 10px rgba(137, 137, 137, 0.05);
  71. transition: all 0.2s ease-out 0s;
  72. box-sizing: border-box;
  73. overflow: hidden;
  74. border: 1px solid #eee;
  75. border-radius: 4px;
  76. // &:hover {
  77. // box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
  78. // .card-img-1 {
  79. // transform: scale(1.1);
  80. // }
  81. // h1 {
  82. // color: #006dc9;
  83. // }
  84. // }
  85. .card-media {
  86. width: 100%;
  87. height: 200px;
  88. box-sizing: border-box;
  89. overflow: hidden;
  90. .card-media-content {
  91. height: auto;
  92. object-fit: contain;
  93. }
  94. .card-img-1 {
  95. height: auto;
  96. transition: all 0.5s;
  97. cursor: pointer;
  98. }
  99. .type-icon {
  100. position: absolute;
  101. top: 10px;
  102. left: 10px;
  103. padding: 10px;
  104. color: #00213b;
  105. background-color: #fff;
  106. border-radius: 4px;
  107. font-weight: 550;
  108. box-shadow: 0 0 0 2px rgba(#bbb, 0.1);
  109. }
  110. }
  111. .card-info {
  112. flex: 1;
  113. height: 100%;
  114. margin: 0 10px 10px 10px;
  115. color: #4a596c;
  116. display: flex;
  117. flex-direction: column;
  118. .card-info-1 {
  119. flex: 1;
  120. }
  121. h1 {
  122. font-size: 18px;
  123. font-weight: 600;
  124. margin: 10px 0;
  125. overflow: hidden;
  126. text-overflow: ellipsis;
  127. display: -webkit-box;
  128. -webkit-line-clamp: 1;
  129. -webkit-box-orient: vertical;
  130. }
  131. .card-info-point {
  132. margin: 10px 0;
  133. min-height: 40px;
  134. line-height: 20px;
  135. overflow: hidden;
  136. text-overflow: ellipsis;
  137. display: -webkit-box;
  138. -webkit-line-clamp: 2;
  139. -webkit-box-orient: vertical;
  140. }
  141. .card-info-label {
  142. display: flex;
  143. /* 使用flex布局 */
  144. flex-wrap: wrap;
  145. /* 限制最大高度为两行 */
  146. overflow: hidden;
  147. /* 超出部分隐藏 */
  148. position: relative;
  149. li {
  150. border: 1px solid #e7e7e7;
  151. font-size: 16px;
  152. border-radius: 6px;
  153. display: inline-block;
  154. padding: 8px;
  155. margin-right: 10px;
  156. margin-bottom: 10px;
  157. color: #fff;
  158. background-color: var(--deep-blue);
  159. cursor: pointer;
  160. }
  161. }
  162. .card-info-btn {
  163. text-align: center;
  164. button {
  165. font-weight: bold;
  166. width: 120px;
  167. color: var(--deep-blue);
  168. border-color: var(--deep-blue);
  169. }
  170. }
  171. }
  172. }
  173. .row {
  174. border: none;
  175. flex-direction: row;
  176. &:hover {
  177. box-shadow: none;
  178. }
  179. .card-media {
  180. height: inherit;
  181. flex: 1;
  182. display: flex;
  183. align-items: center;
  184. video {
  185. width: 100%;
  186. height: auto;
  187. }
  188. }
  189. .card-info {
  190. flex: 1;
  191. height: inherit;
  192. display: flex;
  193. flex-direction: column;
  194. margin: 0 0 0 20px;
  195. .card-info-1 {
  196. flex: 1;
  197. h1 {
  198. margin: 0;
  199. padding-bottom: 10px;
  200. border-bottom: 1px solid #ddd;
  201. }
  202. .card-info-point {
  203. -webkit-line-clamp: 7;
  204. }
  205. }
  206. }
  207. }
  208. </style>