header.vue 4.28 KB
<template>
    <div class="blk-header-wrap" v-if="showHeader" :class="[{'is-fixed': fixed}, className]">
        <div class="blk-header">
            <div class="blk-header-left">
                <slot name="left">
                    <i class="icon icon-back go-back-btn" @click="goBack"></i>
                </slot>
            </div>
            <div class="blk-header-right">
                <slot name="right"></slot>
            </div>
            <div class="blk-header-main">
                <span class="blk-header-title">{{title}}</span>
            </div>
        </div>
        <div class="blk-header-gap" v-if="!fixed"></div>
    </div>
</template>
<script>
    import yoho from 'yoho';

    export default {
        name: 'header-box',
        props: {
            title: String,
            className: [String, Object, Array],
            fixed: Boolean,
            scrollFix: Boolean,
            must: {
                type: Boolean,
                default: true
            }
        },
        data() {
            return {
                showHeader: true
            };
        },
        methods: {
            goBack() {
                yoho.goBack({}, function() {}, function() {});
            }
        },
        created() {
            if (yoho.isYohoBuy) {
                this.showHeader = this.must; // must为true 必须显示,否则为false
                if (this.title) {
                    document.title = this.title;
                }
            }
        },
        watch: {
            title(val) {
                if (val) {
                    document.title = val;
                }
            }
        }
    };
</script>
<style>
    @import "../../scss/common/_header.css";
    .blk-header-wrap.hide {
        .blk-header {
            display: none;
        }
    }
    .blk-header-wrap.ghost {
        .blk-header {
            background-color: rgba(255, 255, 255, 0);
            transition: 0.3s all;
            border-bottom: 0;
        }

        .blk-header-title {
            opacity: 0;
        }
    }

    .blk-header-wrap.ghost-2 {
        .blk-header {
            background-color: rgba(255, 255, 255, 0.4);
            transition: 0.3s all;
            border-bottom: 0;
        }

        .blk-header-title {
            opacity: 0.4;
        }
    }

    .blk-header-wrap.ghost-3 {
        .blk-header {
            background-color: rgba(255, 255, 255, 0.7);
            transition: 0.3s all;
            border-bottom: 0;
        }

        .blk-header-title {
            opacity: 0.7;
        }
    }

    .blk-header {
        box-sizing: content-box;
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        z-index: 210;
        padding: 0 34px;
        height: $header-height;
        max-width: 750px;
        margin-left: auto;
        margin-right: auto;
        line-height: $header-height;
        font-size: $header-font-size;
        font-weight: bold;
        background-color: #fff;
        border-bottom: 1px solid #eee;
        color: #000;

        .icon,
        .blk-header-title {
            vertical-align: middle;
        }

        .blk-header-right {
            margin-right: -32px;
        }

        .icon {
            min-width: $header-height;
            min-height: $header-height;
            line-height: $header-height;
            margin-left: -32px;
            text-indent: 32px;
            display: inline-block;
        }

        .go-back-btn {
            &:active {
                background: #ccc;
                opacity: 0.5;
            }
        }
    }

    .blk-header-main {
        display: block;
        text-align: center;
        margin-left: auto;
        margin-right: auto;
        font-size: $header-font-size;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        position: absolute;
        left: 0;
        right: 0;
        z-index: -1;
    }

    .blk-header-left {
        float: left;
        font-size: 64px;
    }

    .blk-header-right {
        float: right;
        font-size: 45px;

        span {
            margin-left: 30px;
        }

        .right-btn {
            font-size: 17PX;
            margin-right: 30px;
        }
    }

    .blk-header-gap {
        height: calc($header-height + 2);
        background-color: transparent;
    }


</style>