SwiperBanner.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <section class="swiper--banner--wrapper" :data-type="type" :data-fit="fit">
  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="getSlideTitle(index)" class="main--title">
  48. {{ getSlideTitle(index) }}
  49. </h2>
  50. <h3 v-if="getSlideSubtitle(index)" class="sub--title">
  51. {{ getSlideSubtitle(index) }}
  52. </h3>
  53. <h4 v-if="getSlideSmalldesc(index)" class="desc--title">
  54. {{ getSlideSmalldesc(index) }}
  55. </h4>
  56. <NuxtLink
  57. v-if="getSlideMorelink(index)"
  58. class="more--detail--href mt--20"
  59. :to="getSlideMorelink(index)"
  60. :target="getSlideTarget(index)"
  61. >{{ getSlideMorelinktitle(index) }} <i class="ico"></i
  62. ></NuxtLink>
  63. </div>
  64. </div>
  65. <div v-if="notice" class="notice--text">
  66. <p>{{ notice }}</p>
  67. </div>
  68. </div>
  69. </div>
  70. <!-- 70% 영역: 단일 배너 -->
  71. <div class="swiper--banner--section">
  72. <div class="swiper--container" ref="swiperContainer">
  73. <div class="swiper-wrapper">
  74. <div v-for="(slide, index) in slides" :key="index" class="swiper-slide">
  75. <div class="slide--image">
  76. <img
  77. :src="slide.image"
  78. :alt="slide.alt || 'Banner Image'"
  79. loading="lazy"
  80. />
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </section>
  88. </template>
  89. <script setup>
  90. import { Swiper } from "swiper";
  91. import { Navigation, Pagination, Autoplay } from "swiper/modules";
  92. import "swiper/css";
  93. import "swiper/css/navigation";
  94. import "swiper/css/pagination";
  95. // Props 정의
  96. const props = defineProps({
  97. slides: {
  98. type: Array,
  99. default: () => [
  100. {
  101. image: "/img/exclusive/banner1.jpg",
  102. alt: "Audi Banner 1",
  103. title: "Audi R8 V10 Performance",
  104. subtitle: "순수한 스포츠카의 영혼",
  105. },
  106. {
  107. image: "/img/exclusive/banner2.jpg",
  108. alt: "Audi Banner 2",
  109. title: "Audi RS e-tron GT",
  110. subtitle: "전기차의 미래를 선도하는 GT",
  111. },
  112. {
  113. image: "/img/exclusive/banner3.jpg",
  114. alt: "Audi Banner 3",
  115. title: "Audi RS 6 Avant",
  116. subtitle: "프리미엄 퍼포먼스 왜건의 극치",
  117. },
  118. ],
  119. },
  120. title: {
  121. type: String,
  122. default: "",
  123. },
  124. subtitle: {
  125. type: String,
  126. default: "",
  127. },
  128. smalldesc: {
  129. type: String,
  130. default: "",
  131. },
  132. morelink: {
  133. type: String,
  134. default: "",
  135. },
  136. morelinktitle: {
  137. type: String,
  138. default: "자세히 보기",
  139. },
  140. morelinktarget: {
  141. type: String,
  142. default: "_self",
  143. },
  144. notice: {
  145. type: String,
  146. default: "",
  147. },
  148. autoplay: {
  149. type: [Boolean, Object],
  150. default: () => ({ delay: 5000 }),
  151. },
  152. loop: {
  153. type: Boolean,
  154. default: true,
  155. },
  156. type: {
  157. type: String,
  158. default: "horizental", // 'horz' , 'vert'
  159. validator: (value) => ["horizental", "vertical"].includes(value),
  160. },
  161. fit: {
  162. type: String,
  163. default: "cover",
  164. validator: (value) => ["cover", "contain"].includes(value),
  165. },
  166. });
  167. // Refs
  168. const swiperContainer = ref(null);
  169. const paginationRef = ref(null);
  170. const prevRef = ref(null);
  171. const nextRef = ref(null);
  172. const textSlider = ref(null);
  173. let swiperInstance = null;
  174. // 현재 슬라이드 인덱스
  175. const currentSlide = ref(0);
  176. // 슬라이드별 텍스트 반환 함수들
  177. const getSlideTitle = (index) => {
  178. return props.slides[index]?.title || props.title;
  179. };
  180. const getSlideSubtitle = (index) => {
  181. return props.slides[index]?.subtitle || props.subtitle;
  182. };
  183. const getSlideSmalldesc = (index) => {
  184. return props.slides[index]?.smalldesc || props.smalldesc;
  185. };
  186. const getSlideMorelink = (index) => {
  187. return props.slides[index]?.morelink || props.morelink;
  188. };
  189. const getSlideMorelinktitle = (index) => {
  190. return props.slides[index]?.morelinktitle || props.morelinktitle;
  191. };
  192. const getSlideTarget = (index) => {
  193. return props.slides[index]?.morelinktarget || props.morelinktarget;
  194. };
  195. onMounted(() => {
  196. // Swiper 인스턴스 초기화
  197. swiperInstance = new Swiper(swiperContainer.value, {
  198. modules: [Navigation, Pagination, Autoplay],
  199. slidesPerView: 1,
  200. spaceBetween: 0,
  201. loop: props.loop,
  202. autoplay: props.autoplay
  203. ? {
  204. delay:
  205. typeof props.autoplay === "object" ? props.autoplay.delay || 5000 : 5000,
  206. disableOnInteraction: false,
  207. }
  208. : false,
  209. navigation: {
  210. nextEl: nextRef.value,
  211. prevEl: prevRef.value,
  212. },
  213. pagination: {
  214. el: paginationRef.value,
  215. clickable: true,
  216. type: "bullets",
  217. renderBullet: function (index, className) {
  218. return '<span class="' + className + '">' + (index + 1) + "</span>";
  219. },
  220. },
  221. effect: "fade",
  222. fadeEffect: {
  223. crossFade: true,
  224. },
  225. speed: 800,
  226. // 슬라이드 변경 이벤트
  227. on: {
  228. slideChange: function () {
  229. if (this && this.realIndex !== undefined) {
  230. currentSlide.value = this.realIndex;
  231. }
  232. },
  233. init: function () {
  234. if (this && this.realIndex !== undefined) {
  235. currentSlide.value = this.realIndex;
  236. }
  237. },
  238. },
  239. });
  240. });
  241. onUnmounted(() => {
  242. if (swiperInstance) {
  243. swiperInstance.destroy(true, true);
  244. }
  245. });
  246. </script>