<template>
    <header>
        <div class="container">
            <div class="home-logo">
                <h1>
                    <router-link to="/">JS transfer</router-link>
                </h1>
            </div>
            <div class="home-nav">
                <ul>
                    <li v-for="(item, index) in navList" :key="index">
                        <h2>
                            <router-link :to="item.link">{{item.title}}</router-link>
                        </h2>
                    </li>
                </ul>
            </div>
            <div class="home-side">
                <ul v-show="!hasToken">
                    <li>
                        <router-link to="/login" target="_blank">登录</router-link>
                    </li>
                    <li>
                        <router-link to="/register" class="com-btn radius2" target="_blank">注册</router-link>
                    </li>
                </ul>
                <ul v-show="hasToken">
                    <li>
                        <router-link to="/account" class="com-btn radius2" target="_blank">返回我的账户</router-link>
                    </li>
                </ul>
            </div>
        </div>
    </header>
</template>

<script>
import utils from "utils/utils.js";
export default {
    name: "homeHeadere",
    data() {
        return {
            navList: [
                {
                    link: "/",
                    title: "首页"
                },
                {
                    link: "/security",
                    title: "安全"
                },
                {
                    link: "/help",
                    title: "帮助"
                },
                {
                    link: "/about",
                    title: "关于"
                }
            ],
            hasToken: false
        };
    },
    methods: {},
    mounted() {
        if (utils.getCookie("token")) {
            this.hasToken = true;
        } else {
            this.hasToken = false;
        }
    },
    updated() {
        if (utils.getCookie("token")) {
            this.hasToken = true;
        } else {
            this.hasToken = false;
        }
    }
};
</script>

<style lang="less" scoped>
header {
    height: 60px;
    line-height: 60px;
    font-size: 14px;
    background: #fff;
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    z-index: 999;
    box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.08);
    .container {
        width: 1080px;
        margin: 0 auto;
    }
    .home-logo {
        float: left;
        display: block;
        width: 326px;
        height: 36px;
        margin: 12px 0;
        background-image: url(~assets/images/logo.png);
        background-size: 326px 36px;
        background-repeat: no-repeat;
        background-position: 50%;
        text-indent: -9999px;
        h1 {
            margin: 0;
        }
        a {
            display: block;
            height: 36px;
            line-height: 36px;
            width: 326px;
        }
    }
    .home-nav {
        margin-left: 75px;
        float: left;
        ul {
            margin: 0;
            padding: 0;
            height: 60px;
            list-style: none;
            li {
                float: left;
                position: relative;
                h2 {
                    font-weight: 500;
                    margin: 0;
                    padding: 0;
                    a {
                        color: #484848;
                        display: block;
                        text-decoration: none;
                        padding: 0 25px;
                        border-top: 4px solid transparent;
                        border-bottom: 4px solid transparent;
                        line-height: 52px;
                        font-size: 14px;
                        &:hover {
                            color: #3d86e9;
                        }
                        &.router-link-exact-active {
                            color: #3d86e9;
                            border-bottom: 4px solid #3d86e9;
                        }
                    }
                }
            }
        }
    }
    .home-side {
        float: right;
        ul {
            list-style: none;
            margin-top: 15px;
            li {
                float: left;
                margin: 0 0 0 10px;
                position: relative;
                a {
                    text-decoration: none;
                    padding: 0 20px;
                    line-height: 30px;
                    height: 30px;
                    display: block;
                    font-weight: 500;
                    &.radius2 {
                        border-radius: 2px;
                    }
                }
            }
        }
    }
    .com-btn {
        background: #3d86e9;
        color: #fff;
    }
}
</style>
