BambooBookScene3.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <script setup>
  2. import { onMounted, inject, ref, computed } from 'vue'
  3. import useSizeAdapt from "@/useFunctions/useSizeAdapt"
  4. import { Swiper, SwiperSlide } from 'swiper/vue'
  5. import { Pagination } from 'swiper/modules'
  6. // import { Pagination } from 'swiper'
  7. // import 'swiper/css'
  8. // import 'swiper/css/pagination'
  9. const $env = inject('$env')
  10. const {
  11. windowSizeInCssForRef,
  12. windowSizeWhenDesignForRef,
  13. } = useSizeAdapt()
  14. const emit = defineEmits(['close'])
  15. const props = defineProps({
  16. list: {
  17. type: Array,
  18. default: () => { return [] },
  19. },
  20. })
  21. const modules = [Pagination]
  22. const swiperRef = ref(null) // 用于访问Swiper实例
  23. const swiperRealIndex = ref(0)
  24. const displayedPages = ref([])
  25. const currentIndex = ref(0)
  26. const slideChange = (item) => {
  27. swiperRealIndex.value = item.activeIndex
  28. // 这里只是一个简单的示例,根据实际需要调整逻辑
  29. const totalSlides = props.list.length // 总幻灯片数量
  30. const visibleRange = 5 // 每次显示的分页指示器数量(可以根据需要调整)
  31. currentIndex.value = swiperRealIndex.value % 5// 当前幻灯片索引
  32. // console.log('currentIndex', currentIndex)
  33. // displayedPages.value = totalSlides / 5
  34. // let start = Math.max(0, currentIndex.value - Math.floor(visibleRange / 2))
  35. // let end = Math.min(totalSlides - 1, start + visibleRange - 1)
  36. if (swiperRealIndex.value >= totalSlides - totalSlides % visibleRange ) {
  37. displayedPages.value = Array.from({ length: totalSlides % visibleRange }, (_, i) => 0 + i)
  38. // console.log('displayedPages', totalSlides, visibleRange, swiperRealIndex.value, displayedPages.value)
  39. } else {
  40. displayedPages.value = Array.from({ length: 5 }, (_, i) => 0 + i)
  41. }
  42. console.log('displayedPages', totalSlides, visibleRange, swiperRealIndex.value, displayedPages.value)
  43. }
  44. // 跳转到指定幻灯片
  45. const goToSlide = (index) => {
  46. swiperRef.value.slideTo(index)
  47. }
  48. onMounted(() => {
  49. const totalSlides = props.list.length // 总幻灯片数量
  50. const visibleRange = 5 // 每次显示的分页指示器数量(可以根据需要调整)
  51. const currentIndex = swiperRealIndex.value// 当前幻灯片索引
  52. let start = Math.max(0, currentIndex - Math.floor(visibleRange / 2))
  53. let end = Math.min(totalSlides - 1, start + visibleRange - 1)
  54. displayedPages.value = Array.from({ length: end - start + 1 }, (_, i) => start + i)
  55. })
  56. </script>
  57. <template>
  58. <div class="screen-box">
  59. <div class="screen-box3">
  60. <Swiper
  61. ref="swiperRef"
  62. class="step-list"
  63. :modules="modules"
  64. @slide-change="slideChange"
  65. >
  66. <SwiperSlide
  67. v-for="(item, index) in list"
  68. :key="index"
  69. class="step-item"
  70. >
  71. <!-- <div>{{ item['名称'] }}</div> -->
  72. <div class="name-box">
  73. {{ item['画法'] }}
  74. <div class="name-box2">
  75. {{ item['名称'] }}
  76. </div>
  77. <!-- <div
  78. v-for="(item1,index1) in item['显示名称']"
  79. :key="index1"
  80. >
  81. {{ item1 }}
  82. </div> -->
  83. </div>
  84. <img
  85. :src="`${$env.BASE_URL}configMultiMedia/zhupuImages/${item['图片名称'] ? item['图片名称'] : item['名称']}.png`"
  86. alt=""
  87. >
  88. </SwiperSlide>
  89. </Swiper>
  90. <!-- 自定义分页器 -->
  91. <div class="custom-pagination">
  92. <span
  93. v-for="(index, i) in displayedPages"
  94. :key="i"
  95. :class="{ 'pagination-bullet': true, 'swiper-pagination-bullet-active': index === currentIndex }"
  96. @click="goToSlide(index)"
  97. />
  98. </div>
  99. <div class="system-btns">
  100. <BtnBack @click="emit('close')" />
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. <style lang='less' scoped>
  106. ::v-deep {
  107. .swiper-pagination-bullet {
  108. border: 1px solid white;
  109. background: none;
  110. width: 10px;
  111. height: 10px;
  112. opacity: 1;
  113. }
  114. .swiper-pagination-bullet-active {
  115. background: white;
  116. }
  117. .swiper-horizontal>.swiper-pagination-bullets .swiper-pagination-bullet,
  118. .swiper-pagination-horizontal.swiper-pagination-bullets .swiper-pagination-bullet {
  119. margin: 0 calc(5 / v-bind(windowSizeWhenDesignForRef) * v-bind(windowSizeInCssForRef));
  120. }
  121. .custom-pagination {
  122. width: 100%;
  123. height: 10px;
  124. display: flex;
  125. justify-content: center;
  126. align-items: center;
  127. position: fixed;
  128. bottom: calc(30 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  129. span {
  130. width: 10px;
  131. height: 10px;
  132. margin: 0 calc(5 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  133. border-radius: 50px;
  134. border: 1px solid rgb(245, 243, 243);
  135. }
  136. }
  137. }
  138. .screen-box {
  139. width: 100%;
  140. height: 100%;
  141. position: relative;
  142. .screen-box3 {
  143. width: 100%;
  144. height: 100%;
  145. background: url(@/assets/images/screen-box3.png);
  146. background-size: cover;
  147. .step-list {
  148. width: 100%;
  149. height: calc(100% - 15px);
  150. .step-item {
  151. width: 100%;
  152. height: 100%;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. position: relative;
  157. >.name-box {
  158. position: absolute;
  159. left: calc(70 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  160. top: calc(100 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  161. writing-mode: vertical-rl;
  162. letter-spacing: 12px;
  163. background: url(@/assets/images/name-bg.png);
  164. background-size: 100% 100%;
  165. padding: 10px;
  166. color: #476446;
  167. font-family: 'KingHwa_OldSong';
  168. font-size: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  169. line-height: calc(29 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  170. // >:nth-child(odd){
  171. // color:#7B916B;
  172. // font-size: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  173. // line-height: calc(21 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  174. // transform: translateX(-40%)
  175. // }
  176. .name-box2 {
  177. position: absolute;
  178. bottom: 0;
  179. right: 0;
  180. transform: translate(100%, 30%);
  181. writing-mode: vertical-rl;
  182. letter-spacing: 8px;
  183. font-family: 'KingHwa_OldSong';
  184. font-size: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  185. line-height: calc(19 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  186. color: #7B916B;
  187. white-space: nowrap;
  188. }
  189. }
  190. >img {
  191. // width: 40%;
  192. max-width: 80%;
  193. margin-left: calc(50 /v-bind('windowSizeWhenDesignForRef')* v-bind('windowSizeInCssForRef'))
  194. }
  195. }
  196. }
  197. .system-btns {
  198. width: 100%;
  199. padding: 0 calc(20 / v-bind(windowSizeWhenDesignForRef) * v-bind(windowSizeInCssForRef));
  200. display: flex;
  201. justify-content: space-between;
  202. position: absolute;
  203. bottom: calc(20 /v-bind(windowSizeWhenDesignForRef) * v-bind(windowSizeInCssForRef));
  204. z-index: 2;
  205. }
  206. }
  207. }
  208. </style>