123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <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';
-
- 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>
|