swiperBg.vue 6.1 KB

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