swiper.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="swiperContent">
  3. <swiper
  4. @change="change"
  5. @animationfinish="animationfinish"
  6. :indicator-dots="indicatorDots"
  7. :indicator-active-color="indicatorActiveColor"
  8. :indicator-color="indicatorColor"
  9. :autoplay="(autoplay && flag)"
  10. :current="current"
  11. :interval="interval"
  12. :duration="duration"
  13. :circular="circular"
  14. :vertical="vertical"
  15. :previous-margin="previousMargin"
  16. :next-margin="nextMargin"
  17. :display-multiple-items="displayMultipleItems"
  18. :skip-hidden-item-layout="skipHiddenItemLayout"
  19. :style="{'height':swiperHeight+'rpx'}"
  20. :class="(swiperType && displayMultipleItems ==1 && !vertical && !fullScreen)?'cardSwiper':'' "
  21. class="screen-swiper"
  22. >
  23. <swiper-item class="swiper-item"
  24. v-for="(item,index) in swiperList" :key="index"
  25. :class="(cardCur==index && displayMultipleItems ==1 && !vertical && !fullScreen)?'cur':''"
  26. >
  27. <view v-if="item[imageKey] && !item[videoKey]" @click.stop="clickItem(index)">
  28. <image :mode="mode" :src="item[imageKey]" :style="{'height':swiperHeight+'rpx'}"></image>
  29. </view>
  30. <view v-if="item[videoKey]" @click.stop="clickItem(index)">
  31. <video :src="item[videoKey]" @play="play" @pause="pause" :style="{'height':swiperHeight+'rpx'}" autoplay loop muted :autoplay="videoAutoplay" objectFit="cover"></video>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. import jump from '../../../core/routeJump.js';
  39. export default {
  40. name:'bw-swiper',
  41. props: {
  42. mode: {
  43. type: String,
  44. default: 'scaleToFill',
  45. },
  46. swiperHeight: {
  47. type: Number,
  48. default: 350
  49. },
  50. fullScreen:{ // 是否全屏
  51. type:Boolean,
  52. default:false
  53. },
  54. swiperList:{ // 滑块视图容器数据
  55. type:Array,
  56. default:function(){
  57. return []
  58. }
  59. },
  60. swiperType:{
  61. type:Boolean,
  62. default: false
  63. },
  64. videoAutoplay:{
  65. type:Boolean,
  66. default:false
  67. },
  68. videoKey:{
  69. type:String,
  70. default:'src'
  71. },
  72. imageKey:{
  73. type:String,
  74. default:'img'
  75. },
  76. skipHiddenItemLayout:{
  77. type:Boolean,
  78. default:false
  79. },
  80. displayMultipleItems:{
  81. type:Number,
  82. default:1
  83. },
  84. nextMargin:{
  85. type:String,
  86. default:'0px'
  87. },
  88. previousMargin:{
  89. type:String,
  90. default:'0px'
  91. },
  92. vertical:{
  93. type:Boolean,
  94. default:false
  95. },
  96. circular:{
  97. type:Boolean,
  98. default:true
  99. },
  100. duration:{
  101. type:Number,
  102. default:400
  103. },
  104. interval:{
  105. type:Number,
  106. default:2500
  107. },
  108. current:{
  109. type:Number,
  110. default:0
  111. },
  112. autoplay:{
  113. type:Boolean,
  114. default:true
  115. },
  116. indicatorColor:{
  117. type:String,
  118. default:'#CCCCCC'
  119. },
  120. indicatorActiveColor: {
  121. type: String,
  122. default: '#ffffff'
  123. },
  124. indicatorDots: {
  125. type: Boolean,
  126. default: true
  127. }
  128. },
  129. data() {
  130. return {
  131. flag:true,
  132. cardCur:0,
  133. }
  134. },
  135. methods: {
  136. play:function(){
  137. this.flag = false
  138. },
  139. pause:function(){
  140. this.flag = true
  141. },
  142. clickItem:function(index){
  143. console.log(index);
  144. if(this.swiperList.length>0){
  145. jump({open_type : this.swiperList[index].open_type, params: this.swiperList[index].params, page_url: this.swiperList[index].page_url});
  146. this.$emit('clickItem',this.swiperList[index]);
  147. }
  148. },
  149. change:function(e){
  150. this.$emit('change',e)
  151. },
  152. animationfinish:function(e){
  153. this.cardCur = e.detail.current;
  154. this.$emit('animationfinish',e)
  155. }
  156. },
  157. }
  158. </script>
  159. <style lang="scss">
  160. .cardSwiper .swiper-item{
  161. width:86%!important;
  162. overflow: initial;
  163. }
  164. .cardSwiper .swiper-item view{
  165. width: 100%;
  166. display: block;
  167. height: 100%;
  168. border-radius: 10upx;
  169. transform: scale(0.93,0.8);
  170. opacity: 0.7;
  171. transition: all 0.4s ease-in 0s;
  172. overflow: hidden;
  173. box-sizing: border-box;
  174. margin-left:8.1%;
  175. }
  176. .cardSwiper .cur view{
  177. transform: initial;
  178. opacity: 1;
  179. transition: all 0.4s ease-in 0s;
  180. }
  181. .swiper-item view{
  182. height:100%;
  183. width:100%;
  184. position: relative;
  185. }
  186. .swiperText{
  187. position: absolute;
  188. color:#ffffff;
  189. z-index:2;
  190. border-radius: 4upx;
  191. padding:0 4upx;
  192. }
  193. .screen-swiper image{
  194. width:100%;
  195. }
  196. .screen-swiper video,
  197. .swiper-item video {
  198. width: 100%;
  199. display: block;
  200. height: 100%;
  201. }
  202. .swiperContent{
  203. width:100%;
  204. }
  205. </style>