Skip to content

Commit ff4dd3a

Browse files
feat(Layout): Add cutMenu layout
1 parent 1522e92 commit ff4dd3a

File tree

23 files changed

+711
-171
lines changed

23 files changed

+711
-171
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ initDark()
3434
3535
html,
3636
body {
37-
padding: 0;
37+
padding: 0 !important;
3838
margin: 0;
3939
overflow: hidden;
4040
.size;

src/components/Logo/src/Logo.vue

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const appStore = useAppStore()
66
77
const show = ref(true)
88
9-
const title = computed(() => appStore.getLogoTitle)
9+
const title = computed(() => appStore.getTitle)
1010
1111
const layout = computed(() => appStore.getLayout)
1212
@@ -19,15 +19,30 @@ onMounted(() => {
1919
watch(
2020
() => collapse.value,
2121
(collapse: boolean) => {
22-
if (layout.value !== 'classic') {
22+
if (unref(layout) === 'topLeft' || unref(layout) === 'cutMenu') {
23+
show.value = true
24+
return
25+
}
26+
if (!collapse) {
27+
setTimeout(() => {
28+
show.value = !collapse
29+
}, 400)
30+
} else {
31+
show.value = !collapse
32+
}
33+
}
34+
)
35+
36+
watch(
37+
() => layout.value,
38+
(layout) => {
39+
if (layout === 'top' || layout === 'cutMenu') {
2340
show.value = true
2441
} else {
25-
if (!collapse) {
26-
setTimeout(() => {
27-
show.value = !collapse
28-
}, 400)
42+
if (unref(collapse)) {
43+
show.value = false
2944
} else {
30-
show.value = !collapse
45+
show.value = true
3146
}
3247
}
3348
}
@@ -55,7 +70,8 @@ watch(
5570
'ml-10px text-16px font-700',
5671
{
5772
'text-[var(--logo-title-text-color)]': layout === 'classic',
58-
'text-[var(--top-header-text-color)]': layout === 'topLeft'
73+
'text-[var(--top-header-text-color)]':
74+
layout === 'topLeft' || layout === 'top' || layout === 'cutMenu'
5975
}
6076
]"
6177
>
@@ -66,15 +82,4 @@ watch(
6682

6783
<style lang="less" scoped>
6884
@prefix-cls: ~'@{namespace}-logo';
69-
70-
.@{prefix-cls} {
71-
&:after {
72-
position: absolute;
73-
right: 0;
74-
bottom: 0;
75-
width: 100%;
76-
border-bottom: 1px solid var(--logo-border-color);
77-
content: '';
78-
}
79-
}
8085
</style>

src/components/Menu/src/Menu.vue

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="tsx">
2-
import { computed, defineComponent, unref } from 'vue'
2+
import { computed, defineComponent, unref, PropType } from 'vue'
33
import { ElMenu, ElScrollbar } from 'element-plus'
44
import { useAppStore } from '@/store/modules/app'
55
import { usePermissionStore } from '@/store/modules/permission'
@@ -10,25 +10,35 @@ import { isUrl } from '@/utils/is'
1010
1111
export default defineComponent({
1212
name: 'Menu',
13-
setup() {
13+
props: {
14+
menuSelect: {
15+
type: Function as PropType<(index: string) => void>,
16+
default: undefined
17+
}
18+
},
19+
setup(props) {
1420
const appStore = useAppStore()
1521
22+
const layout = computed(() => appStore.getLayout)
23+
1624
const { push, currentRoute } = useRouter()
1725
1826
const permissionStore = usePermissionStore()
1927
2028
const menuMode = computed((): 'vertical' | 'horizontal' => {
2129
//
22-
const vertical: LayoutType[] = ['classic', 'topLeft']
30+
const vertical: LayoutType[] = ['classic', 'topLeft', 'cutMenu']
2331
24-
if (vertical.includes(appStore.getLayout)) {
32+
if (vertical.includes(unref(layout))) {
2533
return 'vertical'
2634
} else {
2735
return 'horizontal'
2836
}
2937
})
3038
31-
const routers = computed(() => permissionStore.getRouters)
39+
const routers = computed(() =>
40+
unref(layout) === 'cutMenu' ? permissionStore.getMenuTabRouters : permissionStore.getRouters
41+
)
3242
3343
const collapse = computed(() => appStore.getCollapse)
3444
@@ -42,6 +52,10 @@ export default defineComponent({
4252
})
4353
4454
const menuSelect = (index: string) => {
55+
if (props.menuSelect) {
56+
props.menuSelect(index)
57+
}
58+
// 自定义事件
4559
if (isUrl(index)) {
4660
window.open(index)
4761
} else {
@@ -52,19 +66,21 @@ export default defineComponent({
5266
return () => (
5367
<div
5468
class={[
55-
'v-menu',
56-
'h-[100%] overflow-hidden z-100 flex-col',
57-
appStore.getCollapse
58-
? 'w-[var(--left-menu-min-width)]'
59-
: 'w-[var(--left-menu-max-width)]',
60-
'bg-[var(--left-menu-bg-color)]'
69+
`v-menu v-menu__${unref(menuMode)}`,
70+
'h-[100%] overflow-hidden z-100 flex-col bg-[var(--left-menu-bg-color)]',
71+
{
72+
'w-[var(--left-menu-min-width)]': unref(collapse) && unref(layout) !== 'cutMenu',
73+
'w-[var(--left-menu-max-width)]': !unref(collapse) && unref(layout) !== 'cutMenu'
74+
}
6175
]}
6276
>
6377
<ElScrollbar>
6478
<ElMenu
6579
defaultActive={unref(activeMenu)}
6680
mode={unref(menuMode)}
67-
collapse={unref(collapse)}
81+
collapse={
82+
unref(layout) === 'top' || unref(layout) === 'cutMenu' ? false : unref(collapse)
83+
}
6884
backgroundColor="var(--left-menu-bg-color)"
6985
textColor="var(--left-menu-text-color)"
7086
activeTextColor="var(--left-menu-text-active-color)"
@@ -180,6 +196,35 @@ export default defineComponent({
180196
display: none;
181197
}
182198
}
199+
200+
// 水平菜单
201+
&__horizontal {
202+
height: calc(~'var( - -top-tool-height)') !important;
203+
204+
:deep(.el-menu--horizontal) {
205+
height: calc(~'var( - -top-tool-height)');
206+
border-bottom: none;
207+
// 重新设置底部高亮颜色
208+
& > .el-sub-menu.is-active {
209+
.el-sub-menu__title {
210+
border-bottom-color: var(--el-color-primary) !important;
211+
}
212+
}
213+
214+
.el-menu-item.is-active {
215+
position: relative;
216+
217+
&:after {
218+
display: none !important;
219+
}
220+
}
221+
222+
.v-menu__title {
223+
max-height: calc(~'var( - -top-tool-height)') !important;
224+
line-height: calc(~'var( - -top-tool-height)');
225+
}
226+
}
227+
}
183228
}
184229
</style>
185230

@@ -196,36 +241,35 @@ export default defineComponent({
196241
content: '';
197242
}
198243
199-
.@{prefix-cls} {
200-
&--vertical {
201-
// 设置选中时子标题的颜色
202-
.is-active {
203-
& > .el-sub-menu__title {
204-
color: var(--left-menu-text-active-color) !important;
205-
}
244+
.@{prefix-cls}--vertical,
245+
.@{prefix-cls}--horizontal {
246+
// 设置选中时子标题的颜色
247+
.is-active {
248+
& > .el-sub-menu__title {
249+
color: var(--left-menu-text-active-color) !important;
206250
}
251+
}
207252
208-
// 设置子菜单悬停的高亮和背景色
209-
.el-sub-menu__title,
210-
.el-menu-item {
211-
&:hover {
212-
color: var(--left-menu-text-active-color) !important;
213-
background-color: var(--left-menu-bg-color) !important;
214-
}
253+
// 设置子菜单悬停的高亮和背景色
254+
.el-sub-menu__title,
255+
.el-menu-item {
256+
&:hover {
257+
color: var(--left-menu-text-active-color) !important;
258+
background-color: var(--left-menu-bg-color) !important;
215259
}
260+
}
216261
217-
// 设置选中时的高亮背景
218-
.el-menu-item.is-active {
219-
position: relative;
220-
background-color: var(--left-menu-bg-active-color) !important;
262+
// 设置选中时的高亮背景
263+
.el-menu-item.is-active {
264+
position: relative;
265+
background-color: var(--left-menu-bg-active-color) !important;
221266
222-
&:hover {
223-
background-color: var(--left-menu-bg-active-color) !important;
224-
}
267+
&:hover {
268+
background-color: var(--left-menu-bg-active-color) !important;
269+
}
225270
226-
&:after {
227-
.is-active--after;
228-
}
271+
&:after {
272+
.is-active--after;
229273
}
230274
}
231275
}

src/components/Setting/src/Setting.vue

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { ElDrawer, ElDivider } from 'element-plus'
3-
import { ref, unref } from 'vue'
3+
import { ref, unref, computed, watch } from 'vue'
44
import { useI18n } from '@/hooks/web/useI18n'
55
import { ThemeSwitch } from '@/components/ThemeSwitch'
66
import { colorIsDark, lighten, hexToRGB } from '@/utils/color'
@@ -15,6 +15,8 @@ const appStore = useAppStore()
1515
1616
const { t } = useI18n()
1717
18+
const layout = computed(() => appStore.getLayout)
19+
1820
const drawer = ref(false)
1921
2022
// 主题色相关
@@ -34,14 +36,20 @@ const setHeaderTheme = (color: string) => {
3436
const isDarkColor = colorIsDark(color)
3537
const textColor = isDarkColor ? '#fff' : 'inherit'
3638
const textHoverColor = isDarkColor ? lighten(color!, 6) : '#f6f6f6'
39+
const topToolBorderColor = isDarkColor ? color : '#eee'
3740
setCssVar('--top-header-bg-color', color)
3841
setCssVar('--top-header-text-color', textColor)
3942
setCssVar('--top-header-hover-color', textHoverColor)
43+
setCssVar('--top-tool-border-color', topToolBorderColor)
4044
appStore.setTheme({
4145
topHeaderBgColor: color,
4246
topHeaderTextColor: textColor,
43-
topHeaderHoverColor: textHoverColor
47+
topHeaderHoverColor: textHoverColor,
48+
topToolBorderColor
4449
})
50+
if (unref(layout) === 'top') {
51+
setMenuTheme(color)
52+
}
4553
}
4654
4755
// 菜单主题相关
@@ -72,11 +80,26 @@ const setMenuTheme = (color: string) => {
7280
// logo字体颜色
7381
logoTitleTextColor: isDarkColor ? '#fff' : 'inherit',
7482
// logo边框颜色
75-
logoBorderColor: isDarkColor ? 'inherit' : '#eee'
83+
logoBorderColor: isDarkColor ? color : '#eee'
7684
}
7785
appStore.setTheme(theme)
7886
appStore.setCssVarTheme()
7987
}
88+
89+
// 监听layout变化,重置一些主题色
90+
watch(
91+
() => layout.value,
92+
(n, o) => {
93+
if (o === 'top') {
94+
menuTheme.value = '#fff'
95+
setMenuTheme('#fff')
96+
}
97+
if ((o === 'classic' || o === 'topLeft') && n === 'top') {
98+
menuTheme.value = headerTheme.value
99+
setMenuTheme(unref(menuTheme))
100+
}
101+
}
102+
)
80103
</script>
81104

82105
<template>
@@ -136,21 +159,23 @@ const setMenuTheme = (color: string) => {
136159
/>
137160

138161
<!-- 菜单主题 -->
139-
<ElDivider>{{ t('setting.menuTheme') }}</ElDivider>
140-
<ColorRadioPicker
141-
v-model="menuTheme"
142-
:schema="[
143-
'#fff',
144-
'#001529',
145-
'#212121',
146-
'#273352',
147-
'#191b24',
148-
'#383f45',
149-
'#001628',
150-
'#344058'
151-
]"
152-
@change="setMenuTheme"
153-
/>
162+
<template v-if="layout !== 'top'">
163+
<ElDivider>{{ t('setting.menuTheme') }}</ElDivider>
164+
<ColorRadioPicker
165+
v-model="menuTheme"
166+
:schema="[
167+
'#fff',
168+
'#001529',
169+
'#212121',
170+
'#273352',
171+
'#191b24',
172+
'#383f45',
173+
'#001628',
174+
'#344058'
175+
]"
176+
@change="setMenuTheme"
177+
/>
178+
</template>
154179
</div>
155180

156181
<!-- 界面显示 -->

0 commit comments

Comments
 (0)