swiperBg.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <!-- 带背景轮播图 -->
  3. <view class="swiperBg" :style="[swiperBgStyle]">
  4. <template v-if="dataConfig.swiperConfig.list.length">
  5. <view class="colorBg" :style="[colorBgStyle]"></view>
  6. <view class="swiper">
  7. <swiper :style="'height:'+ imageH +'rpx;'" :autoplay="true" :previous-margin="swiperMargin" :next-margin="swiperMargin" :circular="circular" :interval="interval" :duration="duration"
  8. @change="bannerfun" v-if="imageH">
  9. <swiper-item v-for="(item,index) in dataConfig.swiperConfig.list" :key="index">
  10. <view @click="goDetail(item)" class="swiper-item" :class="{ active: active == index }">
  11. <image :src="item.img" mode="aspectFill" class="image" :style="[imageStyle]"></image>
  12. </view>
  13. </swiper-item>
  14. </swiper>
  15. <view class="noPic" v-else>图片加载中...</view>
  16. <view class="dot acea-row" :style="[dotStyle]">
  17. <view class="progress" v-if="dataConfig.docConfig.tabVal == 2" :style="[progressWidth,dotItemStyle]">
  18. <view class="inner" :style="[progressValue,dotItemActiveStyle]"></view>
  19. </view>
  20. <view class="acea-row" :class="{ small: dataConfig.docConfig.tabVal == 1, line: dataConfig.docConfig.tabVal == 3 }" v-else>
  21. <view class="dot-item" v-for="(item, index) in dataConfig.swiperConfig.list" :key="index" :class="{ active: active == index }"
  22. :style="[active == index ? dotItemActiveStyle : dotItemStyle]"></view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'swiperBg',
  32. props: {
  33. dataConfig: {
  34. type: Object,
  35. default: () => {}
  36. },
  37. isSortType: {
  38. type: String | Number,
  39. default: 0
  40. }
  41. },
  42. data() {
  43. return {
  44. circular: true,
  45. autoplay: true,
  46. interval: 3000,
  47. duration: 500,
  48. imgUrls: [], //图片轮播数据
  49. bgColor: '', //轮播背景颜色
  50. marginTop: 0, //组件上边距
  51. paddinglr: 0, //轮播左右边距
  52. docConfig: 0, //指示点样式
  53. imgConfig: 0, //是否为圆角
  54. imageH: 0,
  55. isColor: 0,
  56. txtStyle: 0,
  57. dotColor: '',
  58. current: 1, //数字指示器当前
  59. active: 0, //一般指示器当前
  60. swiperMargin: '',
  61. swiperMargin: '',
  62. };
  63. },
  64. computed: {
  65. swiperBgStyle() {
  66. return {
  67. padding: `${this.dataConfig.topConfig.val * 2}rpx ${this.dataConfig.prConfig.val * 2}rpx ${this.dataConfig.bottomConfig.val * 2}rpx`,
  68. marginTop: `${this.dataConfig.mbConfig.val * 2}rpx`,
  69. };
  70. },
  71. colorBgStyle() {
  72. let styleObject = {
  73. 'background': this.dataConfig.bgColor.color[0].item,
  74. };
  75. if (this.dataConfig.styleConfig.tabVal == 1) {
  76. styleObject['height'] = '50%';
  77. }
  78. return styleObject;
  79. },
  80. imageStyle() {
  81. return {
  82. borderRadius: `${this.dataConfig.filletImg.val * 2}rpx`,
  83. };
  84. },
  85. dotStyle() {
  86. let styleObject = {};
  87. if (this.dataConfig.docPosition.tabVal) {
  88. styleObject['justify-content'] = this.dataConfig.docPosition.tabVal == 1 ? 'center' : 'flex-end';
  89. }
  90. return styleObject;
  91. },
  92. dotItemStyle() {
  93. let styleObject = {};
  94. if (this.dataConfig.toneConfig.tabVal) {
  95. styleObject['background'] = this.dataConfig.dotBgColor.color[0].item;
  96. }
  97. return styleObject;
  98. },
  99. dotItemActiveStyle() {
  100. let styleObject = {};
  101. if (this.dataConfig.toneConfig.tabVal) {
  102. styleObject['background'] = this.dataConfig.dotColor.color[0].item;
  103. }
  104. return styleObject;
  105. },
  106. progressWidth() {
  107. return {
  108. width: `${this.dataConfig.swiperConfig.list.length * 20}rpx`,
  109. };
  110. },
  111. progressValue() {
  112. return {
  113. width: `${this.current / this.dataConfig.swiperConfig.list.length * 100}%`,
  114. };
  115. },
  116. },
  117. watch: {
  118. imageH(nVal, oVal) {
  119. let self = this
  120. this.imageH = nVal
  121. },
  122. },
  123. created() {
  124. this.imgUrls = this.dataConfig.swiperConfig.list
  125. if (this.dataConfig.styleConfig.tabVal == 2) {
  126. this.swiperMargin = '55rpx';
  127. }
  128. },
  129. mounted() {
  130. if (this.imgUrls.length) {
  131. let that = this;
  132. this.$nextTick((e) => {
  133. uni.getImageInfo({
  134. src: that.setDomain(that.imgUrls[0].img),
  135. success: (res) => {
  136. if (res && res.height > 0) {
  137. // that.$set(that, 'imageH',
  138. // res.height / res
  139. // .width * 750)
  140. let height = res.height * ((750 - this.dataConfig.prConfig.val * 4) / res.width)
  141. that.$set(that, 'imageH', height);
  142. } else {
  143. that.$set(that, 'imageH', 375);
  144. }
  145. },
  146. fail: function(error) {
  147. that.$set(that, 'imageH', 375);
  148. }
  149. })
  150. })
  151. }
  152. },
  153. methods: {
  154. bannerfun(e) {
  155. this.active = e.detail.current;
  156. this.current = e.detail.current + 1;
  157. },
  158. //替换安全域名
  159. setDomain: function(url) {
  160. url = url ? url.toString() : '';
  161. //本地调试打开,生产请注销
  162. if (url.indexOf("https://") > -1) return url;
  163. else return url.replace('http://', 'https://');
  164. },
  165. goDetail(url) {
  166. let urls = url.info[0].value;
  167. this.$util.JumpPath(urls);
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. .noPic {
  174. border-radius: 10rpx;
  175. width: 100%;
  176. height: 300rpx;
  177. background-color: #F0F0F0;
  178. color: #ccc;
  179. text-align: center;
  180. line-height: 300rpx;
  181. font-size: 30rpx;
  182. }
  183. .swiperBg {
  184. position: relative;
  185. .colorBg {
  186. position: absolute;
  187. left: 0;
  188. top: 0;
  189. height: 100%;
  190. width: 100%;
  191. }
  192. .swiper {
  193. z-index: 20;
  194. position: relative;
  195. overflow: hidden;
  196. .dot {
  197. position: absolute;
  198. bottom: 20rpx;
  199. left: 0;
  200. width: 100%;
  201. padding: 0 20rpx;
  202. .dot-item {
  203. width: 12rpx;
  204. height: 12rpx;
  205. border-radius: 6rpx;
  206. margin-right: 16rpx;
  207. background: #DDDDDD;
  208. &:last-child {
  209. margin-right: 0;
  210. }
  211. &.active {
  212. background: var(--view-theme);
  213. }
  214. }
  215. .small {
  216. .dot-item {
  217. width: 10rpx;
  218. height: 10rpx;
  219. border-radius: 5rpx;
  220. margin-right: 8rpx;
  221. &.active {
  222. width: 18rpx;
  223. }
  224. }
  225. }
  226. .line {
  227. .dot-item {
  228. width: 20rpx;
  229. height: 6rpx;
  230. border-radius: 3rpx;
  231. margin-right: 10rpx;
  232. }
  233. }
  234. .progress {
  235. width: 60rpx;
  236. height: 6rpx;
  237. border-radius: 3rpx;
  238. background: #DDDDDD;
  239. .inner {
  240. width: 33%;
  241. height: 6rpx;
  242. border-radius: 3rpx;
  243. background: var(--view-theme);
  244. transition: 0.3s;
  245. }
  246. }
  247. }
  248. .swiper-item {
  249. width: 100%;
  250. height: 100%;
  251. transform: scale(0.9);
  252. transition: 0.3s;
  253. &.active {
  254. transform: scale(1);
  255. }
  256. }
  257. .image {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. // 圆形指示点
  262. &.circular {
  263. /deep/.uni-swiper-dot {
  264. width: 10rpx !important;
  265. height: 10rpx !important;
  266. background: rgba(0, 0, 0, .4) !important
  267. }
  268. /deep/.uni-swiper-dot-active {
  269. background: #fff !important
  270. }
  271. }
  272. // 方形指示点
  273. &.square {
  274. /deep/.uni-swiper-dot {
  275. width: 20rpx !important;
  276. height: 5rpx !important;
  277. border-radius: 3rpx;
  278. background: rgba(0, 0, 0, .4) !important
  279. }
  280. /deep/.uni-swiper-dot-active {
  281. background: #fff !important
  282. }
  283. }
  284. }
  285. }
  286. </style>