home-slider.vue 4.33 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" @click="close">
                        <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" @click="close">
                            <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)
            });
        }
    },
    watch: {
        value(val) {
            this.$yoho && this.$yoho.blkBackStatus(val);
        }
    },
    mounted() {
        for (let i = 0; i < this.sliders.length; i++) {
            this.subSwitch.push(false);
        }
    }
};
</script>

<style lang="scss">
.home-slider {
    position: absolute;
    right: 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: 30px;
            }

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

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

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

        .childs .item {
            height: 86px;
            margin-left: 20px;
            padding-left: 0;
            font-family: HiraginoSansGB-W3, HelveticaNeue , Tahoma, Arial;

            .link-a {
                left: 0;
            }
        }
    }

}
.home-slider-enter-active, .home-slider-leave-active {
    will-change: true;
    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>