4
0
mirror of https://github.com/iczer/vue-antd-admin.git synced 2025-04-06 03:57:44 +08:00

feat: complete layout toggle function

This commit is contained in:
iczer 2018-08-30 11:57:21 +08:00 committed by chenghx
parent db881e57bf
commit 2adbdc8830
5 changed files with 182 additions and 114 deletions

View File

@ -1,14 +1,16 @@
<template> <template>
<a-layout-header :class="[backgroundColor, 'global-header']"> <a-layout-header :class="[theme, 'global-header']">
<router-link v-if="isMobile" to="/" class="logo"> <div :class="['global-header-wide', layout]">
<router-link v-if="isMobile || layout === 'head'" to="/" :class="['logo', isMobile ? null : 'pc', theme]">
<img width="32" src="static/img/vue-antd-logo.png" /> <img width="32" src="static/img/vue-antd-logo.png" />
<h1 v-if="!isMobile">Vue Antd Admin</h1>
</router-link> </router-link>
<a-divider v-if="isMobile" type="vertical" /> <a-divider v-if="isMobile" type="vertical" />
<a-icon v-if="layout === 'side'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/> <a-icon v-if="layout === 'side'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/>
<div v-if="layout === 'head'" class="global-header-menu"> <div v-if="layout === 'head'" class="global-header-menu">
<i-menu style="height: 64px; line-height: 64px;" :theme="theme" mode="horizontal" :menuData="menuData" @select="onSelect"/> <i-menu style="height: 64px; line-height: 64px;" :theme="theme" mode="horizontal" :menuData="menuData" @select="onSelect"/>
</div> </div>
<div style="float: right"> <div :class="['global-header-right', theme]">
<header-search class="header-item" /> <header-search class="header-item" />
<a-tooltip class="header-item" title="帮助文档" placement="bottom" > <a-tooltip class="header-item" title="帮助文档" placement="bottom" >
<a> <a>
@ -18,6 +20,7 @@
<header-notice class="header-item"/> <header-notice class="header-item"/>
<header-avatar class="header-item"/> <header-avatar class="header-item"/>
</div> </div>
</div>
</a-layout-header> </a-layout-header>
</template> </template>
@ -48,7 +51,7 @@ export default {
ALayout, ALayout,
ALayoutSider, ALayoutSider,
ALayoutHeader}, ALayoutHeader},
props: ['collapsed', 'menuData', 'theme'], props: ['collapsed', 'menuData'],
computed: { computed: {
isMobile () { isMobile () {
return this.$store.state.setting.isMobile return this.$store.state.setting.isMobile
@ -56,8 +59,8 @@ export default {
layout () { layout () {
return this.$store.state.setting.layout return this.$store.state.setting.layout
}, },
backgroundColor () { theme () {
return this.layout === 'side' ? 'light' : this.theme return this.layout === 'side' ? 'light' : this.$store.state.setting.theme
} }
}, },
methods: { methods: {
@ -78,12 +81,10 @@ export default {
padding: 0 24px; padding: 0 24px;
cursor: pointer; cursor: pointer;
transition: color .3s; transition: color .3s;
} &:hover{
.trigger:hover {
color: #1890ff; color: #1890ff;
} }
}
.header-item{ .header-item{
padding: 0 12px; padding: 0 12px;
display: inline-block; display: inline-block;
@ -104,7 +105,14 @@ export default {
background: #fff; background: #fff;
} }
&.dark{ &.dark{
background-color: #001529; background: #001529;
}
.global-header-wide{
&.head{
max-width: 1200px;
margin: auto;
}
&.side{
} }
.logo { .logo {
height: 64px; height: 64px;
@ -114,13 +122,33 @@ export default {
padding: 0 12px 0 24px; padding: 0 12px 0 24px;
cursor: pointer; cursor: pointer;
font-size: 20px; font-size: 20px;
&.pc{
padding: 0 12px 0 0;
}
img { img {
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
} }
h1{
display: inline-block;
font-size: 16px;
}
&.dark h1{
color: #fff;
}
} }
.global-header-menu{ .global-header-menu{
display: inline-block; display: inline-block;
} }
.global-header-right{
float: right;
&.dark{
color: #fff;
i{
color: #fff;
}
}
}
}
} }
</style> </style>

View File

@ -11,7 +11,7 @@
<setting /> <setting />
</drawer> </drawer>
<a-layout> <a-layout>
<global-header :menuData="menuData" :theme="theme" :collapsed="collapsed" @toggleCollapse="toggleCollapse"/> <global-header :menuData="menuData" :collapsed="collapsed" @toggleCollapse="toggleCollapse"/>
<a-layout-content :style="{minHeight: minHeight, margin: '24px 24px 0'}"> <a-layout-content :style="{minHeight: minHeight, margin: '24px 24px 0'}">
<slot></slot> <slot></slot>
</a-layout-content> </a-layout-content>

View File

@ -33,7 +33,7 @@
</template> </template>
<span @click="fetchNotice" class="header-notice"> <span @click="fetchNotice" class="header-notice">
<a-badge count="12"> <a-badge count="12">
<a-icon style="font-size: 16px; padding: 4px" type="bell" /> <a-icon :class="['header-notice-icon', theme]" type="bell" />
</a-badge> </a-badge>
</span> </span>
</a-popover> </a-popover>
@ -60,6 +60,11 @@ export default {
loadding: false loadding: false
} }
}, },
computed: {
theme () {
return this.$store.state.setting.layout === 'side' ? 'light' : this.$store.state.setting.theme
}
},
methods: { methods: {
fetchNotice () { fetchNotice () {
if (this.loadding) { if (this.loadding) {
@ -79,10 +84,18 @@ export default {
.header-notice{ .header-notice{
display: inline-block; display: inline-block;
transition: all 0.3s; transition: all 0.3s;
& :global{
span { span {
vertical-align: initial; vertical-align: initial;
} }
.header-notice-icon{
font-size: 16px;
padding: 4px;
&.dark{
color: #fff;
}
&.light{
color: rgba(0,0,0,.65);
}
} }
} }
</style> </style>

View File

@ -13,7 +13,7 @@
</div> </div>
<slot slot="extra" name="extra"></slot> <slot slot="extra" name="extra"></slot>
</page-header> </page-header>
<div ref="page" style="margin: 24px 24px 0px"> <div ref="page" :class="['page-content', layout]" >
<slot ></slot> <slot ></slot>
</div> </div>
</div> </div>
@ -31,6 +31,11 @@ export default {
breadcrumb: [] breadcrumb: []
} }
}, },
computed: {
layout () {
return this.$store.state.setting.layout
}
},
mounted () { mounted () {
this.getBreadcrumb() this.getBreadcrumb()
}, },
@ -58,5 +63,13 @@ export default {
} }
} }
} }
.page-content{
&.side{
margin: 24px 24px 0px;
}
&.head{
margin: 24px auto 0;
max-width: 1200px;
}
}
</style> </style>

View File

@ -1,5 +1,6 @@
<template> <template>
<div class="page-header"> <div class="page-header">
<div :class="['page-header-wide', layout]">
<div class="breadcrumb"> <div class="breadcrumb">
<a-breadcrumb> <a-breadcrumb>
<a-breadcrumb-item :key="item.path" v-for="(item, index) in breadcrumb"> <a-breadcrumb-item :key="item.path" v-for="(item, index) in breadcrumb">
@ -21,7 +22,7 @@
<div v-if="this.$slots.extra" class="extra"><slot name="extra"></slot></div> <div v-if="this.$slots.extra" class="extra"><slot name="extra"></slot></div>
</div> </div>
</div> </div>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -51,6 +52,11 @@ export default {
type: String, type: String,
required: false required: false
} }
},
computed: {
layout () {
return this.$store.state.setting.layout
}
} }
} }
</script> </script>
@ -60,6 +66,13 @@ export default {
background: #fff; background: #fff;
padding: 16px 32px 0; padding: 16px 32px 0;
border-bottom: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8;
.page-header-wide{
&.head{
margin: auto;
max-width: 1200px;
}
&.side{
}
.breadcrumb{ .breadcrumb{
margin-bottom: 16px; margin-bottom: 16px;
} }
@ -114,4 +127,5 @@ export default {
} }
} }
} }
}
</style> </style>