swiperBg.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="swiperBg" :style="{marginTop:mt +'rpx'}">
  3. <view class="bag" v-if="isIframe || (imgUrls.length && isShow)">
  4. </view>
  5. <block v-if="isShow && imgUrls.length">
  6. <view class="swiper square" v-if="imgUrls.length">
  7. <swiper class="skeleton-rect" :style="'height:'+ (imageH) +'rpx;'" indicator-dots="true"
  8. :autoplay="true" :circular="circular" :interval="interval" :duration="duration"
  9. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff" :current="swiperCur"
  10. @change="swiperChange">
  11. <block v-for="(item,index) in imgUrls" :key="index">
  12. <swiper-item class="" :class="{active:index == swiperCur}">
  13. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
  14. <image :src="item.img" class="slide-image" mode="widthFix"
  15. :style="'height:'+ (imageH) +'rpx;'">
  16. </image>
  17. </view>
  18. </swiper-item>
  19. </block>
  20. </swiper>
  21. </view>
  22. </block>
  23. <block v-if="!isShow && isIframe && imgUrls.length && imageH">
  24. <view class="swiper square" v-if="imgUrls.length && imageH" :style="'height:'+ (imageH) +'rpx;'">
  25. <swiper :style="'height:'+ (imageH) +'rpx;'" indicator-dots="true" :autoplay="true" :circular="circular"
  26. :interval="interval" :duration="duration" indicator-color="rgba(255,255,255,0.6)"
  27. indicator-active-color="#fff">
  28. <block v-for="(item,index) in imgUrls" :key="index">
  29. <swiper-item>
  30. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
  31. <image :src="item.img" class="slide-image" mode="widthFix"
  32. :style="'height:'+ (imageH) +'rpx;'">
  33. </image>
  34. </view>
  35. </swiper-item>
  36. </block>
  37. </swiper>
  38. </view>
  39. </block>
  40. <block v-if="isIframe && (!imgUrls.length || !imageH)">
  41. <view class="empty-img">{{$t(`暂无图片,请上传图片`)}}</view>
  42. </block>
  43. </view>
  44. </template>
  45. <script>
  46. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  47. let app = getApp();
  48. import {
  49. goPage
  50. } from '@/libs/order.js'
  51. export default {
  52. name: 'swiperBg',
  53. props: {
  54. dataConfig: {
  55. type: Object,
  56. default: () => {}
  57. },
  58. },
  59. watch: {
  60. dataConfig: {
  61. immediate: true,
  62. handler(nVal, oVal) {
  63. if (nVal) {
  64. this.imgUrls = nVal.imgList ? nVal.imgList.list : [];
  65. this.isShow = nVal.isShow ? nVal.isShow.val : true
  66. uni.getImageInfo({
  67. src: this.imgUrls.length ? this.imgUrls[0].img : '',
  68. success: (res) => {
  69. if (res && res.height > 0) {
  70. this.$set(this, 'imageH',
  71. res.height / res
  72. .width * 690)
  73. } else {
  74. this.$set(this, 'imageH', 320);
  75. }
  76. },
  77. fail: (error) => {
  78. this.$set(this, 'imageH', 320);
  79. }
  80. })
  81. }
  82. }
  83. },
  84. imageH(nVal, oVal) {
  85. let self = this
  86. },
  87. },
  88. data() {
  89. return {
  90. indicatorDots: false,
  91. circular: true,
  92. autoplay: true,
  93. interval: 4000,
  94. duration: 500,
  95. imgUrls: [], //图片轮播数据
  96. name: this.$options.name,
  97. isIframe: false,
  98. mt: -55,
  99. isShow: true,
  100. imageH: 320,
  101. swiperCur: 0,
  102. };
  103. },
  104. created() {
  105. // #ifdef MP || APP-PLUS
  106. const res = uni.getSystemInfoSync()
  107. const system = res.platform
  108. this.statusBarHeight = res.statusBarHeight
  109. if (system === 'android') {
  110. this.mt = parseFloat(statusBarHeight) * 2 + 170
  111. } else {
  112. this.mt = parseFloat(statusBarHeight) * 2 + 168
  113. }
  114. // #endif
  115. this.isIframe = app.globalData.isIframe;
  116. },
  117. mounted() {},
  118. methods: {
  119. goDetail(url) {
  120. goPage().then(res => {
  121. let urls = url.info[1].value
  122. this.$util.JumpPath(urls);
  123. })
  124. },
  125. //替换安全域名
  126. setDomain: function(url) {
  127. url = url ? url.toString() : '';
  128. //本地调试打开,生产请注销
  129. if (url.indexOf("https://") > -1) return url;
  130. else return url.replace('http://', 'https://');
  131. },
  132. swiperChange(e) {
  133. // this.swiperCur = e.detail.current
  134. let {
  135. current,
  136. source
  137. } = e.detail
  138. if (source === 'autoplay' || source === 'touch') {
  139. //根据官方 source 来进行判断swiper的change事件是通过什么来触发的,autoplay是自动轮播。touch是用户手动滑动。其他的就是未知问题。抖动问题主要由于未知问题引起的,所以做了限制,只有在自动轮播和用户主动触发才去改变current值,达到规避了抖动bug
  140. this.swiperCur = e.detail.current
  141. }
  142. },
  143. }
  144. }
  145. </script>
  146. <style lang="scss">
  147. .swiperBg /deep/ .uni-swiper-slides {
  148. overflow: hidden;
  149. border-radius: 10rpx;
  150. }
  151. .swiperBg {
  152. background-color: #fff;
  153. position: relative;
  154. margin-top: -20rpx;
  155. padding-top: 4rpx;
  156. .bag {
  157. position: absolute;
  158. top: 0;
  159. width: 100%;
  160. height: 140rpx;
  161. background: linear-gradient(90deg, var(--view-main-start) 0%, var(--view-main-over) 100%);
  162. border-bottom-left-radius: 40rpx;
  163. border-bottom-right-radius: 40rpx;
  164. }
  165. /* #ifdef APP-PLUS */
  166. /* #endif */
  167. .colorBg {
  168. position: absolute;
  169. left: 0;
  170. top: 0;
  171. height: 130rpx;
  172. width: 100%;
  173. }
  174. .swiper {
  175. z-index: 100;
  176. position: relative;
  177. min-height: 200rpx;
  178. padding: 0 $uni-index-margin-col;
  179. /* #ifdef APP-PLUS */
  180. // margin: 0rpx auto 0 auto;
  181. /* #endif */
  182. overflow: hidden;
  183. /* #ifdef MP */
  184. /* #endif */
  185. /* 设置圆角 */
  186. &.fillet {
  187. border-radius: 10rpx;
  188. image {
  189. border-radius: 10rpx;
  190. }
  191. }
  192. swiper,
  193. .swiper-item,
  194. image {
  195. width: 100%;
  196. overflow: hidden;
  197. border-radius: 10rpx;
  198. }
  199. .slide-navigator {}
  200. image {
  201. transform: scale(1);
  202. // transition: all .3s ease;
  203. }
  204. swiper-item.active {
  205. image {
  206. transform: scale(1);
  207. }
  208. }
  209. // 圆形指示点
  210. &.circular {
  211. /deep/.uni-swiper-dot {
  212. width: 10rpx !important;
  213. height: 10rpx !important;
  214. background: rgba(0, 0, 0, .4) !important
  215. }
  216. /deep/.uni-swiper-dot-active {
  217. background: #fff !important
  218. }
  219. }
  220. // 方形指示点
  221. &.square {
  222. /deep/.uni-swiper-dot {
  223. width: 20rpx !important;
  224. height: 5rpx !important;
  225. border-radius: 3rpx;
  226. background: rgba(0, 0, 0, .4) !important
  227. }
  228. /deep/.uni-swiper-dot-active {
  229. background: #fff !important
  230. }
  231. }
  232. }
  233. }
  234. .item-img image {
  235. display: block;
  236. width: 100%;
  237. border-radius: 10rpx;
  238. }
  239. .empty-img {
  240. width: 690rpx;
  241. height: 300rpx;
  242. border-radius: 14rpx;
  243. margin: 26rpx auto 0 auto;
  244. background-color: #ccc;
  245. text-align: center;
  246. line-height: 300rpx;
  247. position: relative;
  248. .iconfont {
  249. font-size: 50rpx;
  250. }
  251. }
  252. </style>