swiperBg.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="swiperBg skeleton-rect" :style="'margin-top:' + marginTop*2 +'rpx;'" v-show="!isSortType">
  3. <block v-if="imgUrls.length">
  4. <view class="colorBg"
  5. :style="'background: linear-gradient(90deg, '+ bgColor[0].item +' 50%, '+ bgColor[1].item +' 100%);'"
  6. v-if="isColor"></view>
  7. <view class="swiper" :class="[imgConfig?'':'fillet']" :style="'padding: 0 '+ paddinglr +'rpx;'">
  8. <swiper :style="'height:'+ imageH +'rpx;'" :autoplay="true" :circular="circular" :interval="interval"
  9. :duration="duration" indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff"
  10. @change='bannerfun'>
  11. <block v-for="(item,index) in imgUrls" :key="index">
  12. <swiper-item>
  13. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
  14. <image :src="item.img" mode="aspectFill" class="slide-image aa"
  15. :style="'height:'+ imageH +'rpx;'">
  16. </image>
  17. </view>
  18. </swiper-item>
  19. </block>
  20. </swiper>
  21. <view v-if="docConfig==0" class="dot acea-row"
  22. :style="{paddingLeft: paddinglr+20 + 'rpx',paddingRight: paddinglr+20 + 'rpx',justifyContent: (txtStyle==1?'center':txtStyle==2?'flex-end':'flex-start')}">
  23. <view class="dot-item" :style="active==index?'background:'+ dotColor:''"
  24. v-for="(item,index) in imgUrls"></view>
  25. </view>
  26. <view v-if="docConfig==1" class="dot acea-row"
  27. :style="{paddingLeft: paddinglr+20 + 'rpx',paddingRight: paddinglr+20 + 'rpx',justifyContent: (txtStyle==1?'center':txtStyle==2?'flex-end':'flex-start')}">
  28. <view class="dot-item line_dot-item" :style="active==index?'background:'+ dotColor:''"
  29. v-for="(item,index) in imgUrls"></view>
  30. </view>
  31. <view v-if="docConfig==2" class="dot acea-row"
  32. :style="{paddingLeft: paddinglr+20 + 'rpx',paddingRight: paddinglr+20 + 'rpx',justifyContent: (txtStyle==1?'center':txtStyle==2?'flex-end':'flex-start')}">
  33. <view class="instruct">{{current}}/{{imgUrls.length}}</view>
  34. </view>
  35. </view>
  36. </block>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'swiperBg',
  42. props: {
  43. dataConfig: {
  44. type: Object,
  45. default: () => {}
  46. },
  47. isSortType: {
  48. type: String | Number,
  49. default: 0
  50. }
  51. },
  52. data() {
  53. return {
  54. circular: true,
  55. autoplay: true,
  56. interval: 3000,
  57. duration: 500,
  58. imgUrls: [], //图片轮播数据
  59. bgColor: this.dataConfig.bgColor.color, //轮播背景颜色
  60. marginTop: this.dataConfig.mbConfig.val, //组件上边距
  61. paddinglr: (this.dataConfig.lrConfig.val) * 2, //轮播左右边距
  62. docConfig: this.dataConfig.docConfig.type, //指示点样式
  63. imgConfig: this.dataConfig.imgConfig.type, //是否为圆角
  64. imageH: 280,
  65. isColor: this.dataConfig.isShow.val,
  66. txtStyle: this.dataConfig.txtStyle.type,
  67. dotColor: this.dataConfig.dotColor.color[0].item,
  68. current: 1, //数字指示器当前
  69. active: 0 //一般指示器当前
  70. };
  71. },
  72. watch: {
  73. imageH(nVal, oVal) {
  74. let self = this
  75. this.imageH = nVal
  76. },
  77. },
  78. created() {
  79. this.imgUrls = this.dataConfig.swiperConfig.list
  80. },
  81. mounted() {
  82. if (this.imgUrls.length) {
  83. let that = this;
  84. this.$nextTick((e) => {
  85. uni.getImageInfo({
  86. src: that.imgUrls[0].img,
  87. success: (res) => {
  88. if (res && res.height > 0) {
  89. // that.$set(that, 'imageH',
  90. // res.height / res
  91. // .width * 750)
  92. let height = res.height * ((750 - this.paddinglr * 2) / res.width)
  93. that.$set(that, 'imageH', height);
  94. } else {
  95. that.$set(that, 'imageH', 375);
  96. }
  97. },
  98. fail: function(error) {
  99. that.$set(that, 'imageH', 375);
  100. }
  101. })
  102. })
  103. }
  104. },
  105. methods: {
  106. bannerfun(e) {
  107. this.active = e.detail.current;
  108. this.current = e.detail.current + 1;
  109. },
  110. //替换安全域名
  111. setDomain: function(url) {
  112. url = url ? url.toString() : '';
  113. //本地调试打开,生产请注销
  114. if (url.indexOf("https://") > -1) return url;
  115. else return url.replace('http://', 'https://');
  116. },
  117. goDetail(url) {
  118. let urls = url.info[1].value
  119. if (urls.indexOf("http") != -1) {
  120. // #ifdef H5
  121. location.href = urls
  122. // #endif
  123. // #ifdef MP || APP-PLUS
  124. uni.navigateTo({
  125. url: `/pages/annex/web_view/index?url=${urls}`
  126. });
  127. // #endif
  128. } else {
  129. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index']
  130. .indexOf(urls) == -1) {
  131. uni.navigateTo({
  132. url: urls
  133. })
  134. } else {
  135. uni.reLaunch({
  136. url: urls
  137. })
  138. }
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. .swiperBg {
  146. position: relative;
  147. // #ifdef APP-PLUS
  148. // padding-top: 100rpx;
  149. // #endif
  150. .colorBg {
  151. position: absolute;
  152. left: 0;
  153. top: 0;
  154. height: 130rpx;
  155. width: 100%;
  156. }
  157. .swiper {
  158. z-index: 20;
  159. position: relative;
  160. overflow: hidden;
  161. .dot {
  162. position: absolute;
  163. left: 0;
  164. bottom: 20rpx;
  165. width: 100%;
  166. .instruct {
  167. width: 50rpx;
  168. height: 36rpx;
  169. line-height: 36rpx;
  170. background-color: #bfc1c4;
  171. color: #fff;
  172. border-radius: 16rpx;
  173. font-size: 24rpx;
  174. text-align: center;
  175. }
  176. .dot-item {
  177. width: 10rpx;
  178. height: 10rpx;
  179. background: rgba(0, 0, 0, .4);
  180. border-radius: 50%;
  181. margin: 0 4px;
  182. &.line_dot-item {
  183. width: 20rpx;
  184. height: 5rpx;
  185. border-radius: 3rpx;
  186. }
  187. }
  188. }
  189. /* 设置圆角 */
  190. &.fillet {
  191. border-radius: 10rpx;
  192. image {
  193. border-radius: 10rpx;
  194. }
  195. }
  196. swiper,
  197. .swiper-item,
  198. image {
  199. width: 100%;
  200. display: block;
  201. }
  202. // 圆形指示点
  203. &.circular {
  204. /deep/.uni-swiper-dot {
  205. width: 10rpx !important;
  206. height: 10rpx !important;
  207. background: rgba(0, 0, 0, .4) !important
  208. }
  209. /deep/.uni-swiper-dot-active {
  210. background: #fff !important
  211. }
  212. }
  213. // 方形指示点
  214. &.square {
  215. /deep/.uni-swiper-dot {
  216. width: 20rpx !important;
  217. height: 5rpx !important;
  218. border-radius: 3rpx;
  219. background: rgba(0, 0, 0, .4) !important
  220. }
  221. /deep/.uni-swiper-dot-active {
  222. background: #fff !important
  223. }
  224. }
  225. }
  226. }
  227. .item-img image {
  228. display: block;
  229. width: 100%;
  230. }
  231. </style>