mp-swiper.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="swiper">
  3. <view class="swiper-title">
  4. <swiper :style="{height:fullHeight}" class="swiper-tall" :indicator-dots="indicatorDots"
  5. :autoplay="autoplay" :previous-margin="previousMargin" :next-margin="nextMargin" :circular="circular"
  6. @change="change" :current="swiperCurrentIndex">
  7. <swiper-item class="swiper-container" v-for="(item,index) in list" :key="index" :item-id="index"
  8. :data-year="index">
  9. <view :animation="animationData[index]" class="swiper-item" >
  10. <image :src="name?item[name]:item" mode=""></image>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="center flex-direction">
  16. <text style="margin-bottom: 50rpx;font-size: 32rpx;">{{list[swiperCurrentIndex].name}}</text>
  17. <view @click="operate" class="cu-btn flex round text-lg"
  18. style="padding: 46rpx 0;background-color: #EF9944;color: #FFFFFF;width: 76%;">
  19. <u-icon margin-left="10" label-color="#fff" :label="operateText" :name="iconName"></u-icon>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. list: Array,
  28. name: String,
  29. iconName:String,
  30. operateText:{
  31. type:String,
  32. default:'下一步'
  33. }
  34. },
  35. data() {
  36. return {
  37. screenHeight: 0,
  38. animationData: {
  39. 0: {},
  40. 1: {},
  41. 2: {},
  42. 3: {}
  43. },
  44. title: '0',
  45. indicatorDots: false,
  46. autoplay: false,
  47. previousMargin: uni.upx2px(82) + 'px',
  48. nextMargin: uni.upx2px(82) + 'px',
  49. circular: true,
  50. zoomParam: 1.10,
  51. swiperCurrentIndex: 0,
  52. data: [],
  53. max: 0,
  54. }
  55. },
  56. computed: {
  57. fullHeight() {
  58. const res = uni.getSystemInfoSync();
  59. return res.windowHeight - (res.statusBarHeight + 44) + 'px';
  60. }
  61. },
  62. created() {
  63. this.animation = uni.createAnimation();
  64. this.animation.scale(this.zoomParam).step();
  65. this.animationData[0] = this.animation.export();
  66. },
  67. methods: {
  68. operate() {
  69. this.$emit('click', this.swiperCurrentIndex)
  70. },
  71. change(e) {
  72. this.swiperCurrentIndex = e.detail.current;
  73. this.title = e.detail.currentItemId;
  74. for (let key in this.animationData) {
  75. if (e.detail.currentItemId == key) {
  76. this.animation.scale(this.zoomParam).step();
  77. this.animationData[key] = this.animation.export();
  78. } else {
  79. this.animation.scale(1.0).step();
  80. this.animationData[key] = this.animation.export();
  81. }
  82. }
  83. this.$emit('change', this.list[this.swiperCurrentIndex].image)
  84. }
  85. }
  86. }
  87. </script>
  88. <style>
  89. page {
  90. display: flex;
  91. flex-wrap: wrap;
  92. }
  93. .save-btn {
  94. background-color: #EF9944;
  95. color: #FFFFFF;
  96. }
  97. .swiper-container {
  98. display: flex;
  99. align-items: center;
  100. }
  101. .swiper-item {
  102. display: flex;
  103. flex-wrap: wrap;
  104. justify-content: center;
  105. margin-left: auto;
  106. margin-right: auto;
  107. height: 760upx;
  108. width: 544upx;
  109. line-height: 300upx;
  110. text-align: center;
  111. margin-bottom: 50upx;
  112. }
  113. .swiper-tall {
  114. display: flex;
  115. align-items: center;
  116. }
  117. .swiper-title {
  118. margin-top: -100rpx;
  119. width: 760upx;
  120. text-align: center;
  121. }
  122. </style>