fs-swiper.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <swiper
  3. :current="current"
  4. :indicator-dots="indicatorDots"
  5. :indicator-color="indicatorColor"
  6. :indicator-active-color="indicatorActiveColor"
  7. :autoplay="autoplay"
  8. :interval="interval"
  9. :duration="duration"
  10. :circular="circular"
  11. :vertical="vertical"
  12. :previous-margin="previousMargin"
  13. :next-margin="nextMargin"
  14. @change="handleChange"
  15. @transition="handleTransition"
  16. class="fs-swiper"
  17. :class="{'fs-swiper-card': mode === 'card', 'gutter-v': gutter}"
  18. :style="{height: height}">
  19. <template v-if="mode === 'card'">
  20. <swiper-item class="fs-swiper-item-box" v-for="(item, index) in list" :key="index" @click="handleClick">
  21. <view class="fs-swiper-item" :class="{'card-cur': index === curIndex}">
  22. <fs-avatar shape="square" radius width="100%" height="100%" :src="item[keyMap.src]"></fs-avatar>
  23. </view>
  24. </swiper-item>
  25. </template>
  26. <template v-else>
  27. <swiper-item class="fs-swiper-item-box" v-for="(item, index) in list" :key="index" @click="handleClick">
  28. <view class="fs-swiper-item">
  29. <fs-avatar shape="square" width="100%" height="100%" :src="item[keyMap.src]"></fs-avatar>
  30. </view>
  31. </swiper-item>
  32. </template>
  33. </swiper>
  34. </template>
  35. <script setup>
  36. import { ref } from 'vue'
  37. const props = defineProps({
  38. current: {
  39. type: Number,
  40. default: 0
  41. },
  42. indicatorDots: {
  43. type: Boolean,
  44. default: true
  45. },
  46. indicatorColor: {
  47. type: String,
  48. default: 'rgba(0, 0, 0, .3)'
  49. },
  50. indicatorActiveColor: {
  51. type: String,
  52. default: '#fff'
  53. },
  54. autoplay: {
  55. type: Boolean,
  56. default: true
  57. },
  58. circular: {
  59. type: Boolean,
  60. default: true
  61. },
  62. interval: {
  63. type: Number,
  64. default: 3000
  65. },
  66. duration: {
  67. type: Number,
  68. default: 1000
  69. },
  70. vertical: {
  71. type: Boolean,
  72. default: false
  73. },
  74. previousMargin: {
  75. type: String,
  76. default: '0'
  77. },
  78. nextMargin: {
  79. type: String,
  80. default: '0'
  81. },
  82. height: {
  83. type: String,
  84. default: '350rpx'
  85. },
  86. list: {
  87. type: Array,
  88. default() {
  89. return []
  90. }
  91. },
  92. keyMap: {
  93. type: Object,
  94. default() {
  95. return {
  96. src: 'src'
  97. }
  98. }
  99. },
  100. mode: {
  101. type: String
  102. },
  103. gutter: Boolean
  104. })
  105. const emits = defineEmits(['change', 'click', 'transition'])
  106. let curIndex = ref(0)
  107. const handleChange = e => {
  108. curIndex.value = e.detail.current
  109. emits('change', e)
  110. }
  111. const handleTransition = e => {
  112. emits('transition', e)
  113. }
  114. const handleClick = item => {
  115. emits('click', item)
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .fs-swiper{
  120. &-item{
  121. width: 100%;
  122. height: 100%;
  123. }
  124. }
  125. .fs-swiper-card{
  126. .fs-swiper-item-box{
  127. width: 610rpx !important;
  128. left: 70rpx;
  129. }
  130. .fs-swiper-item{
  131. transform: scale(.9);
  132. transition: all 0.2s ease-in 0s;
  133. overflow: hidden;
  134. }
  135. .card-cur{
  136. transform: scale(1)
  137. }
  138. }
  139. </style>