swiperBg.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. this.$util.JumpPath(urls);
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .noPic{
  121. border-radius: 10rpx;
  122. width: 100%;
  123. height: 300rpx;
  124. background-color: #F0F0F0;
  125. color: #ccc;
  126. text-align: center;
  127. line-height: 300rpx;
  128. font-size: 30rpx;
  129. }
  130. .swiperBg {
  131. position: relative;
  132. // #ifdef APP-PLUS
  133. // padding-top: 100rpx;
  134. // #endif
  135. .colorBg {
  136. position: absolute;
  137. left: 0;
  138. top: 0;
  139. height: 130rpx;
  140. width: 100%;
  141. }
  142. .swiper {
  143. z-index: 20;
  144. position: relative;
  145. overflow: hidden;
  146. .dot{
  147. position: absolute;
  148. left:0;
  149. bottom: 20rpx;
  150. width: 100%;
  151. .instruct {
  152. width: 50rpx;
  153. height: 36rpx;
  154. line-height: 36rpx;
  155. background-color: rgba(0,0,0,0.8);
  156. color: #fff;
  157. border-radius: 16rpx;
  158. font-size: 24rpx;
  159. text-align: center;
  160. }
  161. .dot-item{
  162. width: 10rpx;
  163. height: 10rpx;
  164. background: rgba(0, 0, 0, .4);
  165. border-radius: 50%;
  166. margin: 0 4px;
  167. &.line_dot-item{
  168. width: 20rpx;
  169. height: 5rpx;
  170. border-radius: 3rpx;
  171. }
  172. }
  173. }
  174. /* 设置圆角 */
  175. &.fillet {
  176. border-radius: 10rpx;
  177. image {
  178. border-radius: 10rpx;
  179. }
  180. }
  181. swiper,
  182. .swiper-item,
  183. image {
  184. width: 100%;
  185. display: block;
  186. }
  187. // 圆形指示点
  188. &.circular {
  189. /deep/.uni-swiper-dot {
  190. width: 10rpx !important;
  191. height: 10rpx !important;
  192. background: rgba(0, 0, 0, .4) !important
  193. }
  194. /deep/.uni-swiper-dot-active {
  195. background: #fff !important
  196. }
  197. }
  198. // 方形指示点
  199. &.square {
  200. /deep/.uni-swiper-dot {
  201. width: 20rpx !important;
  202. height: 5rpx !important;
  203. border-radius: 3rpx;
  204. background: rgba(0, 0, 0, .4) !important
  205. }
  206. /deep/.uni-swiper-dot-active {
  207. background: #fff !important
  208. }
  209. }
  210. }
  211. }
  212. .item-img image {
  213. display: block;
  214. width: 100%;
  215. }
  216. </style>