NavigationBar.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="bar" :class="{ show }">
  3. <img class="close" :src="closeICON" @click="toggleMenu" />
  4. <Swiper
  5. :slides-per-view="slidePreview"
  6. :navigation="{
  7. nextEl: '.swiper-button-next',
  8. prevEl: '.swiper-button-prev',
  9. }"
  10. :modules="modules"
  11. :pagination="{ el: '.pagination', type: 'bullets' }"
  12. :grabCursor="true"
  13. :space-between="0"
  14. :freeMode="true"
  15. @swiper="onSwiper"
  16. @slideChange="onSlideChange"
  17. >
  18. <template v-for="item in lists">
  19. <SwiperSlide @click="handleClick(item)">
  20. <div class="cover">
  21. <img :src="`${imagePath}${item.cover}`" />
  22. </div>
  23. <div class="desc">
  24. <span class="cap">{{ item.zhName }}</span>
  25. <span class="sub">{{ item.enName }}</span>
  26. </div>
  27. </SwiperSlide>
  28. </template>
  29. </Swiper>
  30. <div
  31. class="swiper-button swiper-button-next"
  32. >
  33. </div>
  34. <div
  35. class="swiper-button swiper-button-prev"
  36. >
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { ref, inject, computed } from "vue";
  42. import { Swiper, SwiperSlide, useSwiper } from "swiper/vue";
  43. import { Navigation } from 'swiper/modules';
  44. import closeICON from '../assets/cloes.png'
  45. import 'swiper/less/navigation';
  46. import 'swiper/less/pagination';
  47. import "swiper/css";
  48. import { onMounted, onUnmounted } from "vue";
  49. const data = inject("data");
  50. const emits = defineEmits(["changeScene","toggleMenu"]);
  51. const swiper = ref(null);
  52. console.log("useSwiper", swiper, useSwiper);
  53. const imagePath = ref(import.meta.env.VITE_COVER_DIR);
  54. defineProps({
  55. show: {
  56. type: Boolean,
  57. default: () => false,
  58. },
  59. });
  60. const lists = computed(() =>
  61. Array.from(data.value).filter((item) => item.type === "scene")
  62. );
  63. const modules = [Navigation]
  64. const slidePreview = ref(5);
  65. const navigation = ref({
  66. nextEl: ".swiper-button-next",
  67. prevEl: ".swiper-button-prev ",
  68. // hideOnClick: true,
  69. });
  70. const handleWindowResize = () => {
  71. const innerWidth = window.innerWidth;
  72. const pre = Math.ceil(innerWidth / 280);
  73. console.log("slidePreview", pre);
  74. slidePreview.value = pre;
  75. };
  76. const handleClick = (item) => {
  77. emits("changeScene", item);
  78. };
  79. const toggleMenu = () => {
  80. emits('toggleMenu')
  81. }
  82. onMounted(() => {
  83. window.addEventListener("resize", handleWindowResize, false);
  84. handleWindowResize();
  85. });
  86. onUnmounted(() => {
  87. window.removeEventListener("resize", handleWindowResize, false);
  88. });
  89. const onSwiper = (swiper) => {
  90. console.log('onSwiper',swiper);
  91. swiper.value = swiper;
  92. };
  93. const onSlideChange = () => {
  94. console.log("slide change");
  95. };
  96. </script>
  97. <style scoped lang="scss">
  98. .bar {
  99. position: fixed;
  100. z-index: 10;
  101. bottom: -100%;
  102. left: 0;
  103. width: calc(100% - 30px);
  104. height: 206px;
  105. padding-right: 15px;
  106. padding-left: 15px;
  107. box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25);
  108. transition: bottom 0.2s ease-in-out;
  109. // .swiper-button {
  110. // position: absolute;
  111. // top: 60px;
  112. // cursor: pointer;
  113. // }
  114. &.show {
  115. bottom: 0;
  116. }
  117. .close{
  118. position: absolute;
  119. right: 5px;
  120. top: 4px;
  121. width: 18px;
  122. cursor: pointer;
  123. z-index: 10;
  124. }
  125. &::before {
  126. content: " ";
  127. width: 100%;
  128. position: absolute;
  129. top: 0;
  130. left: 0;
  131. height: 146px;
  132. background: rgba(1, 144, 64, 0.9);
  133. }
  134. &::after {
  135. content: " ";
  136. width: 100%;
  137. position: absolute;
  138. bottom: 0;
  139. left: 0;
  140. height: 60px;
  141. background: rgba(255, 255, 255, 0.9);
  142. }
  143. .swiper-slide {
  144. display: flex;
  145. flex-direction: column;
  146. align-items: center;
  147. cursor: pointer;
  148. .cover {
  149. width: 230px;
  150. height: 117px;
  151. margin-top: 20px;
  152. margin-bottom: 10px;
  153. overflow: hidden;
  154. border-radius: 5px;
  155. img {
  156. width: 100%;
  157. height: auto;
  158. object-fit: cover;
  159. }
  160. }
  161. .desc {
  162. width: 230px;
  163. height: 60px;
  164. color: black;
  165. text-align: left;
  166. display: flex;
  167. flex-direction: column;
  168. span.cap {
  169. font-size: 16px;
  170. font-weight: bold;
  171. margin-top: 5px;
  172. }
  173. span.sub {
  174. font-size: 13px;
  175. text-wrap: nowrap;
  176. font-weight: normal;
  177. }
  178. }
  179. }
  180. }
  181. </style>