bw-swiper.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="swiperContent">
  3. <swiper
  4. @change="change"
  5. @animationfinish="animationfinish"
  6. :current="current"
  7. :interval="interval"
  8. :duration="duration"
  9. :circular="circular"
  10. :vertical="vertical"
  11. :previous-margin="previousMargin"
  12. :next-margin="nextMargin"
  13. :autoplay="(autoplay && flag)"
  14. :style="{'height':swiperHeight+'px'}"
  15. :class="(swiperType && displayMultipleItems ==1 && !vertical && !fullScreen)?'cardSwiper':'' "
  16. class="screen-swiper"
  17. >
  18. <swiper-item class="swiper-item" v-for="(item,index) in swiperList" :key="index" :class="(cardCur==index && displayMultipleItems ==1 && !vertical && !fullScreen)?'cur':''">
  19. <view class="swiper-box" v-if="item[imageKey] && !item[videoKey]">
  20. <image :src="item[imageKey]"></image>
  21. <view class="swiperText">
  22. <view class="swiperText_name">{{item.name}}</view>
  23. <view>可享受商品折扣: {{item.discount}}%</view>
  24. <view class="flex disdiscount_box" v-if="item.is_clear == false && item.task_list.length > 1">
  25. <view class="" v-for="ls in item.task_list">
  26. <view class="task_name">{{ls.number}}</view>
  27. <view v-if="">{{ls.real_name}}</view>
  28. </view>
  29. </view>
  30. <view class="disdiscount_box" v-if="item.is_clear == false && item.task_list.length == 1">
  31. <view class="" v-for="ls in item.task_list">
  32. <view class="task_name">{{ls.number}}</view>
  33. <view v-if="">{{ls.name}}</view>
  34. </view>
  35. </view>
  36. <view class="is_clear" v-if="item.is_clear == true">该会员等级尚未解锁</view>
  37. </view>
  38. </view>
  39. <view v-if="item[videoKey]">
  40. <video :src="item[videoKey]" @play="play" @pause="pause" :style="{'height':swiperHeight+'px'}" autoplay loop muted :autoplay="videoAutoplay" objectFit="cover"></video>
  41. </view>
  42. </swiper-item>
  43. <swiper-item class="swiper-item" v-if="swiperList.length==0" >
  44. <text></text>
  45. </swiper-item>
  46. </swiper>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. name:'bw-swiper',
  52. created:function(){
  53. var that = this;
  54. if(this.fullScreen){
  55. uni.getSystemInfo({
  56. success:function(e){
  57. that.swiperHeight = e.screenHeight -44
  58. }})
  59. }
  60. },
  61. mounted:function(){
  62. if(!this.fullScreen){
  63. const query = uni.createSelectorQuery().in(this);
  64. query.select('.swiper-item').boundingClientRect(data => {
  65. this.swiperHeight = data.width/this.w_h;
  66. }).exec();
  67. }
  68. },
  69. props: {
  70. fullScreen:{ // 是否全屏
  71. type:Boolean,
  72. default:false
  73. },
  74. swiperList:{ // 滑块视图容器数据
  75. type:Array,
  76. required: true,
  77. default:function(){
  78. return []
  79. }
  80. },
  81. swiperType:{ // false => 全屏限高轮播图 true => 卡塔式轮播图
  82. type:Boolean,
  83. default:true
  84. },
  85. videoAutoplay:{ // true =>自动播放
  86. type:Boolean,
  87. default:false
  88. },
  89. videoKey:{ // 视频映射的键
  90. type:String,
  91. default:'src'
  92. },
  93. imageKey:{ // 图片映射的键
  94. type:String,
  95. default:'image'
  96. },
  97. textKey:{ // 文字说明映射的键
  98. type:String,
  99. default:'name'
  100. },
  101. displayMultipleItems:{ //同时显示的滑块数量
  102. type:Number,
  103. default:1
  104. },
  105. textTip:{ // 图片文字说明 false => 隐藏
  106. type:Boolean,
  107. default:true
  108. },
  109. textStyleSize:{ // 图片文字大小
  110. type:Number,
  111. default:45
  112. },
  113. textStyleTop:{ // 图片文字位置
  114. type:Number,
  115. default:2
  116. },
  117. textStyleLeft:{ // 图片文字位置
  118. type:Number,
  119. default:5
  120. },
  121. textStyleColor:{ // 图片文字颜色
  122. type:String,
  123. default:'#ffffff'
  124. },
  125. textStyleBgcolor:{ // 图片文字背景色
  126. type:String,
  127. default:'transparent'
  128. },
  129. w_h:{ //宽高比 推荐 w/h => 2
  130. type:Number,
  131. default:2
  132. },
  133. nextMargin:{ // 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值 头条小程序不支持
  134. type:String,
  135. default:'0px'
  136. },
  137. previousMargin:{//前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值头条小程序不支持
  138. type:String,
  139. default:'0px'
  140. },
  141. vertical:{ //滑动方向是否为纵向 卡牌 不支持纵向以及同时显示的2块以上滑块数量
  142. type:Boolean,
  143. default:false
  144. },
  145. circular:{ // 是否采用衔接滑动
  146. type:Boolean,
  147. default:true
  148. },
  149. duration:{ // 滑动动画时长
  150. type:Number,
  151. default:400
  152. },
  153. interval:{ // 自动切换时间间隔
  154. type:Number,
  155. default:2500
  156. },
  157. current:{ // 当前所在滑块的 index
  158. type:Number,
  159. default:0
  160. },
  161. autoplay:{ // 是否自动切换
  162. type:Boolean,
  163. default:false
  164. },
  165. indicatorDots: { // 是否显示面板指示点
  166. type: Boolean,
  167. default: false
  168. }
  169. },
  170. data() {
  171. return {
  172. flag:true,
  173. cardCur:0,
  174. swiperHeight:300
  175. }
  176. },
  177. computed:{
  178. },
  179. methods: {
  180. play:function(){
  181. this.flag = false
  182. },
  183. pause:function(){
  184. this.flag = true
  185. },
  186. // clickItem:function(index){
  187. // console.log(index,"66")
  188. // if(this.swiperList.length>0){
  189. // this.$emit('clickItem',this.swiperList[index])
  190. // console.log(this.swiperList[index],55)
  191. // }
  192. // },
  193. change:function(e){
  194. this.$emit('change',e.detail.current)
  195. // console.log(e.detail.current,55)
  196. },
  197. animationfinish:function(e){
  198. this.cardCur = e.detail.current;
  199. this.$emit('animationfinish',e)
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss">
  205. .swiperContent{
  206. background-color: #232323;
  207. }
  208. .cardSwiper .swiper-item{
  209. .swiper-box{
  210. display: block;
  211. transform: scale(0.93,0.8);
  212. opacity: 0.7;
  213. transition: all 0.1s ease-in 0s;
  214. overflow: hidden;
  215. box-sizing: border-box;
  216. height:100%;
  217. position: relative;
  218. width:86%!important;
  219. overflow: initial;
  220. padding: 25rpx 0rpx;
  221. margin-left: 8%;
  222. transform: initial;
  223. opacity: 1;
  224. transition: all 0.1s ease-in 0s;
  225. image{
  226. width: 100%;
  227. height: 100%;
  228. border-radius: 10upx;
  229. }
  230. }
  231. }
  232. .swiperText{
  233. width: 100%;
  234. height: 100%;
  235. position: absolute;
  236. color:#ffffff;
  237. z-index:2;
  238. padding: 45rpx 25rpx;
  239. top:0;
  240. color: rgb(255, 255, 255);
  241. font-size: 28rpx;
  242. .swiperText_name{
  243. font-size: 45rpx;
  244. font-weight: bold;
  245. padding-bottom: 10rpx;
  246. }
  247. .disdiscount_box{
  248. padding: 45rpx 45rpx;
  249. text-align: center;
  250. }
  251. }
  252. .task_name{
  253. font-size: 45rpx;
  254. }
  255. .is_clear{
  256. padding-top: 65rpx;
  257. }
  258. .swiperContent{
  259. width:100%;
  260. }
  261. </style>