mBanner.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. let urls = url.info[1].value
  106. if (urls.indexOf("http") != -1) {
  107. // #ifdef H5 || APP-PLUS
  108. location.href = urls
  109. // #endif
  110. } else {
  111. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart',
  112. '/pages/user/index'
  113. ].indexOf(urls) ==
  114. -1) {
  115. uni.navigateTo({
  116. url: urls
  117. })
  118. } else {
  119. uni.navigateTo({
  120. url: urls
  121. })
  122. }
  123. }
  124. })
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .swiperBg {
  131. // background-color: $uni-bg-color;
  132. width: 100%;
  133. }
  134. .empty-img {
  135. width: 690rpx;
  136. // height: 300rpx;
  137. // border-radius: 14rpx;
  138. margin: 26rpx auto 0 auto;
  139. background-color: #ccc;
  140. text-align: center;
  141. line-height: 300rpx;
  142. .iconfont {
  143. font-size: 50rpx;
  144. }
  145. }
  146. .boutique {
  147. margin: 0 $uni-index-margin-col;
  148. // width: 711rpx;
  149. // height: 300rpx;
  150. // margin: 0rpx auto 0 auto;
  151. // padding: 28rpx 0;
  152. }
  153. .boutique swiper {
  154. width: 100%;
  155. position: relative;
  156. }
  157. .boutique image {
  158. width: 100%;
  159. border-radius: 10rpx;
  160. }
  161. .off{
  162. padding: 0rpx 20rpx;
  163. background-color: #fff;
  164. }
  165. .off image {
  166. // border-radius: 0 0 10rpx 10rpx;
  167. }
  168. .boutique .wx-swiper-dot {
  169. width: 7rpx;
  170. height: 7rpx;
  171. border-radius: 50%;
  172. }
  173. .boutique .wx-swiper-dot-active {
  174. width: 20rpx;
  175. border-radius: 5rpx;
  176. }
  177. .boutique .wx-swiper-dots.wx-swiper-dots-horizontal {
  178. margin-bottom: -8rpx;
  179. }
  180. </style>