home-slider.vue 4.04 KB
<template>
    <div class="home-slider-content">
        <transition name="home-slider">
            <div class="home-slider" v-if="value">
                <div class="block" v-for="(slider, index) in sliders" :key="slider.name">
                    <div v-if="slider.secList.length" class="item title"
                         @click="selectSlider(index)">
                        <span>{{slider.name}}</span>
                        <i class="icon" :class="{'icon-up': subSwitch[index], 'icon-down': !subSwitch[index]}"></i>
                    </div>
                    <div v-else class="item title">
                        <a-link :href="slider.url">
                            <span>{{slider.name}}</span>
                            <i class="icon icon-up trans-right"></i>
                        </a-link>
                    </div>
                    <div class="childs" v-show="slider.secList.length && subSwitch[index]">
                        <div class="item" v-for="item in slider.secList" :key="item.name">
                            <a-link :href="item.url">{{item.name}}</a-link>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
        <div class="mask" @click="close" v-show="value"></div>
    </div>
</template>

<script>
import _ from 'lodash/core';
export default {
    name: 'HomeSlider',
    props: {
        value: Boolean,
        sliders: Array
    },
    data() {
        return {
            subSwitch: []
        };
    },
    methods: {
        close() {
            this.$emit('input', false);
        },
        selectSlider(idx) {
            _.each(this.subSwitch, (item, index) => {
                if (idx === index) {
                    this.$set(this.subSwitch, index, !this.subSwitch[index]);
                    return true;
                }
                this.$set(this.subSwitch, index, false)
            });
        }
    },
    created() {
        for (let i = 0; i < this.sliders.length; i++) {
            this.subSwitch.push(false);
        }
    }
};
</script>

<style lang="scss">
.home-slider {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 999;
    width: 500px;
    background-color: #fff;
    overflow-y: auto;
    letter-spacing: -0.76px;
    color: #000000;

    .block {
        .title {
            font-size: 32px !important;
            font-weight: bold;
            height: 100px;
            line-height: 100px !important;

            .icon {
                float: right;
                height: 100%;
                line-height: 100px;
                font-weight: bold;
                font-size: 26px;
            }

            .icon-up.trans-right {
                transform: rotate(90deg);
                margin-right: -6px;
            }

            span {
                font-family: HelveticaNeue-Medium, Tahoma, Arial;
            }
        }
        .item {
            position: relative;
            font-size: 28px;
            padding-left: 20px;
            padding-right: 20px;
            border-bottom: solid 1px #EEEEEE;
            height: 86px;
            line-height: 86px;

            a {
                position: absolute;
                top: 0;
                right: 20px;
                bottom: 0;
                left: 20px;
            }
        }

        .childs .item {
            font-family: HelveticaNeue , Tahoma, Arial;
        }
    }

}
.home-slider-enter-active, .home-slider-leave-active {
    will-change: transform;
    transition-duration: 280ms;
}
.home-slider-enter-active {
    transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
}
.home-slider-leave-active {
    transition-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
}
.home-slider-enter, .home-slider-leave-to {
    transform: translateX(-500px);
}
.home-slider-enter-to, .home-slider-leave {
    transform: translateX(0px);
}
.home-slider-content {
    .mask {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 998;
        background: rgba(0, 0, 0, 0.4);
    }
}
</style>