mirror of
https://github.com/iczer/vue-antd-admin.git
synced 2025-05-11 07:19:01 +08:00
feat: add theme style toggle function
This commit is contained in:
parent
2cef87a631
commit
8a0c4b9a3c
@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-layout>
|
<a-layout>
|
||||||
<drawer v-if="isMobile" :openDrawer="collapsed" @change="onDrawerChange">
|
<drawer v-if="isMobile" :openDrawer="collapsed" @change="onDrawerChange">
|
||||||
<sider-menu :menuData="menuData" :collapsed="false" :collapsible="false" @menuSelect="onMenuSelect"/>
|
<sider-menu :theme="theme" :menuData="menuData" :collapsed="false" :collapsible="false" @menuSelect="onMenuSelect"/>
|
||||||
</drawer>
|
</drawer>
|
||||||
<sider-menu v-else :menuData="menuData" :collapsed="collapsed" :collapsible="true" />
|
<sider-menu :theme="theme" v-else :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'" />
|
||||||
@ -66,6 +66,9 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
isMobile () {
|
isMobile () {
|
||||||
return this.$store.state.setting.isMobile
|
return this.$store.state.setting.isMobile
|
||||||
|
},
|
||||||
|
theme () {
|
||||||
|
return this.$store.state.setting.theme
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-layout-sider :class="['sider', isMobile ? null : 'shadow']" width="256px" :collapsible="collapsible" v-model="collapsed" :trigger="null">
|
<a-layout-sider :class="[theme, 'sider', isMobile ? null : 'shadow']" width="256px" :collapsible="collapsible" v-model="collapsed" :trigger="null">
|
||||||
<div class="logo">
|
<div :class="['logo', theme]">
|
||||||
<router-link to="/dashboard/workplace">
|
<router-link to="/dashboard/workplace">
|
||||||
<img src="static/img/vue-antd-logo.png">
|
<img src="static/img/vue-antd-logo.png">
|
||||||
<h1>Vue Antd Admin</h1>
|
<h1>Vue Antd Admin</h1>
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<i-menu :collapsed="collapsed" :menuData="menuData" @select="onSelect"/>
|
<i-menu :theme="theme" :collapsed="collapsed" :menuData="menuData" @select="onSelect"/>
|
||||||
</a-layout-sider>
|
</a-layout-sider>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -30,6 +30,11 @@ export default {
|
|||||||
menuData: {
|
menuData: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
theme: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
default: 'dark'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -46,11 +51,23 @@ 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);
|
||||||
}
|
}
|
||||||
.sider{
|
.sider{
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
&.light{
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
&.dark{
|
||||||
|
background-color: #001529;
|
||||||
|
}
|
||||||
.logo{
|
.logo{
|
||||||
height: 64px;
|
height: 64px;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -58,8 +75,19 @@ export default {
|
|||||||
padding-left: 24px;
|
padding-left: 24px;
|
||||||
-webkit-transition: all .3s;
|
-webkit-transition: all .3s;
|
||||||
transition: all .3s;
|
transition: all .3s;
|
||||||
background: #002140;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
&.light{
|
||||||
|
background-color: #fff;
|
||||||
|
h1{
|
||||||
|
color: #1890ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.dark{
|
||||||
|
background-color: #002140;
|
||||||
|
h1{
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
h1{
|
h1{
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<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="onStyleChange">
|
||||||
<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="{value: 1, name: '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="{value: 2, name: 'light'}"/>
|
||||||
</img-check-box-group>
|
</img-check-box-group>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<setting-item title="主题色">
|
<setting-item title="主题色">
|
||||||
@ -106,9 +106,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onStyleChange (values) {
|
onStyleChange (values) {
|
||||||
if (values.length > 0) {
|
this.$store.commit('setting/setTheme', values[0].name)
|
||||||
this.$message.info(`您选择了 ${values[0].name} 风格`)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onNaviChange (values) {
|
onNaviChange (values) {
|
||||||
if (values.length > 0) {
|
if (values.length > 0) {
|
||||||
|
@ -118,6 +118,7 @@ export default {
|
|||||||
top: 200px;
|
top: 200px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
transition: all 0.5s;
|
transition: all 0.5s;
|
||||||
|
cursor: pointer;
|
||||||
.handler {
|
.handler {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
isMobile: false
|
isMobile: false,
|
||||||
|
theme: 'dark'
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setDevice (state, isMobile) {
|
setDevice (state, isMobile) {
|
||||||
state.isMobile = isMobile
|
state.isMobile = isMobile
|
||||||
|
},
|
||||||
|
setTheme (state, theme) {
|
||||||
|
state.theme = theme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user