mBanner.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="swiperBg">
  3. <view class='boutique' :class="{'off': sty ==='off'}" v-if="isShow && bastBanner.length && !isIframe">
  4. <swiper autoplay="true" indicator-dots="true" :circular="circular" :interval="interval" :duration="duration"
  5. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff" :style="'height:'+ (imageH) +'rpx;'">
  6. <block v-for="(item,index) in bastBanner">
  7. <swiper-item :key='index'>
  8. <view style='width:100%;height:100%;' hover-class='none' @click="goDetail(item)">
  9. <image :src="item.img" class="slide-image" :style="'height:'+ (imageH) +'rpx;'" />
  10. </view>
  11. </swiper-item>
  12. </block>
  13. </swiper>
  14. </view>
  15. <view class='boutique' :style="'height:'+ (imageH) +'rpx;'" v-if="bastBanner.length && isIframe">
  16. <swiper autoplay="true" indicator-dots="true" :style="'height:'+ (imageH) +'rpx;'" :circular="circular" :interval="interval" :duration="duration"
  17. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  18. <block v-for="(item,index) in bastBanner">
  19. <swiper-item :key='index'>
  20. <view style='width:100%;height:100%;' hover-class='none' @click="goDetail(item)">
  21. <image :src="item.img" class="slide-image" :style="'height:'+ (imageH) +'rpx;'"/>
  22. </view>
  23. </swiper-item>
  24. </block>
  25. </swiper>
  26. </view>
  27. <block v-if="isIframe && !bastBanner.length">
  28. <view class="empty-img">{{$t(`暂无图片,请上传图片`)}}</view>
  29. </block>
  30. </view>
  31. </template>
  32. <script>
  33. let app = getApp()
  34. import {
  35. goPage
  36. } from '@/libs/order.js'
  37. export default {
  38. name: 'swiperBg',
  39. props: {
  40. dataConfig: {
  41. type: Object,
  42. default: () => {}
  43. },
  44. sty: {
  45. type: String,
  46. default: 'on'
  47. }
  48. },
  49. data() {
  50. return {
  51. indicatorDots: false,
  52. circular: true,
  53. autoplay: true,
  54. interval: 3000,
  55. duration: 500,
  56. bastBanner: [], //图片轮播数据
  57. name: this.$options.name,
  58. isIframe: false,
  59. isShow: true,
  60. imageH: 375
  61. };
  62. },
  63. watch: {
  64. dataConfig: {
  65. immediate: true,
  66. handler(nVal, oVal) {
  67. if (nVal) {
  68. this.bastBanner = nVal.imgList.list;
  69. this.isShow = nVal.isShow.val;
  70. this.imgUrls = nVal.imgList ? nVal.imgList.list : [];
  71. this.isShow = nVal.isShow ? nVal.isShow.val : true
  72. uni.getImageInfo({
  73. src: this.imgUrls.length ? this.imgUrls[0].img : '',
  74. success: (res) => {
  75. if (res && res.height > 0) {
  76. this.$set(this, 'imageH',
  77. res.height / res
  78. .width * 690)
  79. } else {
  80. this.$set(this, 'imageH', 375);
  81. }
  82. },
  83. fail: (error) => {
  84. this.$set(this, 'imageH', 375);
  85. }
  86. })
  87. }
  88. }
  89. }
  90. },
  91. created() {
  92. this.isIframe = app.globalData.isIframe
  93. },
  94. mounted() {},
  95. methods: {
  96. //替换安全域名
  97. setDomain: function(url) {
  98. url = url ? url.toString() : '';
  99. //本地调试打开,生产请注销
  100. if (url.indexOf("https://") > -1) return url;
  101. else return url.replace('http://', 'https://');
  102. },
  103. goDetail(url) {
  104. goPage().then(res => {
  105. this.$util.JumpPath(urls);
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. .swiperBg {
  113. // background-color: $uni-bg-color;
  114. width: 100%;
  115. }
  116. .empty-img {
  117. width: 690rpx;
  118. // height: 300rpx;
  119. // border-radius: 14rpx;
  120. margin: 26rpx auto 0 auto;
  121. background-color: #ccc;
  122. text-align: center;
  123. line-height: 300rpx;
  124. .iconfont {
  125. font-size: 50rpx;
  126. }
  127. }
  128. .boutique {
  129. margin: 0 $uni-index-margin-col;
  130. // width: 711rpx;
  131. // height: 300rpx;
  132. // margin: 0rpx auto 0 auto;
  133. // padding: 28rpx 0;
  134. }
  135. .boutique swiper {
  136. width: 100%;
  137. position: relative;
  138. }
  139. .boutique image {
  140. width: 100%;
  141. border-radius: 10rpx;
  142. }
  143. .off{
  144. padding: 0rpx 20rpx;
  145. background-color: #fff;
  146. }
  147. .off image {
  148. // border-radius: 0 0 10rpx 10rpx;
  149. }
  150. .boutique .wx-swiper-dot {
  151. width: 7rpx;
  152. height: 7rpx;
  153. border-radius: 50%;
  154. }
  155. .boutique .wx-swiper-dot-active {
  156. width: 20rpx;
  157. border-radius: 5rpx;
  158. }
  159. .boutique .wx-swiper-dots.wx-swiper-dots-horizontal {
  160. margin-bottom: -8rpx;
  161. }
  162. </style>