feat:新增主题功能

This commit is contained in:
zouzhibing 2022-09-13 21:18:36 +08:00
parent 16096a2e83
commit cdbca16c87
5 changed files with 56 additions and 19 deletions

View File

@ -14,6 +14,18 @@
</div>
<el-drawer
v-model="drawer" title="主题配置" size="300px">
<div class="theme-item">
<label>导航栏布局</label>
<el-select
v-model="layout"
placeholder="请选择"
style="width: 150px"
@change="(val) => changeSwitch('mode',val)"
>
<el-option label="纵向" value="vertical"></el-option>
<el-option label="横向" value="horizontal"></el-option>
</el-select>
</div>
<div class="theme-item">
<label>主题颜色</label>
<el-color-picker v-model="primary" :predefine="predefineColor" @change="changePrimary" />
@ -23,16 +35,12 @@
<switch-dark></switch-dark>
</div>
<div class="theme-item">
<label>导航栏布局</label>
<el-select
v-model="layout"
placeholder="请选择"
style="width: 150px"
@change="(val) => changeSwitch('mode',val)"
>
<el-option label="纵向" value="vertical"></el-option>
<el-option label="横向" value="horizontal"></el-option>
</el-select>
<label>灰色模式</label>
<el-switch v-model="gray" @change="(val) => changeGrayWeak('gray',val)" />
</div>
<div class="theme-item">
<label>色弱模式</label>
<el-switch v-model="weak" @change="(val) => changeGrayWeak('weak',val)" />
</div>
<div class="theme-item">
<label>标签栏</label>
@ -42,6 +50,14 @@
<label>侧边栏 Logo</label>
<el-switch v-model="showLogo" @change="(val) => changeSwitch('showLogo',val)" />
</div>
<div class="theme-item">
<label>保持一个子菜单的展开</label>
<el-switch v-model="uniqueOpened" @change="(val) => changeSwitch('uniqueOpened',val)" />
</div>
<div class="theme-item">
<label>固定header</label>
<el-switch v-model="fixedHeader" @change="(val) => changeSwitch('fixedHeader',val)" />
</div>
</el-drawer>
</div>
</template>
@ -57,7 +73,11 @@
const layout = ref(SettingStore.themeConfig.mode)
const showTag = ref(SettingStore.themeConfig.showTag)
const showLogo = ref(SettingStore.themeConfig.showLogo)
const uniqueOpened = ref(SettingStore.themeConfig.uniqueOpened)
const primary = ref(SettingStore.themeConfig.primary)
const fixedHeader = ref(SettingStore.themeConfig.fixedHeader)
const gray = ref(SettingStore.themeConfig.gray)
const weak = ref(SettingStore.themeConfig.weak)
const drawer = computed({
get() {
@ -105,6 +125,15 @@
changeSwitch('primary',val)
}
//
const changeGrayWeak = (type,val)=>{
const body = document.documentElement as HTMLElement;
if (!val) return body.setAttribute("style", "");
if (type === "gray") body.setAttribute("style", "filter: grayscale(1)");
if (type === "weak") body.setAttribute("style", "filter: invert(80%)");
changeSwitch(type,val)
}
</script>
<style lang="scss" scoped>

View File

@ -1,6 +1,7 @@
<template>
<div
class="m-layout-header"
:class="[SettingStore.themeConfig.fixedHeader&&'zb-fixed-header']"
:style="{ left: `${mode === 'horizontal' ? 0 : isCollapse ? '60' : '210'}px` }"
>
<div
@ -148,13 +149,15 @@
}
}
}
.m-layout-header {
.zb-fixed-header{
position: fixed;
top: 0;
background: white;
left: 0;
z-index: 9;
right: 0;
z-index: 9;
}
.m-layout-header {
background: white;
transition: left 0.3s;
flex-shrink: 0;
box-sizing: border-box;

View File

@ -1,10 +1,10 @@
<template>
<el-menu
:default-active="activeMenu"
active-text-color="#ffd04b"
background-color="#304156"
text-color="#fff"
:mode="mode"
:unique-opened="SettingStore.themeConfig.uniqueOpened"
:collapse-transition="false"
class="el-menu-vertical-demo"
:collapse="isCollapse"

View File

@ -8,10 +8,7 @@
hideSliderLayout: mode === 'horizontal',
}"
>
<div
:style="{
height:`${showTag?80:50}px`
}"></div>
<div :style="{ height:`${showTag?80:50}px` }" v-if="SettingStore.themeConfig.fixedHeader"></div>
<u-header />
<div class="m-container-content" :class="{ 'app-main-hide-tag': !showTag }">
<u-main />

View File

@ -31,7 +31,15 @@ export const useSettingStore = defineStore({
// 主题颜色
primary:PRIMARY_COLOR,
// element组件大小
globalComSize:'default'
globalComSize:'default',
// 是否只保持一个子菜单的展开
uniqueOpened:true,
// 固定header
fixedHeader:true,
// 灰色模式
gray:false,
// 色弱模式
weak:false
},
}),
getters: {},