123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <view
- class="swiper-box "
- :class="{
- loading:loading,
- 'main-center':loading,
- 'cross-center': loading
- }"
- :style="{height: height}"
- >
- <u-loading-icon :show="loading" vertical />
- <u-swiper
- v-if="list.length"
- :list="list"
- :height="height"
- :radius="radius"
- :style="{width: '100%', backgroundPosition: 'center'}"
- :indicator="true"
- :show-title="true"
- indicator-mode="dot"
- :indicator-style="{bottom: '24rpx'}"
- @change="handleChange"
- @click="handleClick"
- >
- <view
- slot="indicator"
- class="indicator"
- >
- <view
- v-for="(item, index) in list"
- :key="index"
- class="indicator__line"
- :style="{
- width: `${(380 / list.length)}rpx`
- }"
- :class="[index === currentNum && 'indicator__line--active']"
- />
- </view>
- </u-swiper>
- </view>
- </template>
- <script>
- export default {
- name: 'SwiperBox',
- props: {
- height: {
- type: [Number, String],
- default: '330rpx'
- },
- radius: {
- type: [Number, String],
- default: '0rpx'
- },
- type: {
- type: String,
- default: 'login'
- }
- },
- data() {
- return {
- loading: true,
- list: [],
- original: [],
- currentNum: 0
- }
- },
- computed: {
- },
- created() {
- this.getSwiper()
- },
- methods: {
- handleChange(e) {
- this.currentNum = e.current
- },
- getSwiper() {
- const method = this.type === 'login' ? 'loginBanner' : 'indexBanner'
- this.$api.setting[method]().then(res => {
- this.loading = false
- this.original = res.data
- res.data.forEach(obj => {
- this.list.push(obj.image)
- })
- })
- },
- handleClick(index) {
- const data = this.original[index]
- this.$emit('click', data)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .swiper-box{
- margin: 20rpx 0;
- border-radius: 8rpx;
- &.loading{
- background-color: #FFFFFF;
- }
- .indicator {
- display: flex;
- flex-direction: row;
- justify-content: center;
- position: relative;
- margin-bottom: 10%;
- &__line {
- height: 1rpx;
- width: 50rpx;
- background-color: rgba(255, 255, 255, 0.7);
- transition: background-color 0.3s;
- border-radius: 5rpx;
- &--active {
- height: 8rpx;
- margin-top: -4rpx;
- background: #fff;
- }
- }
- }
- }
- </style>
|