refactor: admin layout settings (#441)

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/442/head
Ryan Wang 2022-02-18 15:43:12 +08:00 committed by GitHub
parent 022a3e1648
commit 9704b00cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 67 deletions

View File

@ -6,8 +6,8 @@
<h3 class="setting-drawer-index-title">整体风格设置</h3> <h3 class="setting-drawer-index-title">整体风格设置</h3>
<div class="setting-drawer-index-blockChecbox"> <div class="setting-drawer-index-blockChecbox">
<a-tooltip> <a-tooltip>
<template slot="title">暗色菜单风格</template> <template #title>暗色菜单风格</template>
<div class="setting-drawer-index-item" @click="handleMenuTheme('dark')"> <div class="setting-drawer-index-item" @click="handleSetMenuTheme('dark')">
<img alt="dark" src="/images/dark.svg" /> <img alt="dark" src="/images/dark.svg" />
<div v-if="navTheme === 'dark'" class="setting-drawer-index-selectIcon"> <div v-if="navTheme === 'dark'" class="setting-drawer-index-selectIcon">
<a-icon type="check" /> <a-icon type="check" />
@ -16,8 +16,8 @@
</a-tooltip> </a-tooltip>
<a-tooltip> <a-tooltip>
<template slot="title">亮色菜单风格</template> <template #title>亮色菜单风格</template>
<div class="setting-drawer-index-item" @click="handleMenuTheme('light')"> <div class="setting-drawer-index-item" @click="handleSetMenuTheme('light')">
<img alt="light" src="/images/dark.svg" /> <img alt="light" src="/images/dark.svg" />
<div v-if="navTheme !== 'dark'" class="setting-drawer-index-selectIcon"> <div v-if="navTheme !== 'dark'" class="setting-drawer-index-selectIcon">
<a-icon type="check" /> <a-icon type="check" />
@ -31,8 +31,8 @@
<h3 class="setting-drawer-index-title">主题色</h3> <h3 class="setting-drawer-index-title">主题色</h3>
<div class="h-5"> <div class="h-5">
<a-tooltip v-for="(item, index) in colorList" :key="index" class="setting-drawer-theme-color-colorBlock"> <a-tooltip v-for="(item, index) in colorList" :key="index" class="setting-drawer-theme-color-colorBlock">
<template slot="title">{{ item.key }}</template> <template #title>{{ item.key }}</template>
<a-tag :color="item.color" @click="changeColor(item.color)"> <a-tag :color="item.color" @click="handleChangeColor(item.color)">
<a-icon v-if="item.color === primaryColor" type="check"></a-icon> <a-icon v-if="item.color === primaryColor" type="check"></a-icon>
</a-tag> </a-tag>
</a-tooltip> </a-tooltip>
@ -43,14 +43,14 @@
<h3 class="setting-drawer-index-title">导航模式</h3> <h3 class="setting-drawer-index-title">导航模式</h3>
<div class="setting-drawer-index-blockChecbox"> <div class="setting-drawer-index-blockChecbox">
<div class="setting-drawer-index-item" @click="handleLayout('sidemenu')"> <div class="setting-drawer-index-item" @click="handleSetLayout('sidemenu')">
<img alt="sidemenu" src="/images/sidemenu.svg" /> <img alt="sidemenu" src="/images/sidemenu.svg" />
<div v-if="layoutMode === 'sidemenu'" class="setting-drawer-index-selectIcon"> <div v-if="layoutMode === 'sidemenu'" class="setting-drawer-index-selectIcon">
<a-icon type="check" /> <a-icon type="check" />
</div> </div>
</div> </div>
<div class="setting-drawer-index-item" @click="handleLayout('topmenu')"> <div class="setting-drawer-index-item" @click="handleSetLayout('topmenu')">
<img alt="topmenu" src="/images/topmenu.svg" /> <img alt="topmenu" src="/images/topmenu.svg" />
<div v-if="layoutMode !== 'sidemenu'" class="setting-drawer-index-selectIcon"> <div v-if="layoutMode !== 'sidemenu'" class="setting-drawer-index-selectIcon">
<a-icon type="check" /> <a-icon type="check" />
@ -62,10 +62,12 @@
<div class="mt-6"> <div class="mt-6">
<a-list :split="false"> <a-list :split="false">
<a-list-item> <a-list-item>
<a-tooltip slot="actions"> <template #actions>
<template slot="title"> 该设定仅 [顶部栏导航] 时有效 </template> <a-tooltip>
<template #title> 该设定仅 [顶部栏导航] 时有效</template>
<a-select <a-select
:defaultValue="contentWidth" :disabled="layoutMode !== 'topmenu'"
:value="contentWidth"
size="small" size="small"
style="width: 80px" style="width: 80px"
@change="handleContentWidthChange" @change="handleContentWidthChange"
@ -74,41 +76,54 @@
<a-select-option v-if="layoutMode !== 'sidemenu'" value="Fluid"></a-select-option> <a-select-option v-if="layoutMode !== 'sidemenu'" value="Fluid"></a-select-option>
</a-select> </a-select>
</a-tooltip> </a-tooltip>
</template>
<a-list-item-meta> <a-list-item-meta>
<div slot="title">内容区域宽度</div> <template #title>
<div>内容区域宽度</div>
</template>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
<a-list-item> <a-list-item>
<a-switch slot="actions" :defaultChecked="fixedHeader" size="small" @change="handleFixedHeader" /> <template #actions>
<a-switch :checked="fixedHeader" size="small" @change="handleSetFixedHeader" />
</template>
<a-list-item-meta> <a-list-item-meta>
<div slot="title">固定 Header</div> <template #title>
<div>固定 Header</div>
</template>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
<a-list-item> <a-list-item>
<template #actions>
<a-switch <a-switch
slot="actions" :checked="autoHideHeader"
:defaultChecked="autoHideHeader"
:disabled="!fixedHeader" :disabled="!fixedHeader"
size="small" size="small"
@change="handleFixedHeaderHidden" @change="handleSetAutoHideHeader"
/> />
</template>
<a-list-item-meta> <a-list-item-meta>
<a-tooltip slot="title" placement="left"> <template #title>
<template slot="title">固定 Header 时可配置</template> <a-tooltip placement="left">
<template #title>固定 Header 时可配置</template>
<div :style="{ opacity: !fixedHeader ? '0.5' : '1' }">下滑时隐藏 Header</div> <div :style="{ opacity: !fixedHeader ? '0.5' : '1' }">下滑时隐藏 Header</div>
</a-tooltip> </a-tooltip>
</template>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
<a-list-item> <a-list-item>
<template #actions>
<a-switch <a-switch
slot="actions" :checked="fixedSidebar"
:defaultChecked="fixedSidebar"
:disabled="layoutMode === 'topmenu'" :disabled="layoutMode === 'topmenu'"
size="small" size="small"
@change="handleFixedSidebar" @change="handleSetFixedSidebar"
/> />
</template>
<a-list-item-meta> <a-list-item-meta>
<div slot="title" :style="{ opacity: layoutMode === 'topmenu' ? '0.5' : '1' }">固定侧边菜单</div> <template #title>
<div :style="{ opacity: layoutMode === 'topmenu' ? '0.5' : '1' }">固定侧边菜单</div>
</template>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
</a-list> </a-list>
@ -148,43 +163,45 @@ export default {
onClose() { onClose() {
this.ToggleLayoutSetting(false) this.ToggleLayoutSetting(false)
}, },
handleMenuTheme(theme) { handleSetMenuTheme(theme) {
this.baseConfig.navTheme = theme this.baseConfig.navTheme = theme
this.$store.dispatch('ToggleTheme', theme) this.$store.dispatch('ToggleTheme', theme)
}, },
handleLayout(mode) { handleSetLayout(mode) {
this.baseConfig.layout = mode this.baseConfig.layout = mode
this.$store.dispatch('ToggleLayoutMode', mode) this.$store.dispatch('ToggleLayoutMode', mode)
this.handleFixedSidebar(false)
if (mode === 'sidemenu') { if (mode === 'sidemenu') {
this.handleContentWidthChange('Fixed') this.handleContentWidthChange('Fixed')
this.handleSetFixedSidebar(true)
} else {
this.handleSetFixedHeader(true)
this.handleSetFixedSidebar(false)
} }
}, },
handleContentWidthChange(type) { handleContentWidthChange(type) {
this.baseConfig.contentWidth = type this.baseConfig.contentWidth = type
this.$store.dispatch('ToggleContentWidth', type) this.$store.dispatch('ToggleContentWidth', type)
}, },
changeColor(color) { handleChangeColor(color) {
this.baseConfig.primaryColor = color this.baseConfig.primaryColor = color
if (this.primaryColor !== color) { if (this.primaryColor !== color) {
this.$store.dispatch('ToggleColor', color) this.$store.dispatch('ToggleColor', color)
updateTheme(color) updateTheme(color)
} }
}, },
handleFixedHeader(fixed) { handleSetFixedHeader(fixed) {
this.baseConfig.fixedHeader = fixed this.baseConfig.fixedHeader = fixed
this.$store.dispatch('ToggleFixedHeader', fixed) this.$store.dispatch('ToggleFixedHeader', fixed)
if (!fixed) {
this.handleSetAutoHideHeader(false)
}
}, },
handleFixedHeaderHidden(autoHidden) { handleSetAutoHideHeader(autoHidden) {
this.baseConfig.autoHideHeader = autoHidden this.baseConfig.autoHideHeader = autoHidden
this.$store.dispatch('ToggleFixedHeaderHidden', autoHidden) this.$store.dispatch('ToggleFixedHeaderHidden', autoHidden)
}, },
handleFixedSidebar(fixed) { handleSetFixedSidebar(fixed) {
if (this.layoutMode === 'topmenu') {
this.baseConfig.fixedSidebar = false
this.$store.dispatch('ToggleFixedSidebar', false)
return
}
this.baseConfig.fixedSidebar = fixed this.baseConfig.fixedSidebar = fixed
this.$store.dispatch('ToggleFixedSidebar', fixed) this.$store.dispatch('ToggleFixedSidebar', fixed)
} }

View File

@ -1,10 +1,10 @@
export default { export default {
primaryColor: '#1890FF', primaryColor: '#1890FF',
navTheme: 'dark', navTheme: 'dark',
layout: 'topmenu', layout: 'sidemenu',
contentWidth: 'Fixed', contentWidth: 'Fixed',
fixedHeader: false, fixedHeader: false,
fixedSidebar: false, fixedSidebar: true,
autoHideHeader: false, autoHideHeader: false,
storageOptions: { storageOptions: {
namespace: 'halo__', namespace: 'halo__',

View File

@ -84,9 +84,6 @@ const app = {
commit('TOGGLE_LAYOUT_MODE', mode) commit('TOGGLE_LAYOUT_MODE', mode)
}, },
ToggleFixedHeader({ commit }, fixedHeader) { ToggleFixedHeader({ commit }, fixedHeader) {
if (!fixedHeader) {
commit('TOGGLE_FIXED_HEADER_HIDDEN', false)
}
commit('TOGGLE_FIXED_HEADER', fixedHeader) commit('TOGGLE_FIXED_HEADER', fixedHeader)
}, },
ToggleFixedSidebar({ commit }, fixedSidebar) { ToggleFixedSidebar({ commit }, fixedSidebar) {