¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="u-swiper-indicator"> |
| | | <view |
| | | class="u-swiper-indicator__wrapper" |
| | | v-if="indicatorMode === 'line'" |
| | | :class="[`u-swiper-indicator__wrapper--${indicatorMode}`]" |
| | | :style="{ |
| | | width: $u.addUnit(lineWidth * length), |
| | | backgroundColor: indicatorInactiveColor |
| | | }" |
| | | > |
| | | <view |
| | | class="u-swiper-indicator__wrapper--line__bar" |
| | | :style="[lineStyle]" |
| | | ></view> |
| | | </view> |
| | | <view |
| | | class="u-swiper-indicator__wrapper" |
| | | v-if="indicatorMode === 'dot'" |
| | | > |
| | | <view |
| | | class="u-swiper-indicator__wrapper__dot" |
| | | v-for="(item, index) in length" |
| | | :key="index" |
| | | :class="[index === current && 'u-swiper-indicator__wrapper__dot--active']" |
| | | :style="[dotStyle(index)]" |
| | | > |
| | | |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | import props from './props.js'; |
| | | /** |
| | | * SwiperIndicator è½®æå¾æç¤ºå¨ |
| | | * @description 该ç»ä»¶ä¸è¬ç¨äºå¯¼èªè½®æï¼å¹¿åå±ç¤ºçåºæ¯,å¯å¼ç®±å³ç¨ï¼ |
| | | * @tutorial https://www.uviewui.com/components/swiper.html |
| | | * @property {String | Number} length è½®æçé¿åº¦ï¼é»è®¤ 0 ï¼ |
| | | * @property {String | Number} current å½åå¤äºæ´»å¨ç¶æçè½®æçç´¢å¼ï¼é»è®¤ 0 ï¼ |
| | | * @property {String} indicatorActiveColor æç¤ºå¨éæ¿æ´»é¢è² |
| | | * @property {String} indicatorInactiveColor æç¤ºå¨çæ¿æ´»é¢è² |
| | | * @property {String} indicatorMode æç¤ºå¨æ¨¡å¼ï¼é»è®¤ 'line' ï¼ |
| | | * @example <u-swiper :list="list4" indicator keyName="url" :autoplay="false"></u-swiper> |
| | | */ |
| | | export default { |
| | | name: 'u-swiper-indicator', |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props], |
| | | data() { |
| | | return { |
| | | lineWidth: 22 |
| | | } |
| | | }, |
| | | computed: { |
| | | // æç¤ºå¨ä¸ºçº¿åçæ ·å¼ |
| | | lineStyle() { |
| | | let style = {} |
| | | style.width = uni.$u.addUnit(this.lineWidth) |
| | | style.transform = `translateX(${ uni.$u.addUnit(this.current * this.lineWidth) })` |
| | | style.backgroundColor = this.indicatorActiveColor |
| | | return style |
| | | }, |
| | | // æç¤ºå¨ä¸ºç¹åçæ ·å¼ |
| | | dotStyle() { |
| | | return index => { |
| | | let style = {} |
| | | style.backgroundColor = index === this.current ? this.indicatorActiveColor : this.indicatorInactiveColor |
| | | return style |
| | | } |
| | | } |
| | | }, |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | |
| | | .u-swiper-indicator { |
| | | |
| | | &__wrapper { |
| | | @include flex; |
| | | |
| | | &--line { |
| | | border-radius: 100px; |
| | | height: 4px; |
| | | |
| | | &__bar { |
| | | width: 22px; |
| | | height: 4px; |
| | | border-radius: 100px; |
| | | background-color: #FFFFFF; |
| | | transition: transform 0.3s; |
| | | } |
| | | } |
| | | |
| | | &__dot { |
| | | width: 5px; |
| | | height: 5px; |
| | | border-radius: 100px; |
| | | margin: 0 4px; |
| | | |
| | | &--active { |
| | | width: 12px; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | </style> |