app-swiper.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="swiper">
  3. <swiper v-if="mode === 'card'" :style="{height: `${height - 30}rpx`}" class="app-swiper-tall"
  4. indicator-dots :previous-margin="previousMargin"
  5. :next-margin="nextMargin" circular autoplay @change="change" :current="swiperCurrentIndex">
  6. <swiper-item class="app-swiper-container" v-for="(item,index) in list" :key="index"
  7. :item-id="index" :data-year="index">
  8. <view class="app-sw">
  9. <app-jump-button height="100" width="100" :open_type="item.open_type" :url="item.url" form>
  10. <view class="app-swiper-item"
  11. :style="{background:item.pic_url?('url('+ item.pic_url +') center no-repeat'):'',height: `${height}rpx`, backgroundSize: `${fill === 0 ? 'contain' : fill === 1 ? 'cover' : 'cover'}`}"
  12. :animation="animationData[index]">
  13. </view>
  14. </app-jump-button>
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. <swiper v-else-if="mode === 'screen'" :style="{height: `${height}rpx`}" autoplay indicator-dots circular>
  19. <swiper-item v-for="(item, index) in list" :key="index">
  20. <view class="app-swiper-image">
  21. <app-jump-button height="100" width="100" :open_type="item.open_type" :url="item.page_url" form>
  22. <view class="app-swiper-item-w"
  23. :style="{background:item?('url('+ item.pic_url +') center no-repeat'):'', backgroundSize: `${fill === 0 ? 'contain' : fill === 1 ? 'cover' : 'cover'}`}"></view>
  24. </app-jump-button>
  25. </view>
  26. </swiper-item>
  27. </swiper>
  28. </view>
  29. </template>
  30. <script>
  31. import appJumpButton from '../../basic-component/app-jump-button/app-jump-button.vue';
  32. export default {
  33. components: {
  34. 'app-jump-button': appJumpButton,
  35. },
  36. props: {
  37. mode: {
  38. type: String,
  39. default: 'screen',
  40. },
  41. list: {
  42. type: Array,
  43. default() {
  44. return [];
  45. }
  46. },
  47. height: {
  48. type: Number,
  49. default() {
  50. return 350;
  51. }
  52. },
  53. fill: {
  54. type: Number,
  55. default() {
  56. return 1;
  57. }
  58. },
  59. },
  60. data() {
  61. return {
  62. animationData: {
  63. 0: {},
  64. 1: {},
  65. 2: {},
  66. 3: {},
  67. },
  68. previousMargin: uni.upx2px(80) + 'px',
  69. nextMargin: uni.upx2px(80) + 'px',
  70. zoomParam: 1.10,
  71. swiperCurrentIndex: 0,
  72. imgs: [
  73. 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
  74. 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
  75. 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
  76. 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
  77. ]
  78. }
  79. },
  80. created() {
  81. this.animation = uni.createAnimation();
  82. this.animation.scale(this.zoomParam).step();
  83. this.animationData[0] = this.animation.export();
  84. },
  85. methods: {
  86. change(e) {
  87. this.swiperCurrentIndex = e.detail.current;
  88. for (let key in this.animationData) {
  89. if (e.detail.currentItemId == key) {
  90. this.animation.scale(this.zoomParam).step();
  91. this.animationData[key] = this.animation.export();
  92. } else {
  93. this.animation.scale(1.0).step();
  94. this.animationData[key] = this.animation.export();
  95. }
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .app-swiper-container {
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. }
  107. .app-swiper-item {
  108. width: #{530rpx};
  109. text-align: center;
  110. border-radius: #{6rpx};
  111. }
  112. .app-swiper-item-w {
  113. height: 100%;
  114. width: 100%;
  115. }
  116. .app-sw {
  117. display: flex;
  118. flex-wrap: wrap;
  119. justify-content: center;
  120. text-align: center;
  121. }
  122. .app-swiper-tall {
  123. display: flex;
  124. align-items: center;
  125. }
  126. .app-swiper-image {
  127. width: 100%;
  128. height: 100%;
  129. }
  130. </style>