gui-swiper.vue 7.1 KB

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