SwiperBanner.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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" :style="'height:' + height + '%'">
  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. height: {
  143. type: String,
  144. default: "60%",
  145. },
  146. title: {
  147. type: String,
  148. default: "",
  149. },
  150. subtitle: {
  151. type: String,
  152. default: "",
  153. },
  154. smalldesc: {
  155. type: String,
  156. default: "",
  157. },
  158. cautiondesc: {
  159. type: String,
  160. default: "",
  161. },
  162. morelink: {
  163. type: String,
  164. default: "",
  165. },
  166. morelinktitle: {
  167. type: String,
  168. default: "자세히 보기",
  169. },
  170. morelinktarget: {
  171. type: String,
  172. default: "_self",
  173. },
  174. notice: {
  175. type: String,
  176. default: "",
  177. },
  178. autoplay: {
  179. type: [Boolean, Object],
  180. default: () => ({ delay: 5000 }),
  181. },
  182. loop: {
  183. type: Boolean,
  184. default: true,
  185. },
  186. type: {
  187. type: String,
  188. default: "horizental", // 'horz' , 'vert'
  189. validator: (value) => ["horizental", "vertical"].includes(value),
  190. },
  191. fit: {
  192. type: String,
  193. default: "cover",
  194. validator: (value) => ["cover", "contain"].includes(value),
  195. },
  196. });
  197. // Refs
  198. const swiperContainer = ref(null);
  199. const paginationRef = ref(null);
  200. const prevRef = ref(null);
  201. const nextRef = ref(null);
  202. const textSlider = ref(null);
  203. let swiperInstance = null;
  204. // 현재 슬라이드 인덱스
  205. const currentSlide = ref(0);
  206. // 슬라이드별 텍스트 반환 함수들
  207. const getSlideTitle = (index) => {
  208. return props.slides[index]?.title || props.title;
  209. };
  210. const getSlideSubtitle = (index) => {
  211. return props.slides[index]?.subtitle || props.subtitle;
  212. };
  213. const getSlideSmalldesc = (index) => {
  214. return props.slides[index]?.smalldesc || props.smalldesc;
  215. };
  216. const getSlideMorelink = (index) => {
  217. return props.slides[index]?.morelink || props.morelink;
  218. };
  219. const getSlideMorelinktitle = (index) => {
  220. return props.slides[index]?.morelinktitle || props.morelinktitle;
  221. };
  222. const getSlideTarget = (index) => {
  223. return props.slides[index]?.morelinktarget || props.morelinktarget;
  224. };
  225. const getSlideCautiondesc = (index) => {
  226. return props.slides[index]?.cautiondesc || props.cautiondesc;
  227. };
  228. onMounted(() => {
  229. // Swiper 인스턴스 초기화
  230. swiperInstance = new Swiper(swiperContainer.value, {
  231. modules: [Navigation, Pagination, Autoplay],
  232. slidesPerView: 1,
  233. spaceBetween: 0,
  234. loop: props.loop,
  235. autoplay: props.autoplay
  236. ? {
  237. delay:
  238. typeof props.autoplay === "object" ? props.autoplay.delay || 5000 : 5000,
  239. disableOnInteraction: false,
  240. }
  241. : false,
  242. navigation: {
  243. nextEl: nextRef.value,
  244. prevEl: prevRef.value,
  245. },
  246. pagination: {
  247. el: paginationRef.value,
  248. clickable: true,
  249. type: "bullets",
  250. renderBullet: function (index, className) {
  251. return '<span class="' + className + '">' + (index + 1) + "</span>";
  252. },
  253. },
  254. effect: "fade",
  255. fadeEffect: {
  256. crossFade: true,
  257. },
  258. speed: 800,
  259. // 슬라이드 변경 이벤트
  260. on: {
  261. slideChange: function () {
  262. if (this && this.realIndex !== undefined) {
  263. currentSlide.value = this.realIndex;
  264. }
  265. },
  266. init: function () {
  267. if (this && this.realIndex !== undefined) {
  268. currentSlide.value = this.realIndex;
  269. }
  270. },
  271. },
  272. });
  273. });
  274. onUnmounted(() => {
  275. if (swiperInstance) {
  276. swiperInstance.destroy(true, true);
  277. }
  278. });
  279. </script>