ad-swipers.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="swiper-wrap" :style="{height, padding}" v-if="lists.length">
  3. <view class="swiper-con" :style="{borderRadius: radius}">
  4. <template v-if="isSwiper">
  5. <swiper class="swiper" :autoplay="autoplay" :circular="circular" @change="swiperChange"
  6. :previous-margin="previousMargin" display-multiple-items="1">
  7. <swiper-item v-for="(item, index) in lists" :key="index">
  8. <view :data-item="item" style="width:100%;height:100%;" @click="goPage(item)">
  9. <u-image mode="aspectFill" :width="'calc(100% - ' + previousMargin + ')'" height="100%"
  10. :border-radius="radius" :src="item.image"></u-image>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. <view class="dots" v-if="lists.length > 1">
  15. <view v-for="(item, index) in lists" :key="index"
  16. :class="'dot ' + (index == currentSwiper ? 'active' : '')"></view>
  17. </view>
  18. </template>
  19. <template v-lese v-for="(item, index) in lists">
  20. <view :key="index" :data-item="item" style="width:100%;height:100%;" @click="goPage(item)"
  21. v-if="index < 1">
  22. <u-image mode="aspectFill" :width="'calc(100% - ' + previousMargin + ')'" height="100%"
  23. :border-radius="radius" :src="item.image"></u-image>
  24. </view>
  25. </template>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. getAdList
  32. } from '@/api/store';
  33. import {
  34. paramsToStr
  35. } from '@/utils/tools'
  36. export default {
  37. data() {
  38. return {
  39. lists: [],
  40. currentSwiper: 0
  41. };
  42. },
  43. props: {
  44. pid: {
  45. type: Number
  46. },
  47. circular: {
  48. type: Boolean,
  49. default: true
  50. },
  51. autoplay: {
  52. type: Boolean,
  53. default: true
  54. },
  55. height: {
  56. type: String
  57. },
  58. radius: {
  59. type: String,
  60. default: '0'
  61. },
  62. padding: {
  63. type: String,
  64. default: '0rpx'
  65. },
  66. previousMargin: {
  67. type: String,
  68. default: "0rpx"
  69. },
  70. isSwiper: {
  71. type: Boolean,
  72. default: true
  73. }
  74. },
  75. created() {
  76. this.getAdListFun();
  77. },
  78. watch: {
  79. 'pid': function(value) {
  80. this.getAdListFun();
  81. }
  82. },
  83. methods: {
  84. async getAdListFun() {
  85. const {
  86. code,
  87. data
  88. } = await getAdList({
  89. pid: this.pid,
  90. terminal: 1
  91. })
  92. if (code == 1) {
  93. this.lists = data
  94. }
  95. },
  96. swiperChange(e) {
  97. this.currentSwiper = e.detail.current
  98. },
  99. goPage(item) {
  100. let {
  101. link,
  102. link_type,
  103. params,
  104. is_tab
  105. } = item;
  106. switch (link_type) {
  107. case 1:
  108. ""
  109. case 2:
  110. if (is_tab) {
  111. this.$Router.pushTab({
  112. path: link
  113. });
  114. } else {
  115. this.$Router.push({
  116. path: link,
  117. query: params
  118. })
  119. }
  120. break;
  121. case 3:
  122. this.$Router.push({
  123. path: '/pages/webview/webview',
  124. query: {
  125. url: link
  126. }
  127. })
  128. break;
  129. }
  130. }
  131. }
  132. };
  133. </script>
  134. <style lang="scss">
  135. .swiper-wrap {
  136. overflow: hidden;
  137. box-sizing: content-box;
  138. .swiper-con {
  139. position: relative;
  140. height: 100%;
  141. overflow: hidden;
  142. transform: translateY(0);
  143. }
  144. .swiper {
  145. width: 100%;
  146. height: 100%;
  147. position: relative;
  148. .slide-image {
  149. height: 100%;
  150. }
  151. }
  152. .dots {
  153. position: absolute;
  154. left: 50%;
  155. transform: translateX(-50%);
  156. bottom: 20rpx;
  157. display: flex;
  158. .dot {
  159. width: 8rpx;
  160. height: 8rpx;
  161. border-radius: 50%;
  162. margin-right: 10rpx;
  163. background-color: #fff;
  164. &.active {
  165. width: 16rpx;
  166. border-radius: 8rpx;
  167. background-color: $-color-primary;
  168. }
  169. }
  170. }
  171. }
  172. </style>