graceNvueSwiper.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="grace-swiper-card-wrap">
  3. <swiper :style="{width:width+'rpx', height:height+'rpx'}" class="grace-swiper-card"
  4. :indicator-dots="false" :interval="interval"
  5. :indicator-color="indicatorColor" :indicator-active-color="indicatorActiveColor"
  6. :duration="500" :circular="true" :autoplay="autoplay" :current="currentIndex" @change="swiperchange">
  7. <swiper-item v-for="(item, index) in swiperItems" :key="index" class="grace-swiper-card-item">
  8. <navigator class="grace-swiper-card-nav" :url="item.url"
  9. :open-type="item.opentype" hover-class="none" v-if="item.opentype != 'click'">
  10. <image :style="{ borderRadius : borderRadius, width:width+'rpx', height:height+'rpx'}"
  11. :src="item.img" class="grace-swiper-card-image" />
  12. </navigator>
  13. <view class="grace-swiper-card-nav" :data-index="index" @tap.stop="taped"
  14. :url="item.url" :open-type="item.opentype" hover-class="none" v-if="item.opentype == 'click'">
  15. <image :style="{ borderRadius : borderRadius, width:width+'rpx', height:height+'rpx'}"
  16. :src="item.img" class="grace-swiper-card-image" />
  17. </view>
  18. <view v-if="indicatorType == 'number'" class="grace-indicator-dot-numbers"
  19. :style="{height:indicatorBarHeight+'rpx', backgroundColor:indicatorBarBgColor,
  20. width:width+'rpx', left:'0rpx', bottom:'0rpx'}">
  21. <text class="grace-indicator-dot-text"
  22. :style="{paddingLeft:'20rpx', 'fontStyle':'italic', color:titleColor}">{{index+1}}</text>
  23. <text class="grace-indicator-dot-text" :style="{'fontSize':'36rpx', color:titleColor}">/</text>
  24. <text class="grace-indicator-dot-text"
  25. :style="{fontSize:'28rpx', paddingRight:'20rpx', fontStyle:'italic', color:titleColor}">{{swiperItems.length}}</text>
  26. <text class="grace-swiper-text"
  27. :style="{color:titleColor, fontSize:titleSize, height:indicatorBarHeight+'rpx',
  28. lineHeight:indicatorBarHeight+'rpx'}">{{item.title}}</text>
  29. </view>
  30. </swiper-item>
  31. </swiper>
  32. <view class="grace-indicator-dots" v-if="indicatorType == 'dot'"
  33. :style="{width:width+'rpx', height:indicatorBarHeight+'rpx', position:indicatorPosition}">
  34. <view v-for="(item, index) in swiperItems" :key="index" class="grace-indicator-dot"
  35. :style="{
  36. width : current != index ? indicatorWidth+'rpx' : indicatorActiveWidth +'rpx',
  37. height : indicatorHeight+'rpx',
  38. borderRadius : indicatorRadius+'rpx',
  39. backgroundColor : current != index ? indicatorColor : indicatorActiveColor}"></view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default{
  45. props:{
  46. width:{ type : Number, default : 750 },
  47. height:{ type : Number, default : 300 },
  48. swiperItems : { type : Array, default : function(){return new Array();} },
  49. borderRadius : { type : String, default : '10rpx'},
  50. indicatorBarHeight:{type : Number, default : 68},
  51. indicatorBarBgColor:{type : String, default : 'rgba(0,0,0,0)'},
  52. indicatorWidth : { type:Number, default:18 },
  53. indicatorActiveWidth :{ type:Number, default:18 },
  54. indicatorHeight : { type:Number, default:18 },
  55. indicatorRadius:{ type:Number, default:18 },
  56. indicatorColor : { type : String, default : "rgba(255, 255, 255, 0.6)" },
  57. indicatorActiveColor : { type : String, default : "#3688FF" },
  58. indicatorType:{ type : String, default : "dot" },
  59. indicatorPosition:{ type : String, default : "absolute" },
  60. spacing : { type : Number, default : 50 },
  61. padding : { type : Number, default : 26 },
  62. interval : { type : Number, default : 5000 },
  63. autoplay : { type : Boolean, default : true },
  64. currentIndex : { type : Number, default : 0 },
  65. opacity:{ type : Number, default:0.66},
  66. titleColor:{type:String, default:"#FFFFFF"},
  67. titleSize:{type:String, default:"28rpx"}
  68. },
  69. data() {
  70. return {
  71. current : 0,
  72. isReady : false,
  73. widthIn : 750,
  74. heightIn : 300,
  75. widthInSamll:700,
  76. heightInSmall:280,
  77. paddingY:0
  78. }
  79. },
  80. watch:{
  81. currentIndex : function (val) {
  82. this.current = val;
  83. }
  84. },
  85. created:function(){
  86. this.current = this.currentIndex;
  87. },
  88. methods:{
  89. swiperchange : function (e) {
  90. var current = e.detail.current;
  91. this.current = current;
  92. this.$emit('swiperchange', current);
  93. },
  94. taped:function (e) {
  95. this.$emit('taped', e.currentTarget.dataset.index);
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .grace-swiper-card-wrap{position:relative;}
  102. .grace-swiper-card{overflow:hidden;}
  103. .grace-swiper-card-item{font-size:0; overflow:hidden; line-height:0;}
  104. .grace-swiper-card-nav{font-size:0; position:relative;}
  105. .grace-swiper-card-image{}
  106. .grace-indicator-dots{width:750rpx; height:68rpx; overflow:hidden; left:0; bottom:0; flex-direction:row; flex-wrap:nowrap; align-items:center; justify-content:center;}
  107. .grace-indicator-dot{margin:6rpx;}
  108. .grace-indicator-dot-text{text-align:center; line-height:68rpx; padding:0 4rpx; color:#FFFFFF; font-size:32rpx;}
  109. .grace-indicator-dot-numbers{flex-direction:row; flex-wrap:nowrap; justify-content:center; overflow:hidden; align-items:center; position:absolute; z-index:1; left:0; bottom:0;}
  110. .grace-swiper-text{width:700rpx; line-height:68rpx; padding-right:25rpx; overflow:hidden; text-overflow:ellipsis; flex:1;}
  111. </style>