PageLayout.vue 3.35 KB
Newer Older
wb-ct393452's avatar
wb-ct393452 committed
1 2
<template>
    <div class="page-layout">
3 4 5 6 7 8 9
        <page-header
            ref="pageHeader"
            :style="`margin-top: ${multiPage ? 0 : -24}px`"
            :breadcrumb="breadcrumb"
            :logo="logo"
            :avatar="avatar"
        >
水落(YangLei)'s avatar
水落(YangLei) committed
10 11
            <slot name="action" slot="action" />
            <slot slot="content" name="headerContent" />
wb-ct393452's avatar
wb-ct393452 committed
12 13 14 15
            <div slot="content" v-if="!this.$slots.headerContent && desc">
                <p>{{ desc }}</p>
                <div v-if="this.linkList" class="link">
                    <template v-for="(link, index) in linkList">
16
                        <a :key="index" :href="link.href"> <a-icon :type="link.icon" />{{ link.title }} </a>
wb-ct393452's avatar
wb-ct393452 committed
17 18 19 20 21
                    </template>
                </div>
            </div>
            <slot v-if="this.$slots.extra" slot="extra" name="extra"></slot>
        </page-header>
水落(YangLei)'s avatar
水落(YangLei) committed
22
        <slot />
wb-ct393452's avatar
wb-ct393452 committed
23 24 25 26
    </div>
</template>

<script>
水落(YangLei)'s avatar
水落(YangLei) committed
27
import PageHeader from '@/components/page/PageHeader.vue';
wb-ct393452's avatar
wb-ct393452 committed
28 29
import { mapState, mapMutations } from 'vuex';
import { getI18nKey } from '@/utils/routerUtil';
水落(YangLei)'s avatar
水落(YangLei) committed
30
import { getUserInfo } from '@/utils';
wb-ct393452's avatar
wb-ct393452 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

export default {
    name: 'PageLayout',
    components: { PageHeader },
    props: ['desc', 'logo', 'title', 'avatar', 'linkList', 'extraImage'],
    data() {
        return {
            page: {},
            pageHeaderHeight: 0,
        };
    },
    watch: {
        $route() {
            this.page = this.$route.meta.page;
        },
    },
    updated() {
        if (!this._inactive) {
            this.updatePageHeight();
        }
    },
    activated() {
        this.updatePageHeight();
    },
    deactivated() {
        this.updatePageHeight(0);
    },
    mounted() {
        this.updatePageHeight();
    },
    created() {
水落(YangLei)'s avatar
水落(YangLei) committed
62 63
        const { menuList } = getUserInfo();
        this.menuList = menuList;
wb-ct393452's avatar
wb-ct393452 committed
64 65 66 67 68 69
        this.page = this.$route.meta.page;
    },
    beforeDestroy() {
        this.updatePageHeight(0);
    },
    computed: {
水落(YangLei)'s avatar
水落(YangLei) committed
70
        ...mapState('settingModule', ['layout', 'multiPage', 'pageMinHeight', 'pageWidth']),
wb-ct393452's avatar
wb-ct393452 committed
71
        breadcrumb() {
水落(YangLei)'s avatar
水落(YangLei) committed
72
            return this.getRouteBreadcrumb();
wb-ct393452's avatar
wb-ct393452 committed
73 74 75 76 77 78 79 80 81
        },
        marginCorrect() {
            return this.multiPage ? 24 : 0;
        },
    },
    methods: {
        ...mapMutations('settingModule', ['correctPageMinHeight']),
        getRouteBreadcrumb() {
            const path = this.$route.path;
水落(YangLei)'s avatar
水落(YangLei) committed
82 83 84 85 86 87 88
            const currentMenu = this.menuList.find(m => m.menuUrl === path);
            let parentMenuId = currentMenu.parentMenuId;
            const breadcrumb = [currentMenu.menuName];
            while (parentMenuId !== 0) {
                const parentMenu = this.menuList.find(m => m.menuId === parentMenuId);
                breadcrumb.unshift(parentMenu.menuName);
                parentMenuId = parentMenu.parentMenuId;
wb-ct393452's avatar
wb-ct393452 committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
            }
            return breadcrumb;
        },
        /**
         * 用于计算页面内容最小高度
         * @param newHeight
         */
        updatePageHeight(newHeight = this.$refs.pageHeader.$el.offsetHeight + this.marginCorrect) {
            this.correctPageMinHeight(this.pageHeaderHeight - newHeight);
            this.pageHeaderHeight = newHeight;
        },
    },
};
</script>

<style lang="less">
.link {
    line-height: 24px;
    a {
        font-size: 14px;
        margin-right: 32px;
        i {
            font-size: 22px;
            margin-right: 8px;
        }
    }
}
</style>