SwiperBanner.vue 8.2 KB

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