swiperBg.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <!-- 轮播图 -->
  3. <view class="swiperBg" :style="[boxStyle]">
  4. <view class="swiper page_swiper" :class="docConfig" v-if="imgUrls.length">
  5. <swiper :autoplay="true" :circular="true" :interval="3000" :duration="500"
  6. :indicator-active-color="docColor" :current="swiperCur" :previous-margin="swiperType==0&&imgUrls.length>1?'40rpx':''" :next-margin="swiperType==0&&imgUrls.length>1?'40rpx':''"
  7. @change="swiperChange">
  8. <block v-for="(item,index) in imgUrls" :key="index">
  9. <swiper-item :class="{ active: index == swiperCur }">
  10. <view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper tui-skeleton-rect'>
  11. <image :src="item.img" mode="aspectFill" :style="[imgStyle]" class="slide-image aa"></image>
  12. </view>
  13. </swiper-item>
  14. </block>
  15. </swiper>
  16. <view v-if="docType === 0" class="dots" :style="[dotStyle]">
  17. <block v-for="(item,index) in imgUrls" :key="index">
  18. <view class="dot-item"
  19. :style="{'background-color': swiperCur === index ? (dataConfig.themeStyleConfig.tabVal?dataConfig.docColor.color[0].item:themeColor) : ''}">
  20. </view>
  21. </block>
  22. </view>
  23. <view v-if="docType === 1" class="dots" :style="[dotStyle]">
  24. <block v-for="(item,index) in imgUrls" :key="index">
  25. <view class="dot"
  26. :style="{'background-color': swiperCur === index ? (dataConfig.themeStyleConfig.tabVal?dataConfig.docColor.color[0].item:themeColor) : ''}">
  27. </view>
  28. </block>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. // +----------------------------------------------------------------------
  35. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  36. // +----------------------------------------------------------------------
  37. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  38. // +----------------------------------------------------------------------
  39. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  40. // +----------------------------------------------------------------------
  41. // | Author: CRMEB Team <admin@crmeb.com>
  42. // +----------------------------------------------------------------------
  43. import {
  44. navigatoPage
  45. } from "@/utils/index"
  46. let app = getApp();
  47. export default {
  48. name: 'swiperBg',
  49. props: {
  50. dataConfig: {
  51. type: Object,
  52. default: () => {}
  53. },
  54. merId: {}
  55. },
  56. data() {
  57. return {
  58. indicatorDots: false,
  59. imgUrls: [], //图片轮播数据
  60. txtStyle: this.dataConfig.txtStyle.type, //指示器位置
  61. imageH: 310,
  62. swiperCur: 0,
  63. themeColor:this.$options.filters.filterTheme(app.globalData.theme)
  64. };
  65. },
  66. watch: {
  67. imageH(nVal, oVal) {
  68. let self = this
  69. this.imageH = nVal
  70. }
  71. },
  72. computed: {
  73. //指示器样式
  74. dotStyle() {
  75. return {
  76. padding: '0 50rpx',
  77. justifyContent: this.dataConfig.txtStyle.tabVal === 1 ? 'center' : this.dataConfig.txtStyle
  78. .tabVal === 2 ? 'flex-end' : 'flex-start'
  79. }
  80. },
  81. //指示器类型,0圆,1直,2无
  82. docType() {
  83. return this.dataConfig.docConfig.tabVal
  84. },
  85. //轮播图样式
  86. swiperType(){
  87. return this.dataConfig.swiperStyleConfig.tabVal
  88. },
  89. //最外层盒子的样式
  90. boxStyle() {
  91. return {
  92. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
  93. background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
  94. margin: this.dataConfig.mbConfig.val * 2 + 'rpx' + ' ' + this.dataConfig.lrConfig.val * 2 + 'rpx' +
  95. ' ' + 0,
  96. padding: this.dataConfig.upConfig.val * 2 + 'rpx' + ' ' + '20rpx' + ' ' + this.dataConfig.downConfig.val *
  97. 2 + 'rpx'
  98. }
  99. },
  100. //指示器颜色
  101. docColor() {
  102. return this.dataConfig.docColor.color[0].item + '!important'
  103. },
  104. //指示器样式
  105. docConfig() {
  106. if (this.dataConfig.docConfig.tabVal == 1) {
  107. return 'square'
  108. } else if (this.dataConfig.docConfig.tabVal == 2) {
  109. return 'nodoc'
  110. } else {
  111. return 'circular'
  112. }
  113. },
  114. //内容圆角
  115. imgStyle() {
  116. return {
  117. "border-radius": this.dataConfig.contentStyle.val * 2 + 'rpx'
  118. }
  119. }
  120. },
  121. created() {
  122. this.imgUrls = this.dataConfig.swiperConfig.list
  123. },
  124. mounted() {
  125. let that = this;
  126. this.$nextTick(function() {
  127. uni.getImageInfo({
  128. src: that.setDomain(that.imgUrls[0].img),
  129. success: function(res) {
  130. that.$set(that, 'imageH', res.height);
  131. },
  132. fail: function(error) {
  133. that.$set(that, 'imageH', 310);
  134. }
  135. })
  136. })
  137. },
  138. methods: {
  139. //替换安全域名
  140. setDomain: function(url) {
  141. url = url ? url.toString() : '';
  142. //本地调试打开,生产请注销
  143. if (url.indexOf("https://") > -1) return url;
  144. else return url.replace('http://', 'https://');
  145. },
  146. swiperChange(e) {
  147. let {
  148. current,
  149. source
  150. } = e.detail;
  151. if (source === 'autoplay' || source === 'touch') {
  152. this.swiperCur = e.detail.current;
  153. }
  154. },
  155. goDetail(url) {
  156. let path = url.info[1].value
  157. this.$util.navigateTo(path);
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. /*用来包裹所有的小圆点 */
  164. .dots {
  165. display: flex;
  166. flex-direction: row;
  167. position: absolute;
  168. bottom: 24rpx;
  169. align-items: center;
  170. width: 100%;
  171. }
  172. .dot-item {
  173. width: 10rpx;
  174. height: 10rpx;
  175. background-color: rgba(255, 255, 255, .4);
  176. border-radius: 50%;
  177. margin: 0 6rpx;
  178. }
  179. /*未选中时的小圆点样式 */
  180. .dot {
  181. width: 16rpx;
  182. height: 6rpx;
  183. border-radius: 6rpx;
  184. margin-right: 6rpx;
  185. background-color: rgba(255, 255, 255, .4);
  186. }
  187. .swiperBg {
  188. position: relative;
  189. background: #fff;
  190. z-index: 1;
  191. .colorBg {
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. height: 130rpx;
  196. width: 100%;
  197. }
  198. .page_swiper {
  199. position: relative;
  200. width: 100%;
  201. height: auto;
  202. margin: 0 auto;
  203. border-radius: 10rpx;
  204. overflow-x: hidden;
  205. /* #ifdef MP */
  206. z-index: 20;
  207. /* #endif */
  208. /* 设置圆角 */
  209. &.fillet {
  210. .swiper-item,
  211. image,
  212. .acea-row.row-between-wrapper {
  213. border-radius: 10rpx;
  214. }
  215. }
  216. .swiper-item,
  217. image,
  218. .acea-row.row-between-wrapper {
  219. width: 100%;
  220. height: 100%;
  221. margin: 0 auto;
  222. }
  223. swiper {
  224. width: 100%;
  225. display: block;
  226. }
  227. image {
  228. transform: scale(0.93);
  229. transition: all 0.6s ease;
  230. }
  231. swiper-item.active {
  232. image {
  233. transform: scale(1);
  234. }
  235. }
  236. // 圆形指示点
  237. &.circular {
  238. /deep/.uni-swiper-dot {
  239. width: 10rpx;
  240. height: 10rpx;
  241. }
  242. }
  243. // 方形指示点
  244. &.square {
  245. /deep/.uni-swiper-dot {
  246. width: 20rpx;
  247. height: 5rpx;
  248. border-radius: 3rpx;
  249. }
  250. }
  251. &.nodoc {
  252. /deep/.uni-swiper-dot {
  253. display: none;
  254. }
  255. }
  256. }
  257. }
  258. /deep/.dot0 .uni-swiper-dots-horizontal {
  259. left: 10%;
  260. }
  261. /deep/.dot1 .uni-swiper-dots-horizontal {
  262. left: 50%;
  263. }
  264. /deep/.dot2 .uni-swiper-dots-horizontal {
  265. left: 90%;
  266. }
  267. .item-img image {
  268. display: block;
  269. width: 100%;
  270. }
  271. </style>