NavigationBar.vue 5.5 KB

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