IDCDatasync-vue/src/components/page/PageLayout.vue

223 lines
5.1 KiB
Vue

<template>
<div :style="!$route.meta.pageHeader ? 'margin: 0;' : null">
<!-- pageHeader , route meta hideHeader:true on hide -->
<page-header v-if="!$route.meta.pageHeader" :title="title" :logo="logo" :avatar="avatar">
<slot slot="action" name="action"></slot>
<!-- <slot slot="content" name="headerContent"></slot> -->
<!-- <div slot="content" v-if="!this.$slots.headerContent && desc">
<p style="font-size: 14px;color: rgba(0,0,0,.65)">{{ desc }}</p>
<div class="link">
<template v-for="(link, index) in linkList">
<a :key="index" :href="link.href">
<a-icon :type="link.icon" />
<span>{{ link.title }}</span>
</a>
</template>
</div>
</div> -->
<!-- <slot slot="extra" name="extra"></slot>
<div slot="pageMenu">
<div class="page-menu-search" v-if="search">
<a-input-search style="width: 80%; max-width: 522px;" placeholder="请输入..." size="large" enterButton="搜索" />
</div>
<div class="page-menu-tabs" v-if="tabs && tabs.items">
<a-tabs :tabBarStyle="{ margin: 0 }" @change="tabs.callback" :activeKey="tabs.active()">
<a-tab-pane v-for="item in tabs.items" :tab="item.title" :key="item.key"></a-tab-pane>
</a-tabs>
</div>
</div> -->
</page-header>
<div class="leftMenu">
<!-- <div class="parent"></div> -->
<!-- <div class="child" v-for="(item,index) in menuList">{{ item.meta.title }}</div> -->
<a-menu mode="vertical" theme="dark" :selected-keys="[current]" @click="handleClick">
<a-menu-item v-for="item in menuList" :key="item.id">
{{ item.meta.title }}
</a-menu-item>
</a-menu>
</div>
<div class="content">
<div :class="['page-header-index-wide']">
<slot></slot>
</div>
</div>
</div>
</template>
<script>
import PageHeader from './PageHeader'
import { mapState, mapActions } from 'vuex'
export default {
name: "LayoutContent",
components: {
PageHeader,
},
data() {
return {
current: '',
menuList: [],
parentTitle: ''
}
},
// ['desc', 'logo', 'title', 'avatar', 'linkList', 'extraImage']
props: {
desc: {
type: String,
default: null
},
logo: {
type: String,
default: null
},
title: {
type: String,
default: null
},
avatar: {
type: String,
default: null
},
linkList: {
type: Array,
default: null
},
extraImage: {
type: String,
default: null
},
search: {
type: Boolean,
default: false
},
tabs: {
type: Object,
default: () => { }
}
},
computed: {
...mapState({
// 主路由
mainRouters: (state) => state.permission.addRouters,
// 后台菜单
permissionMenuList: (state) => state.user.permissionList,
}),
},
watch: {
title(val) {
if (val) {
this.initMenuList()
}
}
},
mounted() {
this.initMenuList()
},
methods: {
initMenuList() {
this.menuList = []
this.parentTitle = this.$route.matched[1].meta.title
this.permissionMenuList.forEach((item) => {
if (item.meta.title == this.parentTitle) this.menuList = item.children
})
// 依据标题设置选中
if (this.menuList && this.menuList.length > 0) {
var choseMenu = this.menuList.filter(item => item.meta.title == this.title)
if (choseMenu && choseMenu.length > 0) this.current = choseMenu[0].id
}
},
handleClick(e) {
this.current = e.key;
var node = this.menuList.filter(item => item.id == e.key)
if (node && node.length > 0) this.$router.push({ name: node[0].name, path: node[0].path })
},
}
}
</script>
<style lang="less" scoped>
.leftMenu {
background-image: url('~@/assets/img/leftMenu.png');
background-repeat: no-repeat;
width: 288px;
height: calc(100vh - 64px);
position: absolute;
left: 20px;
top: 140px;
font-size: 18px;
padding: 30px 15px 0;
}
.leftMenu .parent {
width: 263px;
height: 46px;
background: linear-gradient(0deg, #1E30A2, #11B3FF);
color: #fff;
text-align: left;
padding-left: 20px;
line-height: 46px;
position: absolute;
left: 14px;
top: 30px;
}
.leftMenu .child {
height: 60px;
background-color: #00467C;
color: #fff;
text-align: center;
line-height: 60px;
}
.leftMenu .child.selected {
background-color: #2B85D1;
}
.content {
width: calc(100vw - 344px);
height: 913px;
background-color: #ffffff;
position: absolute;
left: 324px;
top: 140px;
padding: 72px 10px 0 20px;
.link {
margin-top: 16px;
&:not(:empty) {
margin-bottom: 16px;
}
a {
margin-right: 32px;
height: 24px;
line-height: 24px;
display: inline-block;
i {
font-size: 24px;
margin-right: 8px;
vertical-align: middle;
}
span {
height: 24px;
line-height: 24px;
display: inline-block;
vertical-align: middle;
}
}
}
}
.page-menu-search {
text-align: center;
margin-bottom: 16px;
}
.page-menu-tabs {
margin-top: 48px;
}
</style>