Skip to content

Commit f272a7e

Browse files
author
sheepzh
committed
Fix sidebar bgcolor (#208)
1 parent 76287ba commit f272a7e

File tree

5 files changed

+53
-55
lines changed

5 files changed

+53
-55
lines changed

src/api/chrome/tab.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export function createTab(param: chrome.tabs.CreateProperties | string): Promise
3636
*/
3737
export async function createTabAfterCurrent(url: string): Promise<ChromeTab> {
3838
const tab = await getCurrentTab()
39-
console.log(tab)
4039
if (!tab) {
4140
// Current tab not found
4241
return createTab(url)

src/app/components/common/content-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* Copyright (c) 2021 Hengyang Zhang
2+
* Copyright (c) 2021-present Hengyang Zhang
33
*
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { ElCard } from "element-plus"
8+
import { ElCard, ElScrollbar } from "element-plus"
99
import ContentCard from "./content-card"
1010
import { defineComponent, h, useSlots } from "vue"
1111

@@ -19,7 +19,7 @@ const _default = defineComponent(() => {
1919
} else {
2020
content && children.push(h(ContentCard, () => h(content)))
2121
}
22-
return () => h("div", { class: "content-container" }, children)
22+
return () => h(ElScrollbar, () => h("div", { class: "content-container" }, children))
2323
})
2424

2525
export default _default

src/app/layout/index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
/**
2-
* Copyright (c) 2021 Hengyang Zhang
2+
* Copyright (c) 2021-present Hengyang Zhang
33
*
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { ElAside, ElContainer } from "element-plus"
8+
import { ElAside, ElContainer, ElScrollbar } from "element-plus"
99
import { defineComponent, h } from "vue"
1010
import Menu from "./menu"
1111
import VersionTag from "./version-tag"
1212
import { RouterView } from "vue-router"
1313

14-
const _default = defineComponent({
15-
name: "Layout",
16-
render() {
17-
return h(ElContainer, {}, () => [
18-
h(ElAside, { width: `270px` }, () => h(Menu)),
19-
h(ElContainer, { class: 'app-container' }, () => h(RouterView)),
20-
h(VersionTag)
21-
])
22-
}
14+
const _default = defineComponent(() => {
15+
return () => h(ElContainer, {}, () => [
16+
h(ElAside, () => h(ElScrollbar, () => h(Menu))),
17+
h(ElContainer, { class: 'app-container' }, () => h(RouterView)),
18+
h(VersionTag)
19+
])
2320
})
2421

2522
export default _default

src/app/layout/menu.ts

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import type { UnwrapRef } from "vue"
8+
import type { Ref } from "vue"
99
import type ElementIcon from "@src/element-ui/icon"
1010
import type { MenuItemRegistered } from "element-plus"
11-
import type { RouteLocationNormalizedLoaded, Router } from "vue-router"
11+
import type { Router } from "vue-router"
1212
import type { I18nKey } from "@app/locale"
1313
import type { MenuMessage } from "@i18n/message/app/menu"
1414

15-
import { defineComponent, h, onMounted, reactive } from "vue"
15+
import { defineComponent, h, onMounted, ref, watch } from "vue"
1616
import { ElIcon, ElMenu, ElMenuItem, ElMenuItemGroup } from "element-plus"
17-
import { useRoute, useRouter } from "vue-router"
17+
import { useRouter } from "vue-router"
1818
import { t } from "@app/locale"
1919
import { HOME_PAGE, FEEDBACK_QUESTIONNAIRE, getGuidePageUrl } from "@util/constant/url"
2020
import { Aim, Calendar, ChatSquare, Folder, HelpFilled, HotWater, Memo, Rank, SetUp, Stopwatch, Sugar, Tickets, Timer } from "@element-plus/icons-vue"
2121
import { locale } from "@i18n"
2222
import TrendIcon from "./icon/trend-icon"
23-
import { createTab } from "@api/chrome/tab"
23+
import { createTabAfterCurrent } from "@api/chrome/tab"
2424
import { ANALYSIS_ROUTE, MERGE_ROUTE } from "@app/router/constants"
2525
import { START_ROUTE } from "@guide/router/constants"
2626

@@ -37,11 +37,6 @@ type _MenuGroup = {
3737
children: _MenuItem[]
3838
}
3939

40-
type _RouteProps = {
41-
router: Router
42-
current: RouteLocationNormalizedLoaded
43-
}
44-
4540
/**
4641
* Generate menu items after locale initialized
4742
*/
@@ -126,23 +121,24 @@ function generateMenus(): _MenuGroup[] {
126121
}]
127122
}
128123

129-
function openMenu(route: string, title: I18nKey, routeProps: UnwrapRef<_RouteProps>) {
130-
const routerVal = routeProps.router
131-
const currentRouteVal = routeProps.current
132-
if (currentRouteVal && currentRouteVal.path !== route) {
133-
routerVal && routerVal.push(route)
124+
function openMenu(route: string, title: I18nKey, router: Router) {
125+
const currentPath = router.currentRoute.value?.path
126+
if (currentPath !== route) {
127+
router?.push(route)
134128
document.title = t(title)
135129
}
136130
}
137131

138-
const openHref = (href: string) => createTab(href)
132+
const openHref = (href: string) => createTabAfterCurrent(href)
139133

140-
function handleClick(menuItem: _MenuItem, routeProps: UnwrapRef<_RouteProps>) {
134+
function handleClick(menuItem: _MenuItem, router: Router, currentActive: Ref<string>) {
141135
const { route, title, href } = menuItem
142136
if (route) {
143-
openMenu(route, msg => msg.menu[title], routeProps)
137+
openMenu(route, msg => msg.menu[title], router)
138+
currentActive.value = '/data/dashboard'//route
144139
} else {
145140
openHref(href)
141+
currentActive.value = router.currentRoute?.value?.path
146142
}
147143
}
148144

@@ -153,10 +149,10 @@ const iconStyle: Partial<CSSStyleDeclaration> = {
153149
lineHeight: '0.83em'
154150
}
155151

156-
function renderMenuLeaf(menu: _MenuItem, routeProps: UnwrapRef<_RouteProps>) {
152+
function renderMenuLeaf(menu: _MenuItem, router: Router, currentActive: Ref<string>) {
157153
const { route, title, icon, index } = menu
158154
const props: { onClick: (item: MenuItemRegistered) => void; index?: string } = {
159-
onClick: (_item) => handleClick(menu, routeProps)
155+
onClick: (_item) => handleClick(menu, router, currentActive)
160156
}
161157
const realIndex = index || route
162158
realIndex && (props.index = realIndex)
@@ -166,9 +162,9 @@ function renderMenuLeaf(menu: _MenuItem, routeProps: UnwrapRef<_RouteProps>) {
166162
})
167163
}
168164

169-
function renderMenu(menu: _MenuGroup, props: UnwrapRef<_RouteProps>) {
165+
function renderMenu(menu: _MenuGroup, router: Router, currentActive: Ref<string>) {
170166
const title = t(msg => msg.menu[menu.title])
171-
return h(ElMenuItemGroup, { title }, () => menu.children.map(item => renderMenuLeaf(item, props)))
167+
return h(ElMenuItemGroup, { title }, () => menu.children.map(item => renderMenuLeaf(item, router, currentActive)))
172168
}
173169

174170
async function initTitle(allMenus: _MenuGroup[], router: Router) {
@@ -185,22 +181,22 @@ async function initTitle(allMenus: _MenuGroup[], router: Router) {
185181
}
186182
}
187183

188-
const _default = defineComponent({
189-
name: "LayoutMenu",
190-
setup() {
191-
const routeProps: UnwrapRef<_RouteProps> = reactive({
192-
router: useRouter(),
193-
current: useRoute()
194-
})
195-
196-
const allMenus = generateMenus()
197-
onMounted(() => initTitle(allMenus, useRouter()))
198-
199-
return () => h(ElMenu,
200-
{ defaultActive: routeProps.current.path },
201-
() => allMenus.map(menu => renderMenu(menu, routeProps))
202-
)
184+
const _default = defineComponent(() => {
185+
const router = useRouter()
186+
const currentActive: Ref<string> = ref()
187+
const syncRouter = () => {
188+
const route = router.currentRoute.value
189+
route && (currentActive.value = route.path)
203190
}
191+
192+
watch(router.currentRoute, syncRouter)
193+
194+
const allMenus = generateMenus()
195+
onMounted(() => initTitle(allMenus, router))
196+
197+
return () => h('div', { class: 'menu-container' }, h(ElMenu, { defaultActive: currentActive.value },
198+
() => allMenus.map(menu => renderMenu(menu, router, currentActive))
199+
))
204200
})
205201

206202
export default _default

src/app/styles/index.sass

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 Hengyang Zhang
2+
* Copyright (c) 2021-present Hengyang Zhang
33
*
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
@@ -33,6 +33,11 @@ a
3333
padding-left: 45px !important
3434
.el-aside
3535
width: 240px
36+
.el-menu
37+
padding-bottom: 10px
38+
.menu-container
39+
min-height: 100vh
40+
background-color: var(--el-menu-bg-color)
3641

3742
.app-container
3843
width: 100%
@@ -41,10 +46,11 @@ a
4146

4247
.content-container
4348
margin-top: 30px
44-
width: calc(100% - 60px)
49+
margin-bottom: 30px
50+
width: calc(100vw - 300px)
4551
height: calc(100% - 30px)
4652
padding: 0 30px
47-
overflow-y: auto
53+
overflow: hidden
4854

4955
#app
5056
height: 100%

0 commit comments

Comments
 (0)