SwiperBanner.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <section class="swiper--banner--wrapper" :data-type="type">
  3. <div class="swiper--banner--container">
  4. <!-- 30% 영역: 컨트롤 및 텍스트 -->
  5. <div class="swiper--controls--section">
  6. <div class="controls--top">
  7. <!-- 페이지네이션과 네비게이션 버튼 -->
  8. <div class="pagination--nav--wrapper">
  9. <div class="navigation--buttons">
  10. <div class="swiper-button-prev" ref="prevRef">
  11. <svg
  12. fill="none"
  13. xmlns="http://www.w3.org/2000/svg"
  14. aria-hidden="true"
  15. width="24px"
  16. height="24px"
  17. class="sc-oVpqz cvAPSl"
  18. >
  19. <use href="/img/ico--back--s.svg#main"></use>
  20. </svg>
  21. </div>
  22. <div class="swiper-pagination" ref="paginationRef"></div>
  23. <div class="swiper-button-next" ref="nextRef">
  24. <svg
  25. fill="none"
  26. xmlns="http://www.w3.org/2000/svg"
  27. aria-hidden="true"
  28. width="24px"
  29. height="24px"
  30. class="sc-oVpqz cvAPSl"
  31. >
  32. <use href="/img/ico--forward--s.svg#main"></use>
  33. </svg>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 텍스트 컨텐츠 -->
  39. <div class="text--content">
  40. <div class="text--slider" ref="textSlider">
  41. <div
  42. v-for="(slide, index) in slides"
  43. :key="index"
  44. class="text--slide"
  45. :class="{ active: index === currentSlide }"
  46. >
  47. <h2 v-if="title" class="main--title">{{ getSlideTitle(index) }}</h2>
  48. <h3 v-if="subtitle" class="sub--title">{{ getSlideSubtitle(index) }}</h3>
  49. <h4 v-if="smalldesc" class="desc--title">{{ getSlideSmalldesc(index) }}</h4>
  50. </div>
  51. </div>
  52. <div v-if="notice" class="notice--text">
  53. <p>{{ notice }}</p>
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 70% 영역: 단일 배너 -->
  58. <div class="swiper--banner--section">
  59. <div class="swiper--container" ref="swiperContainer">
  60. <div class="swiper-wrapper">
  61. <div v-for="(slide, index) in slides" :key="index" class="swiper-slide">
  62. <div class="slide--image">
  63. <img
  64. :src="slide.image"
  65. :alt="slide.alt || 'Banner Image'"
  66. loading="lazy"
  67. />
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </section>
  75. </template>
  76. <script setup>
  77. import { Swiper } from "swiper";
  78. import { Navigation, Pagination, Autoplay } from "swiper/modules";
  79. import "swiper/css";
  80. import "swiper/css/navigation";
  81. import "swiper/css/pagination";
  82. // Props 정의
  83. const props = defineProps({
  84. slides: {
  85. type: Array,
  86. default: () => [
  87. {
  88. image: "/img/exclusive/banner1.jpg",
  89. alt: "Audi Banner 1",
  90. title: "Audi R8 V10 Performance",
  91. subtitle: "순수한 스포츠카의 영혼",
  92. },
  93. {
  94. image: "/img/exclusive/banner2.jpg",
  95. alt: "Audi Banner 2",
  96. title: "Audi RS e-tron GT",
  97. subtitle: "전기차의 미래를 선도하는 GT",
  98. },
  99. {
  100. image: "/img/exclusive/banner3.jpg",
  101. alt: "Audi Banner 3",
  102. title: "Audi RS 6 Avant",
  103. subtitle: "프리미엄 퍼포먼스 왜건의 극치",
  104. },
  105. ],
  106. },
  107. title: {
  108. type: String,
  109. default: "Audi Exclusive",
  110. },
  111. subtitle: {
  112. type: String,
  113. default: "특별한 아우디 경험",
  114. },
  115. smalldesc: {
  116. type: String,
  117. default: "",
  118. },
  119. notice: {
  120. type: String,
  121. default: "* 모든 이미지는 참고용이며 실제와 다를 수 있습니다.",
  122. },
  123. autoplay: {
  124. type: [Boolean, Object],
  125. default: () => ({ delay: 5000 }),
  126. },
  127. loop: {
  128. type: Boolean,
  129. default: true,
  130. },
  131. type: {
  132. type: String,
  133. default: "horizental", // 'horz' , 'vert'
  134. validator: (value) => ["horizental", "vertical"].includes(value),
  135. },
  136. });
  137. // Refs
  138. const swiperContainer = ref(null);
  139. const paginationRef = ref(null);
  140. const prevRef = ref(null);
  141. const nextRef = ref(null);
  142. const textSlider = ref(null);
  143. let swiperInstance = null;
  144. // 현재 슬라이드 인덱스
  145. const currentSlide = ref(0);
  146. // 슬라이드별 텍스트 반환 함수들
  147. const getSlideTitle = (index) => {
  148. return props.slides[index]?.title || props.title;
  149. };
  150. const getSlideSubtitle = (index) => {
  151. return props.slides[index]?.subtitle || props.subtitle;
  152. };
  153. const getSlideSmalldesc = (index) => {
  154. return props.slides[index]?.smalldesc || props.smalldesc;
  155. };
  156. onMounted(() => {
  157. // Swiper 인스턴스 초기화
  158. swiperInstance = new Swiper(swiperContainer.value, {
  159. modules: [Navigation, Pagination, Autoplay],
  160. slidesPerView: 1,
  161. spaceBetween: 0,
  162. loop: props.loop,
  163. autoplay: props.autoplay
  164. ? {
  165. delay:
  166. typeof props.autoplay === "object" ? props.autoplay.delay || 5000 : 5000,
  167. disableOnInteraction: false,
  168. }
  169. : false,
  170. navigation: {
  171. nextEl: nextRef.value,
  172. prevEl: prevRef.value,
  173. },
  174. pagination: {
  175. el: paginationRef.value,
  176. clickable: true,
  177. type: "bullets",
  178. renderBullet: function (index, className) {
  179. return '<span class="' + className + '">' + (index + 1) + "</span>";
  180. },
  181. },
  182. effect: "fade",
  183. fadeEffect: {
  184. crossFade: true,
  185. },
  186. speed: 800,
  187. // 슬라이드 변경 이벤트
  188. on: {
  189. slideChange: function () {
  190. if (this && this.realIndex !== undefined) {
  191. currentSlide.value = this.realIndex;
  192. }
  193. },
  194. init: function () {
  195. if (this && this.realIndex !== undefined) {
  196. currentSlide.value = this.realIndex;
  197. }
  198. },
  199. },
  200. });
  201. });
  202. onUnmounted(() => {
  203. if (swiperInstance) {
  204. swiperInstance.destroy(true, true);
  205. }
  206. });
  207. </script>