sidebar.vue 3.52 KB
<template>
    <div class="sidebar">
        <template v-for="(index, item) in list">
            <template v-if="item.separative_sign === 'Y'">
                <div class="sep">
                    <!-- 分割线 -->
                </div>
            </template>
            <span class="item ellipsis" :class="{'selected': selectedIndex === index}"
            @click="select(index, item)">
                <span class="en">{{(item.sort_name_en || '').trim()}}</span>
                <span class="cn">{{item.sort_name}}</span>
            </span>
        </template>
    </div>
</template>

<script>
    const $ = require('jquery');
    const interceptClick = require('common/intercept-click');

    module.exports = {
        data() {
            return {
                selectedIndex: '',
                list: []
            };
        },
        created() {
            $.ajax({
                url: '/sidebar'
            }).then((res) => {
                this.list = res.data;
            });
        },
        methods: {
            select(index, item) {
                this.selectedIndex = index;
                interceptClick.intercept(item.sort_url);
            }
        }

        // ,
        // ready() {
        //     var a =document.querySelector('.sidebar')
        //     alert(a.getBoundingClientRect().width)
        // }
    };
</script>

<style>
    @import "../../scss/common/color";

    html {
        font-size: 60px !important;
        overflow-x: hidden;
    }

    #sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow-x: hidden;
        overflow-y: auto;
        background: #f6f6f6;
    }

    .sidebar {
        background: $white;

        .item {
            position: relative;
            display: block;
            padding: 0 30px;
            height: 124px;
            line-height: 124px;
            font-size: 30px;
            font-weight: bold;
            font-family: "BrownStd-Bold", "PingFang SC", Helvetica, Roboto, "Heiti SC", "黑体", Arial;

            .en {
                font-size: 36px;
            }

            .cn {
                margin-left: -6px;
            }

            &:first-child {
                font-size: 36px;
                height: 142px;
                line-height: 142px;
                font-family: "PingFang SC", Helvetica, Roboto, "Heiti SC", "黑体", Arial;
            }

            &:after {
                content: "";
                position: absolute;
                left: 30px;
                bottom: 0;
                width: 100%;
                height: 0;
                border-bottom: 1px solid #eee;
            }

            &:last-child {
                border-bottom: 1px solid #eee;

                &:after {
                    content: none;
                }
            }
        }

        .selected {
            background: $black;
            color: $white;

            &:after {
                border-bottom: 1px solid $black;
            }
        }

        .sep {
            margin-top: -1px;
            width: 100%;
            height: 20px;
            background: #f6f6f6;
            border-top: 1px solid #eee;
            border-bottom: 1px solid #eee;

            & + .item {
                font-size: 36px;
                height: 142px;
                line-height: 142px;
                font-family: "PingFang SC", Helvetica, Roboto, "Heiti SC", "黑体", Arial;
            }
        }
    }

    .app.ios {
        .sidebar {
            margin-top: 40px;
        }
    }
</style>