swiperBg.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="swiperBg" :style="'margin-top:' + marginTop +'rpx;'">
  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;background: linear-gradient(180deg, '+ bgColor0 +' 50%, '+ bgColor1 +' 100%);'"
  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. :current="swiperCur"
  21. previous-margin="20rpx"
  22. next-margin="20rpx"
  23. @change="swiperChange"
  24. >
  25. <block v-for="(item,index) in imgUrls" :key="index">
  26. <swiper-item :class="{ active: index == swiperCur }">
  27. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
  28. <image :src="item.img" class="slide-image aa"></image>
  29. </view>
  30. </swiper-item>
  31. </block>
  32. </swiper>
  33. </view>
  34. </block>
  35. </view>
  36. </template>
  37. <script>
  38. import {merPath} from "@/utils/index"
  39. export default {
  40. name: 'swiperBg',
  41. props: {
  42. dataConfig: {
  43. type: Object,
  44. default: () => {}
  45. },
  46. merId:{}
  47. },
  48. data() {
  49. return {
  50. indicatorDots: false,
  51. circular: true,
  52. autoplay: true,
  53. interval: 3000,
  54. duration: 500,
  55. imgUrls: [], //图片轮播数据
  56. bgColor0: this.dataConfig.isShow.val ? this.dataConfig.bgColor.color[0].item : 'transparent', //轮播背景颜色
  57. bgColor1: this.dataConfig.isShow.val ? this.dataConfig.bgColor.color[1].item : 'transparent', //轮播背景颜色
  58. marginTop: this.dataConfig.mbConfig.val, //组件上边距
  59. paddinglr: this.dataConfig.lrConfig.val, //轮播左右边距
  60. docConfig: this.dataConfig.docConfig.type, //指示点样式
  61. imgConfig: this.dataConfig.imgConfig.type, //是否为圆角
  62. txtStyle: this.dataConfig.txtStyle.type, //指示器位置
  63. imageH: 310,
  64. swiperCur: 0,
  65. swiperType: 1,
  66. };
  67. },
  68. watch: {
  69. imageH(nVal, oVal) {
  70. let self = this
  71. this.imageH = nVal
  72. }
  73. },
  74. created() {
  75. this.imgUrls = this.dataConfig.swiperConfig.list
  76. },
  77. mounted() {
  78. let that = this;
  79. this.$nextTick(function() {
  80. uni.getImageInfo({
  81. src: that.setDomain(that.imgUrls[0].img),
  82. success: function(res) {
  83. that.$set(that, 'imageH', res.height);
  84. },
  85. fail: function(error) {
  86. that.$set(that, 'imageH', 310);
  87. console.log(error, 'error')
  88. }
  89. })
  90. })
  91. },
  92. methods: {
  93. //替换安全域名
  94. setDomain: function(url) {
  95. url = url ? url.toString() : '';
  96. //本地调试打开,生产请注销
  97. // if (url.indexOf("https://") > -1) return url;
  98. // else return url.replace('http://', 'https://');
  99. },
  100. swiperChange(e) {
  101. let { current, source } = e.detail;
  102. if (source === 'autoplay' || source === 'touch') {
  103. this.swiperCur = e.detail.current;
  104. }
  105. },
  106. goDetail(url){
  107. let urls = url.info[1].value
  108. console.log(urls,'urls');
  109. urls = merPath(urls, this.merId)
  110. if(urls.indexOf("http") != -1){
  111. // #ifdef H5
  112. location.href = urls
  113. // #endif
  114. }else{
  115. if(['/pages/goods_cate/goods_cate','/pages/order_addcart/order_addcart','/pages/user/index','/pages/plant_grass/index'].indexOf(urls) == -1){
  116. uni.navigateTo({
  117. url:urls
  118. })
  119. }else{
  120. uni.switchTab({
  121. url:urls
  122. })
  123. }
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .swiperBg {
  131. position: relative;
  132. background: #fff;
  133. z-index: 1;
  134. .colorBg {
  135. position: absolute;
  136. left: 0;
  137. top: 0;
  138. height: 130rpx;
  139. width: 100%;
  140. }
  141. .page_swiper {
  142. position: relative;
  143. width: 100%;
  144. height: auto;
  145. margin: 0 auto;
  146. border-radius: 10rpx;
  147. overflow-x: hidden;
  148. /* #ifdef MP */
  149. z-index: 20;
  150. /* #endif */
  151. /* 设置圆角 */
  152. &.fillet {
  153. .swiper-item, image, .acea-row.row-between-wrapper{
  154. border-radius: 10rpx;
  155. }
  156. }
  157. .swiper-item, image, .acea-row.row-between-wrapper {
  158. width: 100%;
  159. height:100%;
  160. margin: 0 auto;
  161. }
  162. swiper{
  163. width: 100%;
  164. display: block;
  165. }
  166. image {
  167. transform: scale(0.93);
  168. transition: all 0.6s ease;
  169. }
  170. swiper-item.active {
  171. image {
  172. transform: scale(1);
  173. }
  174. }
  175. // 圆形指示点
  176. &.circular {
  177. /deep/.uni-swiper-dot {
  178. width: 10rpx;
  179. height: 10rpx;
  180. background: rgba(0, 0, 0, .4);
  181. }
  182. /deep/.uni-swiper-dot-active {
  183. background: #fff;
  184. }
  185. }
  186. // 方形指示点
  187. &.square {
  188. /deep/.uni-swiper-dot {
  189. width: 20rpx;
  190. height: 5rpx;
  191. border-radius: 3rpx;
  192. background: rgba(0, 0, 0, .4);
  193. }
  194. /deep/.uni-swiper-dot-active {
  195. background: #fff;
  196. }
  197. }
  198. &.nodoc{
  199. /deep/.uni-swiper-dot {
  200. display: none;
  201. }
  202. }
  203. }
  204. }
  205. /deep/.dot0 .uni-swiper-dots-horizontal{
  206. left: 10%;
  207. }
  208. /deep/.dot1 .uni-swiper-dots-horizontal{
  209. left: 50%;
  210. }
  211. /deep/.dot2 .uni-swiper-dots-horizontal{
  212. left: 90%;
  213. }
  214. .item-img image{
  215. display: block;
  216. width: 100%;
  217. }
  218. </style>