swiperBg.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="swiperBg" :style="'padding-top:' + marginTop +'rpx;background: linear-gradient(180deg, '+ bgColor0 +' 50%, '+ bgColor1 +' 100%);'">
  3. <!-- 单图模式 -->
  4. <block v-if="swiperType == 0">
  5. <view class="item-img" v-for="(item,index) in imgUrls" :key="index" :style="{padding:'0 '+paddinglr+'rpx',marginBottom:itemEdge+'rpx'}">
  6. <image @click="goDetail(item)" :src="item.img"></image></view>
  7. </block>
  8. <block v-else>
  9. <view class="swiper page_swiper" :class="[docConfig == 1 ? 'square' : docConfig == 0 ? 'circular' : 'nodoc',imgConfig ? '' : 'fillet','dot'+txtStyle]"
  10. :style="'padding: 0 '+ paddinglr +'rpx;'"
  11. v-if="imgUrls.length">
  12. <swiper
  13. indicator-dots="true"
  14. :autoplay="true"
  15. :circular="circular"
  16. :interval="interval"
  17. :duration="duration"
  18. indicator-color="rgba(255,255,255,0.6)"
  19. indicator-active-color="#fff"
  20. :style="'height:'+(imageH+10)+'rpx;'"
  21. :current="swiperCur"
  22. @change="swiperChange"
  23. >
  24. <block v-for="(item,index) in imgUrls" :key="index">
  25. <swiper-item :class="{ active: index == swiperCur }">
  26. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
  27. <image :src="item.img" class="slide-image aa" :style="'height:'+ imageH +'rpx;'" mode="aspectFill"></image>
  28. </view>
  29. </swiper-item>
  30. </block>
  31. </swiper>
  32. <!-- <view class="dots" :class="'dot'+txtStyle">
  33. <block v-for="(item,index) in imgUrls" :key="index">
  34. <view class="dot" :class="[docConfig == 1 ? 'square' : docConfig == 0 ? 'circular' : 'nodoc',index == swiperCur ? ' active' : '']"></view>
  35. </block>
  36. </view> -->
  37. </view>
  38. </block>
  39. </view>
  40. </template>
  41. <script>
  42. // +----------------------------------------------------------------------
  43. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  44. // +----------------------------------------------------------------------
  45. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  46. // +----------------------------------------------------------------------
  47. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  48. // +----------------------------------------------------------------------
  49. // | Author: CRMEB Team <admin@crmeb.com>
  50. // +----------------------------------------------------------------------
  51. import {merPath} from "@/utils/index"
  52. export default {
  53. name: 'swiperBg',
  54. props: {
  55. dataConfig: {
  56. type: Object,
  57. default: () => {}
  58. },
  59. merId:{}
  60. },
  61. data() {
  62. return {
  63. indicatorDots: false,
  64. circular: true,
  65. autoplay: true,
  66. interval: 3000,
  67. duration: 500,
  68. imgUrls: [], //图片轮播数据
  69. bgColor0: this.dataConfig.isShow.val ? this.dataConfig.bgColor.color[0].item : 'transparent', //轮播背景颜色
  70. bgColor1: this.dataConfig.isShow.val ? this.dataConfig.bgColor.color[1].item : 'transparent', //轮播背景颜色
  71. marginTop: this.dataConfig.mbConfig.val*2, //组件上边距
  72. paddinglr: this.dataConfig.lrConfig.val*2, //轮播左右边距
  73. docConfig: this.dataConfig.docConfig.type, //指示点样式
  74. imgConfig: this.dataConfig.imgConfig.type, //是否为圆角
  75. txtStyle: this.dataConfig.txtStyle.type, //指示器位置
  76. imageH: 310,
  77. swiperCur: 0,
  78. swiperType: 1,
  79. };
  80. },
  81. watch: {
  82. imageH(nVal, oVal) {
  83. let self = this
  84. this.imageH = nVal
  85. }
  86. },
  87. created() {
  88. this.imgUrls = this.dataConfig.swiperConfig.list
  89. },
  90. mounted() {
  91. let that = this;
  92. that.$nextTick(function() {
  93. uni.getImageInfo({
  94. src: that.setDomain(that.imgUrls[0].img),
  95. success: function(res) {
  96. if (res && res.height > 0) {
  97. let height = res.height * ((750-20) / res.width)
  98. that.$set(that, 'imageH', height);
  99. } else {
  100. that.$set(that, 'imageH', 375);
  101. }
  102. },
  103. fail: function(error) {
  104. that.$set(that, 'imageH', 375);
  105. }
  106. })
  107. })
  108. },
  109. methods: {
  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. swiperChange(e) {
  118. let { current, source } = e.detail;
  119. if (source === 'autoplay' || source === 'touch') {
  120. this.swiperCur = e.detail.current;
  121. }
  122. },
  123. goDetail(url){
  124. let urls = url.info[1].value
  125. urls = merPath(urls, this.merId)
  126. this.$util.JumpPath(urls);
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .swiperBg {
  133. position: relative;
  134. background: #fff;
  135. z-index: 1;
  136. .colorBg {
  137. position: absolute;
  138. left: 0;
  139. top: 0;
  140. height: 130rpx;
  141. width: 100%;
  142. }
  143. .page_swiper {
  144. position: relative;
  145. width: 100%;
  146. box-sizing: border-box;
  147. height: auto;
  148. margin: 0 auto;
  149. border-radius: 10rpx;
  150. overflow-x: hidden;
  151. /* #ifdef MP */
  152. z-index: 20;
  153. /* #endif */
  154. /* 设置圆角 */
  155. &.fillet {
  156. .swiper-item, image, .acea-row.row-between-wrapper{
  157. border-radius: 10rpx;
  158. }
  159. }
  160. .swiper-item, image, .acea-row.row-between-wrapper {
  161. width: 100%;
  162. height:100%;
  163. margin: 0 auto;
  164. }
  165. swiper{
  166. width: 100%;
  167. display: block;
  168. height: auto;
  169. }
  170. image {
  171. transform: scale(0.93);
  172. transition: all 0.6s ease;
  173. }
  174. swiper-item.active {
  175. image {
  176. transform: scale(1);
  177. }
  178. }
  179. }
  180. }
  181. .item-img image{
  182. display: block;
  183. width: 100%;
  184. }
  185. </style>