swiperBg.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. this.$util.JumpPath(url);
  122. })
  123. },
  124. //替换安全域名
  125. setDomain: function(url) {
  126. url = url ? url.toString() : '';
  127. //本地调试打开,生产请注销
  128. if (url.indexOf("https://") > -1) return url;
  129. else return url.replace('http://', 'https://');
  130. },
  131. swiperChange(e) {
  132. // this.swiperCur = e.detail.current
  133. let {
  134. current,
  135. source
  136. } = e.detail
  137. if (source === 'autoplay' || source === 'touch') {
  138. //根据官方 source 来进行判断swiper的change事件是通过什么来触发的,autoplay是自动轮播。touch是用户手动滑动。其他的就是未知问题。抖动问题主要由于未知问题引起的,所以做了限制,只有在自动轮播和用户主动触发才去改变current值,达到规避了抖动bug
  139. this.swiperCur = e.detail.current
  140. }
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .swiperBg /deep/ .uni-swiper-slides {
  147. overflow: hidden;
  148. border-radius: 10rpx;
  149. }
  150. .swiperBg {
  151. background-color: #fff;
  152. position: relative;
  153. margin-top: -20rpx;
  154. padding-top: 4rpx;
  155. .bag {
  156. position: absolute;
  157. top: 0;
  158. width: 100%;
  159. height: 140rpx;
  160. background: linear-gradient(90deg, var(--view-main-start) 0%, var(--view-main-over) 100%);
  161. border-bottom-left-radius: 40rpx;
  162. border-bottom-right-radius: 40rpx;
  163. }
  164. /* #ifdef APP-PLUS */
  165. /* #endif */
  166. .colorBg {
  167. position: absolute;
  168. left: 0;
  169. top: 0;
  170. height: 130rpx;
  171. width: 100%;
  172. }
  173. .swiper {
  174. z-index: 100;
  175. position: relative;
  176. min-height: 200rpx;
  177. padding: 0 $uni-index-margin-col;
  178. /* #ifdef APP-PLUS */
  179. // margin: 0rpx auto 0 auto;
  180. /* #endif */
  181. overflow: hidden;
  182. /* #ifdef MP */
  183. /* #endif */
  184. /* 设置圆角 */
  185. &.fillet {
  186. border-radius: 10rpx;
  187. image {
  188. border-radius: 10rpx;
  189. }
  190. }
  191. swiper,
  192. .swiper-item,
  193. image {
  194. width: 100%;
  195. overflow: hidden;
  196. border-radius: 10rpx;
  197. }
  198. .slide-navigator {}
  199. image {
  200. transform: scale(1);
  201. // transition: all .3s ease;
  202. }
  203. swiper-item.active {
  204. image {
  205. transform: scale(1);
  206. }
  207. }
  208. // 圆形指示点
  209. &.circular {
  210. /deep/.uni-swiper-dot {
  211. width: 10rpx !important;
  212. height: 10rpx !important;
  213. background: rgba(0, 0, 0, .4) !important
  214. }
  215. /deep/.uni-swiper-dot-active {
  216. background: #fff !important
  217. }
  218. }
  219. // 方形指示点
  220. &.square {
  221. /deep/.uni-swiper-dot {
  222. width: 20rpx !important;
  223. height: 5rpx !important;
  224. border-radius: 3rpx;
  225. background: rgba(0, 0, 0, .4) !important
  226. }
  227. /deep/.uni-swiper-dot-active {
  228. background: #fff !important
  229. }
  230. }
  231. }
  232. }
  233. .item-img image {
  234. display: block;
  235. width: 100%;
  236. border-radius: 10rpx;
  237. }
  238. .empty-img {
  239. width: 690rpx;
  240. height: 300rpx;
  241. border-radius: 14rpx;
  242. margin: 26rpx auto 0 auto;
  243. background-color: #ccc;
  244. text-align: center;
  245. line-height: 300rpx;
  246. position: relative;
  247. .iconfont {
  248. font-size: 50rpx;
  249. }
  250. }
  251. </style>