swiperBg.vue 6.4 KB

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