Skip to content

Commit

Permalink
feat(Layout): Add cutMenu layout
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong502431556 committed Jan 21, 2022
1 parent 1522e92 commit ff4dd3a
Show file tree
Hide file tree
Showing 23 changed files with 711 additions and 171 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ initDark()
html,
body {
padding: 0;
padding: 0 !important;
margin: 0;
overflow: hidden;
.size;
Expand Down
43 changes: 24 additions & 19 deletions src/components/Logo/src/Logo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const appStore = useAppStore()
const show = ref(true)
const title = computed(() => appStore.getLogoTitle)
const title = computed(() => appStore.getTitle)
const layout = computed(() => appStore.getLayout)
Expand All @@ -19,15 +19,30 @@ onMounted(() => {
watch(
() => collapse.value,
(collapse: boolean) => {
if (layout.value !== 'classic') {
if (unref(layout) === 'topLeft' || unref(layout) === 'cutMenu') {
show.value = true
return
}
if (!collapse) {
setTimeout(() => {
show.value = !collapse
}, 400)
} else {
show.value = !collapse
}
}
)
watch(
() => layout.value,
(layout) => {
if (layout === 'top' || layout === 'cutMenu') {
show.value = true
} else {
if (!collapse) {
setTimeout(() => {
show.value = !collapse
}, 400)
if (unref(collapse)) {
show.value = false
} else {
show.value = !collapse
show.value = true
}
}
}
Expand Down Expand Up @@ -55,7 +70,8 @@ watch(
'ml-10px text-16px font-700',
{
'text-[var(--logo-title-text-color)]': layout === 'classic',
'text-[var(--top-header-text-color)]': layout === 'topLeft'
'text-[var(--top-header-text-color)]':
layout === 'topLeft' || layout === 'top' || layout === 'cutMenu'
}
]"
>
Expand All @@ -66,15 +82,4 @@ watch(

<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-logo';
.@{prefix-cls} {
&:after {
position: absolute;
right: 0;
bottom: 0;
width: 100%;
border-bottom: 1px solid var(--logo-border-color);
content: '';
}
}
</style>
116 changes: 80 additions & 36 deletions src/components/Menu/src/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="tsx">
import { computed, defineComponent, unref } from 'vue'
import { computed, defineComponent, unref, PropType } from 'vue'
import { ElMenu, ElScrollbar } from 'element-plus'
import { useAppStore } from '@/store/modules/app'
import { usePermissionStore } from '@/store/modules/permission'
Expand All @@ -10,25 +10,35 @@ import { isUrl } from '@/utils/is'
export default defineComponent({
name: 'Menu',
setup() {
props: {
menuSelect: {
type: Function as PropType<(index: string) => void>,
default: undefined
}
},
setup(props) {
const appStore = useAppStore()
const layout = computed(() => appStore.getLayout)
const { push, currentRoute } = useRouter()
const permissionStore = usePermissionStore()
const menuMode = computed((): 'vertical' | 'horizontal' => {
//
const vertical: LayoutType[] = ['classic', 'topLeft']
const vertical: LayoutType[] = ['classic', 'topLeft', 'cutMenu']
if (vertical.includes(appStore.getLayout)) {
if (vertical.includes(unref(layout))) {
return 'vertical'
} else {
return 'horizontal'
}
})
const routers = computed(() => permissionStore.getRouters)
const routers = computed(() =>
unref(layout) === 'cutMenu' ? permissionStore.getMenuTabRouters : permissionStore.getRouters
)
const collapse = computed(() => appStore.getCollapse)
Expand All @@ -42,6 +52,10 @@ export default defineComponent({
})
const menuSelect = (index: string) => {
if (props.menuSelect) {
props.menuSelect(index)
}
// 自定义事件
if (isUrl(index)) {
window.open(index)
} else {
Expand All @@ -52,19 +66,21 @@ export default defineComponent({
return () => (
<div
class={[
'v-menu',
'h-[100%] overflow-hidden z-100 flex-col',
appStore.getCollapse
? 'w-[var(--left-menu-min-width)]'
: 'w-[var(--left-menu-max-width)]',
'bg-[var(--left-menu-bg-color)]'
`v-menu v-menu__${unref(menuMode)}`,
'h-[100%] overflow-hidden z-100 flex-col bg-[var(--left-menu-bg-color)]',
{
'w-[var(--left-menu-min-width)]': unref(collapse) && unref(layout) !== 'cutMenu',
'w-[var(--left-menu-max-width)]': !unref(collapse) && unref(layout) !== 'cutMenu'
}
]}
>
<ElScrollbar>
<ElMenu
defaultActive={unref(activeMenu)}
mode={unref(menuMode)}
collapse={unref(collapse)}
collapse={
unref(layout) === 'top' || unref(layout) === 'cutMenu' ? false : unref(collapse)
}
backgroundColor="var(--left-menu-bg-color)"
textColor="var(--left-menu-text-color)"
activeTextColor="var(--left-menu-text-active-color)"
Expand Down Expand Up @@ -180,6 +196,35 @@ export default defineComponent({
display: none;
}
}
// 水平菜单
&__horizontal {
height: calc(~'var( - -top-tool-height)') !important;
:deep(.el-menu--horizontal) {
height: calc(~'var( - -top-tool-height)');
border-bottom: none;
// 重新设置底部高亮颜色
& > .el-sub-menu.is-active {
.el-sub-menu__title {
border-bottom-color: var(--el-color-primary) !important;
}
}
.el-menu-item.is-active {
position: relative;
&:after {
display: none !important;
}
}
.v-menu__title {
max-height: calc(~'var( - -top-tool-height)') !important;
line-height: calc(~'var( - -top-tool-height)');
}
}
}
}
</style>

Expand All @@ -196,36 +241,35 @@ export default defineComponent({
content: '';
}
.@{prefix-cls} {
&--vertical {
// 设置选中时子标题的颜色
.is-active {
& > .el-sub-menu__title {
color: var(--left-menu-text-active-color) !important;
}
.@{prefix-cls}--vertical,
.@{prefix-cls}--horizontal {
// 设置选中时子标题的颜色
.is-active {
& > .el-sub-menu__title {
color: var(--left-menu-text-active-color) !important;
}
}
// 设置子菜单悬停的高亮和背景色
.el-sub-menu__title,
.el-menu-item {
&:hover {
color: var(--left-menu-text-active-color) !important;
background-color: var(--left-menu-bg-color) !important;
}
// 设置子菜单悬停的高亮和背景色
.el-sub-menu__title,
.el-menu-item {
&:hover {
color: var(--left-menu-text-active-color) !important;
background-color: var(--left-menu-bg-color) !important;
}
}
// 设置选中时的高亮背景
.el-menu-item.is-active {
position: relative;
background-color: var(--left-menu-bg-active-color) !important;
// 设置选中时的高亮背景
.el-menu-item.is-active {
position: relative;
background-color: var(--left-menu-bg-active-color) !important;
&:hover {
background-color: var(--left-menu-bg-active-color) !important;
}
&:hover {
background-color: var(--left-menu-bg-active-color) !important;
}
&:after {
.is-active--after;
}
&:after {
.is-active--after;
}
}
}
Expand Down
61 changes: 43 additions & 18 deletions src/components/Setting/src/Setting.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ElDrawer, ElDivider } from 'element-plus'
import { ref, unref } from 'vue'
import { ref, unref, computed, watch } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { ThemeSwitch } from '@/components/ThemeSwitch'
import { colorIsDark, lighten, hexToRGB } from '@/utils/color'
Expand All @@ -15,6 +15,8 @@ const appStore = useAppStore()
const { t } = useI18n()
const layout = computed(() => appStore.getLayout)
const drawer = ref(false)
// 主题色相关
Expand All @@ -34,14 +36,20 @@ const setHeaderTheme = (color: string) => {
const isDarkColor = colorIsDark(color)
const textColor = isDarkColor ? '#fff' : 'inherit'
const textHoverColor = isDarkColor ? lighten(color!, 6) : '#f6f6f6'
const topToolBorderColor = isDarkColor ? color : '#eee'
setCssVar('--top-header-bg-color', color)
setCssVar('--top-header-text-color', textColor)
setCssVar('--top-header-hover-color', textHoverColor)
setCssVar('--top-tool-border-color', topToolBorderColor)
appStore.setTheme({
topHeaderBgColor: color,
topHeaderTextColor: textColor,
topHeaderHoverColor: textHoverColor
topHeaderHoverColor: textHoverColor,
topToolBorderColor
})
if (unref(layout) === 'top') {
setMenuTheme(color)
}
}
// 菜单主题相关
Expand Down Expand Up @@ -72,11 +80,26 @@ const setMenuTheme = (color: string) => {
// logo字体颜色
logoTitleTextColor: isDarkColor ? '#fff' : 'inherit',
// logo边框颜色
logoBorderColor: isDarkColor ? 'inherit' : '#eee'
logoBorderColor: isDarkColor ? color : '#eee'
}
appStore.setTheme(theme)
appStore.setCssVarTheme()
}
// 监听layout变化,重置一些主题色
watch(
() => layout.value,
(n, o) => {
if (o === 'top') {
menuTheme.value = '#fff'
setMenuTheme('#fff')
}
if ((o === 'classic' || o === 'topLeft') && n === 'top') {
menuTheme.value = headerTheme.value
setMenuTheme(unref(menuTheme))
}
}
)
</script>

<template>
Expand Down Expand Up @@ -136,21 +159,23 @@ const setMenuTheme = (color: string) => {
/>

<!-- 菜单主题 -->
<ElDivider>{{ t('setting.menuTheme') }}</ElDivider>
<ColorRadioPicker
v-model="menuTheme"
:schema="[
'#fff',
'#001529',
'#212121',
'#273352',
'#191b24',
'#383f45',
'#001628',
'#344058'
]"
@change="setMenuTheme"
/>
<template v-if="layout !== 'top'">
<ElDivider>{{ t('setting.menuTheme') }}</ElDivider>
<ColorRadioPicker
v-model="menuTheme"
:schema="[
'#fff',
'#001529',
'#212121',
'#273352',
'#191b24',
'#383f45',
'#001628',
'#344058'
]"
@change="setMenuTheme"
/>
</template>
</div>

<!-- 界面显示 -->
Expand Down
Loading

0 comments on commit ff4dd3a

Please sign in to comment.