SwiperBanner.vue 7.6 KB

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