graceSwiper.nvue 5.0 KB

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