<template>
    <header id="header">
        <div class="logo">
            <!-- <img src="./images/logo.png" alt="科艺logo"><span class="logo-desc">数字化管理平台</span> -->
        </div>
        <h2 class="title"><span>{{ currPageTitle }}</span></h2>
        <div class="date">
            <span class="curr-date">{{ fullDate || '' }}</span>
            <span class="curr-times">{{ fullTime || '' }}</span>
        </div>
    </header>
</template>

<script>
import utils from 'utils'
let timerId = null

export default {
    data () {
        return {
            currPageTitle: '',
            fullDate: '',
            fullTime: ''
        }
    },

    watch: {
        '$route' (oldVal = {}, newVal = {}) {
            if (oldVal.path !== newVal.path) {
                this.getCurrRoute()
            }
        }
    },

    created () {
        window.vm = this

        this.getSysTime()

        this.getCurrRoute()
    },

    beforeDestroy () {
        clearTimeout(timerId)
        timerId = null
    },

    methods: {
        getCurrRoute () {
            const { meta = {} } = this.$router.currentRoute
            this.currPageTitle = meta.title || ''
        },

        getSysTime () {
            const that = this
            try {
                timerId = setTimeout(function getTimer () {
                    const { fullDate = '', fullTime = '' } = utils.getCurrTime('/') || {}
                    that.fullDate = fullDate
                    that.fullTime = fullTime

                    timerId = setTimeout(getTimer, 1000)
                }, 1000)
            } catch (error) {
                console.log('getSysTime-error > ', error)
            }
        }
    }
}
</script>

<style lang="less" scoped>
#header {
    display: flex;
    align-items: center;
    width: 100%;
    height: @pageHeaderHeight;
    padding-right: 35px;
    padding-left: 25px;
}

.logo {
    padding-top: 12px;

    > img {
        vertical-align: -5px;
    }

    .logo-desc {
        margin-left: 24px;
        font-size: 18px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #fff;
    }
}

.title {
    flex: 1;
    height: 100%;
    line-height: @pageHeaderHeight + 4;
    white-space: nowrap;
    text-align: center;
    // background: url('./images/header-bg.png') no-repeat center top;

    > span {
        font-size: 34px;
        font-family: Adobe Heiti Std;
        font-weight: bold;
        color: #fff;

        background: linear-gradient(0deg, #FFFFFF 0%, #FFFFFF 100%);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
}

.date {
    width: 205px;
    padding-top: 30px;
    color: #fff;

    > span {
        font-size: 18px;
        font-family: 'CenturyGothic';
    }

    .curr-times {
        margin-left: 8px;
        font-size: 24px;
        font-weight: bold;
    }
}
</style>>
