lgSwiper.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="container">
  3. <swiper class="swiper" :circular="true" :autoplay="false" :duration="500" :previous-margin="'200rpx'"
  4. :next-margin="'200rpx'" :style="{ height: '320rpx' }" :current="currentIndex"
  5. :easing-function="easeInOutCubic" @change="changeCurrent">
  6. <swiper-item v-for="(slide, index) in processedSildeItems" :key="index" style="overflow: initial;"
  7. :class="index==currentIndex? 'swiper-item-active':'swiper-item-normal'" @click="swiperClick(slide)">
  8. <view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
  9. <view style="width: 100%;height: 90%;position: relative;">
  10. <image style="width: 100%;height: 100%;" mode="aspectFit"
  11. :src="slide[image]?slide[image]:`${FILE_URL}/peixunyugao.jpg`"></image>
  12. <view style="background: rgb(255 248 248 / 60%);
  13. position: absolute;z-index: 9999;width: 100%;height: 100%;"
  14. :class="index == currentIndex ? 'end-active':'end'"
  15. v-if="slide.status === '2' || slide.status === '3'">
  16. <text style="position: absolute;top: 50%;
  17. left: 50%;transform: translate(-50%,-50%);font-size: 30rpx;">已结束</text>
  18. </view>
  19. </view>
  20. <view class="swiper-text-box">
  21. <text class="swiper-text">{{ slide[title] }}</text>
  22. </view>
  23. </view>
  24. <!-- <view :class="index==currentIndex? 'swiper-item active':'swiper-item'" >
  25. <image style="width: 100%;height: 90%;" mode="aspectFit" :src="slide[image]" ></image>
  26. <text class="swiper-text">{{ slide[title] }}</text>
  27. </view> -->
  28. </swiper-item>
  29. </swiper>
  30. </view>
  31. </template>
  32. <script>
  33. import configService from '@/utils/baseurl.js'
  34. export default {
  35. data() {
  36. return {
  37. currentIndex: 0,
  38. FILE_URL: configService.FILE_URL
  39. };
  40. },
  41. methods: {
  42. changeCurrent(e) {
  43. this.currentIndex = e.detail.current
  44. },
  45. swiperClick(data) {
  46. // console.log(111, data)
  47. this.$emit('swiperClick', data);
  48. }
  49. },
  50. props: {
  51. sildeItems: {
  52. type: Array,
  53. required: true
  54. },
  55. image: {
  56. type: String,
  57. required: false,
  58. default: "image"
  59. },
  60. title: {
  61. type: String,
  62. required: false,
  63. default: "title"
  64. }
  65. },
  66. computed: {
  67. processedSildeItems() {
  68. return [...this.sildeItems, ...this.sildeItems];
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. .container {
  75. display: flex;
  76. justify-content: center;
  77. align-items: center;
  78. }
  79. .swiper {
  80. width: 100%;
  81. overflow: visible;
  82. /* 确保部分滑块可见 */
  83. height: 100%;
  84. padding: 0 25rpx;
  85. }
  86. .swiper-item-active {
  87. z-index: 10;
  88. display: flex;
  89. align-items: center;
  90. .swiper-text {
  91. font-weight: bold;
  92. display: inline-block;
  93. // animation: marquee 10s linear infinite;
  94. /* 以下属性防止文字换行 */
  95. white-space: nowrap;
  96. }
  97. }
  98. .end-active{
  99. top: 0;
  100. // transform: translateY(-5%);
  101. left: 0;
  102. }
  103. .end{
  104. // left: 15rpx;
  105. left: 0;
  106. top: 0;
  107. }
  108. @keyframes marquee {
  109. 0% {
  110. transform: translateX(15%);
  111. }
  112. 100% {
  113. transform: translateX(-100%);
  114. }
  115. }
  116. .swiper-item-normal {
  117. z-index: 1;
  118. display: flex;
  119. align-items: center;
  120. }
  121. .swiper-item {
  122. display: flex;
  123. height: 70%;
  124. width: 85%;
  125. margin: 0 auto;
  126. justify-content: flex-end;
  127. align-items: center;
  128. font-size: 16rpx;
  129. border-radius: 10px;
  130. flex-direction: column;
  131. color: #000;
  132. .swiper-text {
  133. white-space: nowrap;
  134. overflow: hidden;
  135. text-overflow: ellipsis;
  136. // margin-top: 10rpx;
  137. margin-top: 7rpx;
  138. }
  139. .swiper-text-box {
  140. width: 100%;
  141. display: flex;
  142. justify-content: center;
  143. }
  144. }
  145. .active {
  146. // display: flex;
  147. height: 100%;
  148. width: 93%;
  149. margin: auto;
  150. justify-content: center;
  151. font-size: 25rpx;
  152. .swiper-text {
  153. white-space: nowrap;
  154. overflow: hidden;
  155. text-overflow: ellipsis;
  156. margin-top: 5rpx;
  157. }
  158. .swiper-text-box {
  159. width: auto;
  160. display: flex;
  161. justify-content: center;
  162. }
  163. }
  164. </style>