Skip to content

Commit bd24b92

Browse files
feat: 🎸 layout布局重构中
1 parent 29d9c98 commit bd24b92

File tree

10 files changed

+364
-174
lines changed

10 files changed

+364
-174
lines changed

src/components/Logo/index.vue

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<router-link class="app-logo" to="/">
2+
<router-link class="app-logo" to="/" :class="{'app-logo--Top': layout !== 'Classic'}">
33
<img :src="require('@/assets/img/logo.png')">
44
<div v-if="show" class="sidebar-title">{{ title }}</div>
55
</router-link>
66
</template>
77

88
<script lang="ts">
9-
import { defineComponent, ref, watch, PropType } from 'vue'
10-
import config from '_p/index/config'
9+
import { defineComponent, ref, watch, PropType, computed } from 'vue'
10+
import { appStore } from '_p/index/store/modules/app'
1111
1212
export default defineComponent({
1313
name: 'Logo',
@@ -19,21 +19,28 @@ export default defineComponent({
1919
},
2020
setup(props) {
2121
const show = ref<boolean>(true)
22+
const title = computed(() => appStore.title)
23+
const layout = computed(() => appStore.layout)
2224
watch(
2325
() => props.collapsed,
2426
(collapsed: boolean) => {
25-
if (!collapsed) {
26-
setTimeout(() => {
27-
show.value = !collapsed
28-
}, 400)
27+
if (layout.value !== 'Classic') {
28+
show.value = true
2929
} else {
30-
show.value = !collapsed
30+
if (!collapsed) {
31+
setTimeout(() => {
32+
show.value = !collapsed
33+
}, 400)
34+
} else {
35+
show.value = !collapsed
36+
}
3137
}
3238
}
3339
)
3440
return {
3541
show,
36-
title: config.title
42+
title,
43+
layout
3744
}
3845
}
3946
})
@@ -44,7 +51,7 @@ export default defineComponent({
4451
display: flex;
4552
align-items: center;
4653
cursor: pointer;
47-
height: @topSilderHeight;
54+
height: @topSiderHeight;
4855
width: 100%;
4956
background-color: @menuBg;
5057
img {
@@ -59,7 +66,22 @@ export default defineComponent({
5966
margin-left: 12px;
6067
}
6168
.sidebar-title {
62-
color: #fff;
69+
color: @menuActiveText;
70+
}
71+
}
72+
.app-logo--Top {
73+
width: auto;
74+
background-color: @topMenuBg;
75+
transition: background 0.2s;
76+
padding: 0 5px;
77+
&:hover {
78+
background: #f6f6f6;
79+
}
80+
img {
81+
margin-left: 0;
82+
}
83+
.sidebar-title {
84+
color: @topMenuText;
6385
}
6486
}
6587
</style>

src/components/ScrollPane/index.vue

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/components/Setting/index.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
</div>
3939

4040
<div class="setting__title">界面显示</div>
41-
<div class="setting__item">
41+
<div v-if="layout !== 'Top'" class="setting__item">
4242
<span>顶部操作栏</span>
4343
<el-switch v-model="navbar" @change="setNavbar" />
4444
</div>
45-
<div class="setting__item">
45+
<div v-if="layout !== 'Top'" class="setting__item">
4646
<span>侧边栏缩收</span>
4747
<el-switch v-model="hamburger" @change="setHamburger" />
4848
</div>
49-
<div class="setting__item">
49+
<div v-if="layout !== 'Top'" class="setting__item">
5050
<span>面包屑</span>
5151
<el-switch v-model="breadcrumb" @change="setBreadcrumb" />
5252
</div>
@@ -79,6 +79,7 @@ export default defineComponent({
7979
function setLayout(mode: 'Classic' | 'LeftTop' | 'Top' | 'Test') {
8080
if (mode === layout.value) return
8181
appStore.SetLayout(mode)
82+
appStore.SetCollapsed(false)
8283
}
8384
8485
// const fixedNavbar = ref<boolean>(appStore.fixedNavbar)

src/components/Sider/SiderItem.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-if="!item.meta?.hidden">
2+
<template v-if="!item.meta?.hidden">
33
<template v-if="hasOneShowingChild(item.children, item) && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.meta?.alwaysShow">
44
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown': !isNest}">
55
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" />
@@ -9,7 +9,13 @@
99
</el-menu-item>
1010
</template>
1111

12-
<el-submenu v-else popper-class="nest-popper-menu" :index="resolvePath(item.path)">
12+
<el-submenu
13+
v-else
14+
:popper-class="layout !== 'Top'
15+
? 'nest-popper-menu'
16+
: 'top-popper-menu'"
17+
:index="resolvePath(item.path)"
18+
>
1319
<template #title>
1420
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
1521
</template>
@@ -18,11 +24,11 @@
1824
:key="child.path"
1925
:is-nest="true"
2026
:item="child"
27+
:layout="layout"
2128
:base-path="resolvePath(child.path)"
22-
class="nest-menu"
2329
/>
2430
</el-submenu>
25-
</div>
31+
</template>
2632
</template>
2733

2834
<script lang="ts">
@@ -47,6 +53,10 @@ export default defineComponent({
4753
basePath: {
4854
type: String as PropType<string>,
4955
default: ''
56+
},
57+
layout: {
58+
type: String as PropType<string>,
59+
default: 'Classic'
5060
}
5161
},
5262
setup(props) {

src/components/Sider/index.vue

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<template>
2-
<div :class="{'has-logo': showLogo}" class="sidebar-container">
2+
<div
3+
:class="{'has-logo': showLogo && layout === 'Classic', 'sidebar-container--Top': layout === 'Top'}"
4+
class="sidebar-container"
5+
>
36
<el-scrollbar>
47
<el-menu
58
:default-active="activeMenu"
69
:collapse="collapsed"
710
:unique-opened="false"
8-
mode="vertical"
11+
:mode="mode"
912
@select="selectMenu"
1013
>
1114
<sider-item
1215
v-for="route in routers"
1316
:key="route.path"
1417
:item="route"
18+
:layout="layout"
1519
:base-path="route.path"
1620
/>
1721
</el-menu>
@@ -20,17 +24,28 @@
2024
</template>
2125

2226
<script lang="ts">
23-
import { defineComponent, computed } from 'vue'
27+
import { defineComponent, computed, PropType } from 'vue'
2428
import { useRouter } from 'vue-router'
2529
import { permissionStore } from '_p/index/store/modules/permission'
2630
import { appStore } from '_p/index/store/modules/app'
27-
import type { RouteRecordRaw, RouteLocationNormalizedLoaded } from 'vue-router'
31+
import type { RouteRecordRaw } from 'vue-router'
2832
import SiderItem from './SiderItem.vue'
2933
import variables from '@/styles/variables.less'
3034
import { isExternal } from '@/utils/validate'
3135
3236
export default defineComponent({
37+
name: 'Sider',
3338
components: { SiderItem },
39+
props: {
40+
layout: {
41+
type: String as PropType<string>,
42+
default: 'Classic'
43+
},
44+
mode: {
45+
type: String as PropType<'horizontal' | 'vertical'>,
46+
default: 'vertical'
47+
}
48+
},
3449
setup() {
3550
const { currentRoute, push } = useRouter()
3651
const routers = computed((): RouteRecordRaw[] => {
@@ -73,19 +88,38 @@ export default defineComponent({
7388
@{deep}(.svg-icon) {
7489
margin-right: 16px;
7590
}
91+
@{deep}(.el-scrollbar) {
92+
width: 100%;
93+
height: 100%;
94+
.el-scrollbar__wrap {
95+
overflow: scroll;
96+
overflow-x: hidden;
97+
.el-menu {
98+
width: 100%;
99+
border: none;
100+
}
101+
}
102+
}
76103
}
77104
.has-logo {
78-
height: calc(~"100% - @{topSilderHeight}");
105+
height: calc(~"100% - @{topSiderHeight}");
79106
}
80-
@{deep}(.el-scrollbar) {
81-
width: 100%;
82-
height: 100%;
83-
.el-scrollbar__wrap {
84-
overflow: scroll;
85-
overflow-x: hidden;
86-
.el-menu {
87-
width: 100%;
88-
border: none;
107+
108+
.sidebar-container--Top {
109+
@{deep}(.el-scrollbar) {
110+
width: 100%;
111+
height: 100%;
112+
.el-scrollbar__wrap {
113+
overflow: scroll;
114+
overflow-x: hidden;
115+
.el-scrollbar__view {
116+
height: @topSiderHeight;
117+
}
118+
.el-menu {
119+
width: auto;
120+
height: 100%;
121+
border: none;
122+
}
89123
}
90124
}
91125
}

0 commit comments

Comments
 (0)