gui-swiper.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="gui-swiper-card-wrap">
  3. <swiper :style="{width:width+'rpx', height:heightIn+'rpx'}"
  4. class="gui-swiper-card"
  5. :indicator-dots="false" :interval="interval" :circular="true"
  6. :autoplay="autoplay" :current="currentIndex"
  7. :previous-margin="spacing+'rpx'" :next-margin="spacing+'rpx'"
  8. @change="swiperchange">
  9. <swiper-item v-for="(item, index) in swiperItems"
  10. :key="index" class="gui-swiper-card-item gui-border-box">
  11. <navigator class="gui-swiper-card-nav gui-transition-all"
  12. :url="item.url" :open-type="item.opentype" hover-class="none"
  13. v-if="item.opentype != 'click'"
  14. :style="{paddingLeft:current != index ? padding +'rpx':'0rpx',
  15. paddingRight:current != index ? padding +'rpx':'0rpx',
  16. paddingTop:current != index ? paddingY +'rpx':'0rpx',
  17. paddingBottom:current != index ? paddingY +'rpx':'0rpx'}">
  18. <image :style="{
  19. borderRadius : borderRadius,
  20. width:current != index ? widthInSamll+'rpx':widthIn+'rpx',
  21. height:current != index ? heightInSmall+'rpx':heightIn+'rpx',
  22. opacity:current != index ? opacity : 1}"
  23. :src="item.img" class="gui-swiper-card-image gui-transition-all" />
  24. </navigator>
  25. <view class="gui-swiper-card-nav gui-transition-all"
  26. hover-class="none" v-if="item.opentype == 'click'"
  27. @tap.stop="taped" :data-index="index"
  28. :style="{paddingLeft:current != index ? padding +'rpx':'0rpx',
  29. paddingRight:current != index ? padding +'rpx':'0rpx',
  30. paddingTop:current != index ? paddingY +'rpx':'0rpx',
  31. paddingBottom:current != index ? paddingY +'rpx':'0rpx'}">
  32. <image :style="{
  33. borderRadius : borderRadius,
  34. width:current != index ? widthInSamll+'rpx':widthIn+'rpx',
  35. height:current != index ? heightInSmall+'rpx':heightIn+'rpx',
  36. opacity:current != index ? opacity : 1}"
  37. :src="item.img" class="gui-swiper-card-image gui-transition-all" />
  38. </view>
  39. <view v-if="indicatorType == 'number'"
  40. class="gui-indicator-dot-numbers gui-flex gui-rows gui-nowrap"
  41. :style="{
  42. height:indicatorBarHeight+'rpx', backgroundColor:indicatorBarBgColor,
  43. 'border-bottom-left-radius':borderRadius, 'border-bottom-right-radius':borderRadius,
  44. width:current != index ? widthInSamll+'rpx':widthIn+'rpx',
  45. left:current != index ? padding+'rpx':'0rpx', bottom:current != index ? paddingY+'rpx':'0rpx'}">
  46. <text class="gui-indicator-dot-text"
  47. :style="{paddingLeft:'20rpx', 'fontStyle':'italic', color:titleColor}">{{index+1}}</text>
  48. <text class="gui-indicator-dot-text"
  49. :style="{'fontSize':'36rpx', color:titleColor}">/</text>
  50. <text class="gui-indicator-dot-text"
  51. :style="{fontSize:'28rpx', paddingRight:'20rpx', fontStyle:'italic', color:titleColor}">{{swiperItems.length}}</text>
  52. <text class="gui-swiper-text gui-block-text gui-flex1 gui-ellipsis"
  53. :style="{color:titleColor, fontSize:titleSize, height:indicatorBarHeight+'rpx',
  54. lineHeight:indicatorBarHeight+'rpx'}">{{item.title}}</text>
  55. </view>
  56. </swiper-item>
  57. </swiper>
  58. <view class="gui-indicator-dots gui-flex gui-rows gui-nowrap gui-justify-content-center gui-align-items-center gui-border-box"
  59. v-if="indicatorType == 'dot'"
  60. :style="{width:width+'rpx', height:indicatorBarHeight+'rpx', position:indicatorPosition,
  61. paddingLeft:spacing+'rpx', paddingRight:spacing+'rpx', 'justify-content':indicatorDirection}">
  62. <view class="gui-indicator-dots-wrap gui-flex gui-rows gui-nowrap gui-justify-content-center">
  63. <view v-for="(item, index) in swiperItems" :key="index"
  64. :class="['gui-indicator-dot',current == index ? 'dot-show' : '']"
  65. :style="{
  66. width : current != index ? indicatorWidth+'rpx' : indicatorActiveWidth +'rpx',
  67. height : indicatorHeight+'rpx',
  68. borderRadius : indicatorRadius+'rpx',
  69. backgroundColor : current != index ? indicatorColor : indicatorActiveColor}"></view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. export default{
  76. name : "gui-swiper",
  77. props : {
  78. width :{ type : Number, default : 750 },
  79. height:{ type : Number, default : 300 },
  80. swiperItems : { type : Array, default : function(){return new Array();} },
  81. borderRadius : { type : String, default : '10rpx'},
  82. indicatorBarHeight:{type : Number, default : 68},
  83. indicatorBarBgColor:{type : String, default : 'rgba(0,0,0,0)'},
  84. indicatorWidth : { type:Number, default:18 },
  85. indicatorActiveWidth :{ type:Number, default:18 },
  86. indicatorHeight : { type:Number, default:18 },
  87. indicatorRadius:{ type:Number, default:18 },
  88. indicatorColor : { type : String, default : "rgba(255, 255, 255, 0.6)" },
  89. indicatorActiveColor : { type : String, default : "#2B2E3D" },
  90. indicatorType:{ type : String, default : "dot" },
  91. indicatorPosition:{ type : String, default : "absolute" },
  92. indicatorDirection:{type:String, default:'center'},
  93. spacing : { type : Number, default : 50 },
  94. padding : { type : Number, default : 26 },
  95. interval : { type : Number, default : 5000 },
  96. autoplay : { type : Boolean, default : true },
  97. currentIndex : { type : Number, default : 0 },
  98. opacity:{ type : Number, default:0.66},
  99. titleColor:{type:String, default:"#FFFFFF"},
  100. titleSize:{type:String, default:"28rpx"}
  101. },
  102. data() {
  103. return {
  104. current : 0,
  105. isReady : false,
  106. widthIn : 750,
  107. heightIn : 300,
  108. widthInSamll:700,
  109. heightInSmall:280,
  110. paddingY:0
  111. }
  112. },
  113. watch:{
  114. currentIndex : function (val) {
  115. this.current = val;
  116. }
  117. },
  118. created:function(){
  119. this.current = this.currentIndex;
  120. this.init();
  121. },
  122. methods:{
  123. init : function(){
  124. // 图片宽高计算
  125. this.widthIn = this.width - this.spacing*2;
  126. this.heightIn = this.height / this.width * this.widthIn;
  127. this.paddingY = this.padding * this.height / this.width;
  128. this.widthInSamll = this.widthIn - this.padding * 2;
  129. this.heightInSmall = this.heightIn - this.paddingY * 2;
  130. },
  131. swiperchange : function (e) {
  132. var current = e.detail.current;
  133. this.current = current;
  134. this.$emit('swiperchange', current);
  135. },
  136. taped : function(e){
  137. this.$emit('taped', e.currentTarget.dataset.index);
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. .gui-swiper-card-wrap{position:relative;}
  144. .gui-swiper-card{overflow:hidden;}
  145. .gui-swiper-card-item{font-size:0; overflow:hidden; line-height:0;}
  146. .gui-swiper-card-nav{font-size:0; position:relative;}
  147. .gui-indicator-dots{width:750rpx; overflow:hidden; z-index:1; left:0; bottom:0;}
  148. .gui-indicator-dot{margin:6rpx;}
  149. .gui-indicator-dots-wrap{padding:0 20rpx;}
  150. .gui-indicator-dot-text{text-align:center; line-height:68rpx; padding:0 4rpx; color:#FFFFFF; font-size:32rpx;}
  151. .gui-indicator-dot-numbers{overflow:hidden; align-items:center; position:absolute; z-index:1; left:0; bottom:0;}
  152. .gui-swiper-text{width:200rpx; line-height:68rpx; padding-right:25rpx; overflow:hidden;}
  153. /* #ifndef APP-NVUE */
  154. @keyframes dot-show{from{opacity:0.1;}to{opacity:1;}}
  155. .dot-show{animation:dot-show 300ms linear forwards;}
  156. /* #endif */
  157. </style>