swipers.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view v-show="!isSortType">
  3. <view class="swipers" :class="[docConfig?'square':'circular',imgConfig?'':'fillet']" v-if="imgUrls.length && tabConfig" :style="'padding:0 '+lrConfig+'rpx;margin-top:' + mbConfig +'rpx;'">
  4. <swiper :style="'height:'+(imageH+10)+'rpx;'" indicator-dots="true" :autoplay="true" :circular="circular" :interval="interval" :duration="duration"
  5. indicator-color="#E4E4E4" indicator-active-color="#E93323" :previous-margin="itemEdge+'rpx'" :next-margin="itemEdge+'rpx'" :current="swiperCur"
  6. @change="swiperChange">
  7. <block v-for="(item,index) in imgUrls" :key="index">
  8. <swiper-item :class="{active:index == swiperCur}">
  9. <navigator :url='item.info[1].title' class='slide-navigator acea-row row-between-wrapper' hover-class='none'>
  10. <image :src="item.img" class="slide-image" mode="widthFix"></image>
  11. </navigator>
  12. </swiper-item>
  13. </block>
  14. </swiper>
  15. </view>
  16. <view :style="'margin-top:' + mbConfig +'rpx;'" v-if="!tabConfig">
  17. <navigator :url="item.info[1].title" hover-class="none" class="advert" :class="imgConfig?'':'fillet'" :style="'padding:0 '+lrConfig+'rpx;'" v-for="(item,index) in imgUrls" :key="index">
  18. <image :src="item.img"></image>
  19. </navigator>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'swiper',
  26. props: {
  27. dataConfig: {
  28. type: Object,
  29. default: () => {}
  30. },
  31. isSortType:{
  32. type: String | Number,
  33. default:0
  34. }
  35. },
  36. data() {
  37. return {
  38. indicatorDots: false,
  39. circular: true,
  40. autoplay: true,
  41. interval: 2500,
  42. duration: 500,
  43. swiperCur: 0,
  44. imgUrls: [],
  45. docConfig: this.dataConfig.docConfig.type,
  46. imgConfig: this.dataConfig.imgConfig.type,
  47. itemEdge: this.dataConfig.itemEdge.val,
  48. lrConfig: this.dataConfig.lrConfig.val,
  49. mbConfig: this.dataConfig.mbConfig.val,
  50. tabConfig: this.dataConfig.tabConfig.tabVal,
  51. imageH: 0
  52. };
  53. },
  54. watch:{
  55. imageH(nVal,oVal){
  56. this.imageH = nVal
  57. }
  58. },
  59. created() {
  60. this.imgUrls = this.dataConfig.swiperConfig.list
  61. },
  62. mounted() {
  63. let that = this;
  64. uni.getImageInfo({
  65. src: that.setDomain(that.imgUrls[0].img),
  66. success: function(res) {
  67. that.$set(that, 'imageH', res.height);
  68. }
  69. })
  70. },
  71. methods: {
  72. // swiper
  73. swiperChange(e) {
  74. this.swiperCur = e.detail.current
  75. },
  76. //替换安全域名
  77. setDomain: function(url) {
  78. url = url ? url.toString() : '';
  79. //本地调试打开,生产请注销
  80. if (url.indexOf("https://") > -1) return url;
  81. else return url.replace('http://', 'https://');
  82. },
  83. }
  84. }
  85. </script>
  86. <style lang="scss">
  87. .advert{
  88. box-sizing: border-box;
  89. image{
  90. width: 100%;
  91. box-sizing: border-box;
  92. display: block;
  93. }
  94. }
  95. .swipers {
  96. position: relative;
  97. width: 100%;
  98. margin: 0 auto;
  99. border-radius: 10rpx;
  100. /* 设置圆角 */
  101. &.fillet {
  102. border-radius: 10rpx;
  103. image {
  104. border-radius: 10rpx;
  105. }
  106. }
  107. swiper,
  108. .swiper-item,
  109. image {
  110. width: 100%;
  111. }
  112. image{
  113. transform: scale(.93);
  114. transition: all .6s ease;
  115. }
  116. swiper-item.active {
  117. image {
  118. transform: scale(1);
  119. }
  120. }
  121. // 圆形指示点
  122. &.circular{
  123. /deep/.uni-swiper-dot{
  124. width: 10rpx!important;
  125. height: 10rpx!important;
  126. background: rgba(0,0,0,.4)!important
  127. }
  128. /deep/.uni-swiper-dot-active{
  129. background: #fff!important
  130. }
  131. }
  132. // 方形指示点
  133. &.square{
  134. /deep/.uni-swiper-dot{
  135. width: 20rpx!important;
  136. height: 5rpx!important;
  137. border-radius: 3rpx;
  138. background: rgba(0,0,0,.4)!important
  139. }
  140. /deep/.uni-swiper-dot-active{
  141. background: #fff!important
  142. }
  143. }
  144. }
  145. </style>