feat: add layout toggle

master
chenghx 7 years ago
parent 1488821833
commit db881e57bf
  1. 30
      src/components/layout/GlobalHeader.vue
  2. 7
      src/components/layout/GlobalLayout.vue
  3. 6
      src/components/menu/SiderMenu.vue
  4. 1
      src/components/menu/menu.js
  5. 22
      src/components/setting/Setting.vue
  6. 6
      src/store/modules/setting.js

@ -1,10 +1,13 @@
<template> <template>
<a-layout-header class="global-header"> <a-layout-header :class="[backgroundColor, 'global-header']">
<router-link v-if="isMobile" to="/" class="logo"> <router-link v-if="isMobile" to="/" class="logo">
<img width="32" src="static/img/vue-antd-logo.png" /> <img width="32" src="static/img/vue-antd-logo.png" />
</router-link> </router-link>
<a-divider v-if="isMobile" type="vertical" /> <a-divider v-if="isMobile" type="vertical" />
<a-icon 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">
<i-menu style="height: 64px; line-height: 64px;" :theme="theme" mode="horizontal" :menuData="menuData" @select="onSelect"/>
</div>
<div style="float: right"> <div style="float: right">
<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" >
@ -27,12 +30,14 @@ import HeaderNotice from './HeaderNotice'
import ATooltip from 'ant-design-vue/es/tooltip/Tooltip' import ATooltip from 'ant-design-vue/es/tooltip/Tooltip'
import HeaderAvatar from './HeaderlAvatar' import HeaderAvatar from './HeaderlAvatar'
import ADivider from 'ant-design-vue/es/divider/index' import ADivider from 'ant-design-vue/es/divider/index'
import IMenu from '../menu/menu'
const ALayoutSider = ALayout.Sider const ALayoutSider = ALayout.Sider
const ALayoutHeader = ALayout.Header const ALayoutHeader = ALayout.Header
export default { export default {
name: 'GlobalHeader', name: 'GlobalHeader',
components: { components: {
IMenu,
ADivider, ADivider,
HeaderAvatar, HeaderAvatar,
ATooltip, ATooltip,
@ -43,15 +48,24 @@ export default {
ALayout, ALayout,
ALayoutSider, ALayoutSider,
ALayoutHeader}, ALayoutHeader},
props: ['collapsed'], props: ['collapsed', 'menuData', 'theme'],
computed: { computed: {
isMobile () { isMobile () {
return this.$store.state.setting.isMobile return this.$store.state.setting.isMobile
},
layout () {
return this.$store.state.setting.layout
},
backgroundColor () {
return this.layout === 'side' ? 'light' : this.theme
} }
}, },
methods: { methods: {
toggleCollapse () { toggleCollapse () {
this.$emit('toggleCollapse') this.$emit('toggleCollapse')
},
onSelect (obj) {
this.$emit('menuSelect', obj)
} }
} }
} }
@ -82,11 +96,16 @@ export default {
} }
} }
.global-header{ .global-header{
background: #fff;
padding: 0 12px 0 0; padding: 0 12px 0 0;
-webkit-box-shadow: 0 1px 4px rgba(0,21,41,.08); -webkit-box-shadow: 0 1px 4px rgba(0,21,41,.08);
box-shadow: 0 1px 4px rgba(0,21,41,.08); box-shadow: 0 1px 4px rgba(0,21,41,.08);
position: relative; position: relative;
&.light{
background: #fff;
}
&.dark{
background-color: #001529;
}
.logo { .logo {
height: 64px; height: 64px;
line-height: 58px; line-height: 58px;
@ -100,5 +119,8 @@ export default {
vertical-align: middle; vertical-align: middle;
} }
} }
.global-header-menu{
display: inline-block;
}
} }
</style> </style>

@ -3,7 +3,7 @@
<drawer v-if="isMobile" :openDrawer="collapsed" @change="onDrawerChange"> <drawer v-if="isMobile" :openDrawer="collapsed" @change="onDrawerChange">
<sider-menu :theme="theme" :menuData="menuData" :collapsed="false" :collapsible="false" @menuSelect="onMenuSelect"/> <sider-menu :theme="theme" :menuData="menuData" :collapsed="false" :collapsible="false" @menuSelect="onMenuSelect"/>
</drawer> </drawer>
<sider-menu :theme="theme" v-else :menuData="menuData" :collapsed="collapsed" :collapsible="true" /> <sider-menu :theme="theme" v-else-if="layout === 'side'" :menuData="menuData" :collapsed="collapsed" :collapsible="true" />
<drawer :open-drawer="showSetting" placement="right" @change="onSettingDrawerChange"> <drawer :open-drawer="showSetting" placement="right" @change="onSettingDrawerChange">
<div class="setting" slot="handler"> <div class="setting" slot="handler">
<a-icon :type="showSetting ? 'close' : 'setting'" /> <a-icon :type="showSetting ? 'close' : 'setting'" />
@ -11,7 +11,7 @@
<setting /> <setting />
</drawer> </drawer>
<a-layout> <a-layout>
<global-header :collapsed="collapsed" @toggleCollapse="toggleCollapse"/> <global-header :menuData="menuData" :theme="theme" :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>
@ -69,6 +69,9 @@ export default {
}, },
theme () { theme () {
return this.$store.state.setting.theme return this.$store.state.setting.theme
},
layout () {
return this.$store.state.setting.layout
} }
}, },
methods: { methods: {

@ -51,12 +51,6 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.dark{
background-color: #002140;
}
.light{
background-color: #fff;
}
.shadow{ .shadow{
box-shadow: 2px 0 6px rgba(0,21,41,.35); box-shadow: 2px 0 6px rgba(0,21,41,.35);
} }

@ -166,7 +166,6 @@ export default {
props: { props: {
theme: this.$props.theme, theme: this.$props.theme,
mode: this.$props.mode, mode: this.$props.mode,
inlineCollapsed: false,
openKeys: this.openKeys, openKeys: this.openKeys,
selectedKeys: this.selectedKeys selectedKeys: this.selectedKeys
}, },

@ -1,9 +1,9 @@
<template> <template>
<a-layout-sider class="sider" width="273"> <a-layout-sider class="sider" width="273">
<setting-item title="整体风格设置"> <setting-item title="整体风格设置">
<img-check-box-group @change="onStyleChange"> <img-check-box-group @change="setTheme">
<img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" :checked="true" :value="{value: 1, name: 'dark'}"/> <img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" :checked="true" value="dark"/>
<img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" :value="{value: 2, name: 'light'}"/> <img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" value="light"/>
</img-check-box-group> </img-check-box-group>
</setting-item> </setting-item>
<setting-item title="主题色"> <setting-item title="主题色">
@ -20,9 +20,9 @@
</setting-item> </setting-item>
<a-divider/> <a-divider/>
<setting-item title="导航设置"> <setting-item title="导航设置">
<img-check-box-group @change="onNaviChange"> <img-check-box-group @change="setLayout">
<img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" :checked="true" :value="{value: 1, name: 'Side Navigation'}"/> <img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" :checked="true" value="side"/>
<img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" :value="{value: 2, name: 'Top Navigation'}"/> <img-check-box img="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" value="head"/>
</img-check-box-group> </img-check-box-group>
</setting-item> </setting-item>
<setting-item> <setting-item>
@ -105,13 +105,11 @@ export default {
this.$message.info(`您选择了主题色 ${colors}`) this.$message.info(`您选择了主题色 ${colors}`)
} }
}, },
onStyleChange (values) { setTheme (values) {
this.$store.commit('setting/setTheme', values[0].name) this.$store.commit('setting/setTheme', values[0])
}, },
onNaviChange (values) { setLayout (values) {
if (values.length > 0) { this.$store.commit('setting/setLayout', values[0])
this.$message.info(`您选择了 ${values[0].name} `)
}
}, },
copyCode () { copyCode () {
let clipboard = new Clipboard('#copyBtn') let clipboard = new Clipboard('#copyBtn')

@ -2,7 +2,8 @@ export default {
namespaced: true, namespaced: true,
state: { state: {
isMobile: false, isMobile: false,
theme: 'dark' theme: 'dark',
layout: 'side'
}, },
mutations: { mutations: {
setDevice (state, isMobile) { setDevice (state, isMobile) {
@ -10,6 +11,9 @@ export default {
}, },
setTheme (state, theme) { setTheme (state, theme) {
state.theme = theme state.theme = theme
},
setLayout (state, layout) {
state.layout = layout
} }
} }
} }

Loading…
Cancel
Save