swipers.vue 3.6 KB

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