fs-swiper.vue 3.1 KB

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