You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
<template> |
|
<view class="uv-swiper-indicator"> |
|
<view |
|
class="uv-swiper-indicator__wrapper" |
|
v-if="indicatorMode === 'line'" |
|
:class="[`uv-swiper-indicator__wrapper--${indicatorMode}`]" |
|
:style="{ |
|
width: $uv.addUnit(lineWidth * length), |
|
backgroundColor: indicatorInactiveColor |
|
}" |
|
> |
|
<view |
|
class="uv-swiper-indicator__wrapper--line__bar" |
|
:style="[lineStyle]" |
|
></view> |
|
</view> |
|
<view |
|
class="uv-swiper-indicator__wrapper" |
|
v-if="indicatorMode === 'dot'" |
|
> |
|
<view |
|
class="uv-swiper-indicator__wrapper__dot" |
|
v-for="(item, index) in length" |
|
:key="index" |
|
:class="[index === current && 'uv-swiper-indicator__wrapper__dot--active']" |
|
:style="[dotStyle(index)]" |
|
> |
|
|
|
</view> |
|
</view> |
|
</view> |
|
</template> |
|
|
|
<script> |
|
import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js' |
|
import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js' |
|
import props from './props.js'; |
|
/** |
|
* SwiperIndicator 轮播图指示器 |
|
* @description 该组件一般用于导航轮播,广告展示等场景,可开箱即用, |
|
* @tutorial https://www.uvui.cn/components/swiper.html |
|
* @property {String | Number} length 轮播的长度(默认 0 ) |
|
* @property {String | Number} current 当前处于活动状态的轮播的索引(默认 0 ) |
|
* @property {String} indicatorActiveColor 指示器非激活颜色 |
|
* @property {String} indicatorInactiveColor 指示器的激活颜色 |
|
* @property {String} indicatorMode 指示器模式(默认 'line' ) |
|
* @example <uv-swiper :list="list4" indicator keyName="url" :autoplay="false"></uv-swiper> |
|
*/ |
|
export default { |
|
name: 'uv-swiper-indicator', |
|
mixins: [mpMixin, mixin, props], |
|
data() { |
|
return { |
|
lineWidth: 22 |
|
} |
|
}, |
|
computed: { |
|
// 指示器为线型的样式 |
|
lineStyle() { |
|
let style = {} |
|
style.width = this.$uv.addUnit(this.lineWidth) |
|
style.transform = `translateX(${ this.$uv.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 '@/uni_modules/uv-ui-tools/libs/css/components.scss'; |
|
|
|
.uv-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>
|
|
|