carousel.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="carousel-container">
  3. <!-- 主轮播区 -->
  4. <div class="main-carousel-wrapper">
  5. <el-carousel
  6. ref="mainCarousel"
  7. :interval="2000"
  8. :autoplay="true"
  9. height="1.89rem"
  10. indicator-position="none"
  11. arrow="never"
  12. @change="handleMainChange"
  13. >
  14. <el-carousel-item v-for="(item, index) in items" :key="index">
  15. <div class="image-wrapper">
  16. <el-image
  17. :src="item.image"
  18. :preview-src-list="previewList"
  19. fit="cover"
  20. class="main-image"
  21. />
  22. <div class="fullscreen-btn" @click="openFullscreen(index)">
  23. <img src="@/assets/image/smart-early-warning/fullScreen.png" alt="">
  24. </div>
  25. </div>
  26. </el-carousel-item>
  27. </el-carousel>
  28. </div>
  29. <!-- 缩略图导航区 -->
  30. <div class="thumbnail-container">
  31. <div class="nav-btn prev-btn" @click="prevSlide">
  32. <img src="@/assets/image/smart-early-warning/leftBtn.png" alt="">
  33. </div>
  34. <div class="thumbnail-list">
  35. <div
  36. v-for="(item, index) in items"
  37. :key="index"
  38. :class="['thumbnail-item', { active: currentIndex === index }]"
  39. @click="switchToSlide(index)"
  40. >
  41. <img :src="item.thumbnail" class="thumbnail-image">
  42. </div>
  43. </div>
  44. <div class="nav-btn next-btn" @click="nextSlide">
  45. <img src="@/assets/image/smart-early-warning/rightBtn.png" alt="">
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. export default {
  52. props:{
  53. items:Array
  54. },
  55. data() {
  56. return {
  57. currentIndex: 0
  58. }
  59. },
  60. computed: {
  61. previewList() {
  62. return this.items.map(item => item.image);
  63. }
  64. },
  65. methods: {
  66. handleMainChange(index) {
  67. this.currentIndex = index;
  68. },
  69. switchToSlide(index) {
  70. this.currentIndex = index;
  71. this.$refs.mainCarousel.setActiveItem(index);
  72. },
  73. prevSlide() {
  74. this.$refs.mainCarousel.prev();
  75. },
  76. nextSlide() {
  77. this.$refs.mainCarousel.next();
  78. },
  79. openFullscreen(index) {
  80. console.info(index)
  81. console.info('vv')
  82. this.$refs.mainCarousel.setActiveItem(index);
  83. const img = this.$el.querySelectorAll('.main-image')[index].querySelector('img');
  84. console.info(img)
  85. img.click(); // 触发图片预览
  86. }
  87. }
  88. }
  89. </script>
  90. <style scoped lang="scss">
  91. .carousel-container {
  92. width: 100%;
  93. margin: 0 auto;
  94. }
  95. .main-carousel-wrapper {
  96. position: relative;
  97. margin-bottom: px-to-rem(10);
  98. }
  99. .image-wrapper {
  100. position: relative;
  101. width: 100%;
  102. height: 100%;
  103. }
  104. .main-image {
  105. width: 100%;
  106. height: 100%;
  107. object-fit: cover;
  108. cursor: pointer;
  109. transition: transform 0.3s;
  110. }
  111. .main-image:hover {
  112. transform: scale(1.02);
  113. }
  114. .fullscreen-btn {
  115. position: absolute;
  116. bottom: px-to-rem(10);
  117. right: px-to-rem(10);
  118. width: px-to-rem(40);
  119. height: px-to-rem(40);
  120. display: flex;
  121. align-items: center;
  122. justify-content: center;
  123. cursor: pointer;
  124. z-index: 10;
  125. transition: all 0.3s;
  126. }
  127. .fullscreen-btn:hover {
  128. transform: scale(1.1);
  129. }
  130. .thumbnail-container {
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. gap: px-to-rem(5);
  135. padding-bottom: px-to-rem(10);
  136. border-bottom: px-to-rem(1) solid #59799F;
  137. margin-bottom: px-to-rem(10);
  138. }
  139. .thumbnail-list {
  140. display: flex;
  141. gap: px-to-rem(5);
  142. overflow-x: auto;
  143. scrollbar-width: none;
  144. }
  145. .thumbnail-list::-webkit-scrollbar {
  146. display: none;
  147. }
  148. .thumbnail-item {
  149. width: px-to-rem(60);
  150. height: px-to-rem(30);
  151. border: px-to-rem(1) solid transparent;
  152. border-radius: px-to-rem(4);
  153. overflow: hidden;
  154. cursor: pointer;
  155. transition: all 0.3s;
  156. flex-shrink: 0;
  157. }
  158. .thumbnail-item:hover {
  159. border-color: #4F9FFF;
  160. }
  161. .thumbnail-item.active {
  162. border-color: #4F9FFF;
  163. }
  164. .thumbnail-image {
  165. width: 100%;
  166. height: 100%;
  167. object-fit: cover;
  168. }
  169. .nav-btn {
  170. width: px-to-rem(12);
  171. height: px-to-rem(30);
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. cursor: pointer;
  176. transition: all 0.3s;
  177. }
  178. .nav-btn:hover {
  179. background: #409EFF;
  180. color: white;
  181. }
  182. </style>