swipers.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <!-- 轮播图 -->
  3. <view v-show="!isSortType">
  4. <common-wrapper :config="configData">
  5. <view
  6. class="swipers"
  7. :class="[docConfig ? 'square' : 'circular', imgConfig ? '' : 'fillet']"
  8. v-if="imgUrls.length && tabConfig"
  9. >
  10. <swiper
  11. :style="'height:' + (imageH + 10) + 'rpx;'"
  12. indicator-dots="true"
  13. :autoplay="true"
  14. :circular="circular"
  15. :interval="interval"
  16. :duration="duration"
  17. indicator-color="#E4E4E4"
  18. indicator-active-color="#E93323"
  19. :previous-margin="itemEdge + 'rpx'"
  20. :next-margin="itemEdge + 'rpx'"
  21. :current="swiperCur"
  22. @change="swiperChange"
  23. >
  24. <block v-for="(item, index) in imgUrls" :key="index">
  25. <swiper-item :class="{ active: index == swiperCur }">
  26. <navigator
  27. :url="item.info[1].title"
  28. class="slide-navigator acea-row row-between-wrapper"
  29. hover-class="none"
  30. >
  31. <image
  32. :src="item.img"
  33. class="slide-image"
  34. mode="widthFix"
  35. ></image>
  36. </navigator>
  37. </swiper-item>
  38. </block>
  39. </swiper>
  40. </view>
  41. <view v-if="!tabConfig">
  42. <navigator
  43. :url="item.info[1].title"
  44. hover-class="none"
  45. class="advert"
  46. :class="imgConfig ? '' : 'fillet'"
  47. v-for="(item, index) in imgUrls"
  48. :key="index"
  49. >
  50. <image :src="item.img"></image>
  51. </navigator>
  52. </view>
  53. </common-wrapper>
  54. </view>
  55. </template>
  56. <script>
  57. import commonWrapper from "./commonWrapper.vue";
  58. export default {
  59. components: { commonWrapper },
  60. name: "swiper",
  61. props: {
  62. dataConfig: {
  63. type: Object,
  64. default: () => {},
  65. },
  66. isSortType: {
  67. type: String | Number,
  68. default: 0,
  69. },
  70. },
  71. data() {
  72. return {
  73. indicatorDots: false,
  74. circular: true,
  75. autoplay: true,
  76. interval: 2500,
  77. duration: 500,
  78. swiperCur: 0,
  79. imgUrls: [],
  80. docConfig: this.dataConfig.docConfig.type,
  81. imgConfig: this.dataConfig.imgConfig.type,
  82. itemEdge: this.dataConfig.itemEdge.val,
  83. lrConfig: this.dataConfig.lrConfig.val,
  84. mbConfig: this.dataConfig.mbConfig.val,
  85. tabConfig: this.dataConfig.tabConfig.tabVal,
  86. imageH: 0,
  87. };
  88. },
  89. computed: {
  90. configData() {
  91. return {
  92. ...this.dataConfig,
  93. paddingConfig: this.dataConfig.paddingConfig || {
  94. isAll: false,
  95. valList: [
  96. {
  97. val: this.dataConfig.topConfig
  98. ? this.dataConfig.topConfig.val
  99. : 0,
  100. },
  101. {
  102. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  103. },
  104. {
  105. val: this.dataConfig.bottomConfig
  106. ? this.dataConfig.bottomConfig.val
  107. : 0,
  108. },
  109. {
  110. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  111. },
  112. ],
  113. },
  114. marginConfig: this.dataConfig.marginConfig || {
  115. isAll: false,
  116. valList: [
  117. {
  118. val: this.dataConfig.mbConfig ? this.dataConfig.mbConfig.val : 0,
  119. },
  120. {
  121. val: 0,
  122. },
  123. {
  124. val: 0,
  125. },
  126. {
  127. val: 0,
  128. },
  129. ],
  130. },
  131. };
  132. },
  133. },
  134. watch: {
  135. imageH(nVal, oVal) {
  136. this.imageH = nVal;
  137. },
  138. },
  139. created() {
  140. this.imgUrls = this.dataConfig.swiperConfig.list;
  141. },
  142. mounted() {
  143. let that = this;
  144. uni.getImageInfo({
  145. src: that.setDomain(that.imgUrls[0].img),
  146. success: function (res) {
  147. that.$set(that, "imageH", res.height);
  148. },
  149. });
  150. },
  151. methods: {
  152. // swiper
  153. swiperChange(e) {
  154. this.swiperCur = e.detail.current;
  155. },
  156. //替换安全域名
  157. setDomain: function (url) {
  158. url = url ? url.toString() : "";
  159. //本地调试打开,生产请注销
  160. if (url.indexOf("https://") > -1) return url;
  161. else return url.replace("http://", "https://");
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="scss">
  167. .advert {
  168. box-sizing: border-box;
  169. image {
  170. width: 100%;
  171. box-sizing: border-box;
  172. display: block;
  173. }
  174. }
  175. .swipers {
  176. position: relative;
  177. width: 100%;
  178. margin: 0 auto;
  179. border-radius: 10rpx;
  180. /* 设置圆角 */
  181. &.fillet {
  182. border-radius: 10rpx;
  183. image {
  184. border-radius: 10rpx;
  185. }
  186. }
  187. swiper,
  188. .swiper-item,
  189. image {
  190. width: 100%;
  191. }
  192. image {
  193. transform: scale(0.93);
  194. transition: all 0.6s ease;
  195. }
  196. swiper-item.active {
  197. image {
  198. transform: scale(1);
  199. }
  200. }
  201. // 圆形指示点
  202. &.circular {
  203. ::v-deep.uni-swiper-dot {
  204. width: 10rpx !important;
  205. height: 10rpx !important;
  206. background: rgba(0, 0, 0, 0.4) !important;
  207. }
  208. ::v-deep.uni-swiper-dot-active {
  209. background: #fff !important;
  210. }
  211. }
  212. // 方形指示点
  213. &.square {
  214. ::v-deep.uni-swiper-dot {
  215. width: 20rpx !important;
  216. height: 5rpx !important;
  217. border-radius: 3rpx;
  218. background: rgba(0, 0, 0, 0.4) !important;
  219. }
  220. ::v-deep.uni-swiper-dot-active {
  221. background: #fff !important;
  222. }
  223. }
  224. }
  225. </style>