Skip to content

Commit 86c292f

Browse files
陈鑫陈鑫
authored andcommitted
路由导航ok
1 parent b0b4d1a commit 86c292f

File tree

9 files changed

+131
-7
lines changed

9 files changed

+131
-7
lines changed

src/components/GlobalHeader/Menus.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ const Menus = defineComponent({
1414
},
1515
setup(props, { slots }) {
1616
const route = useRoute()
17+
const router = useRouter()
1718
const activeRoute = ref(route.path) // 当前路由
1819

20+
// 默认展开项
1921
const openKeys = computed(() => {
2022
if (props.mode == 'inline') {
2123
return ['/smart', '/eoms', '/system', '/database']
2224
}
2325
return []
24-
}) // 默认展开项
26+
})
2527

28+
// 获取显示状态的路由
2629
const menuLists = computed(() => {
2730
return getMenus().filter((item) => !item?.meta?.hidden)
28-
}) // 获取显示状态的路由
31+
})
2932

33+
// 获取路由列表
3034
const getMenus = () => {
3135
let menuList: RouteRecordRaw[] = []
3236
const routes: Array<RouteRecordRaw> = useRouter().options?.routes || []
@@ -36,11 +40,50 @@ const Menus = defineComponent({
3640
}
3741
})
3842
return menuList
39-
} // 获取路由列表
43+
}
4044

45+
// 路由跳转
46+
const handleMenuClick = (item: { key: string }) => {
47+
router.push(item.key)
48+
}
49+
50+
// 监听路由变化
4151
watch(route, (val) => {
4252
activeRoute.value = val.path
43-
}) // 监听路由变化
53+
})
54+
55+
// 子级导航渲染
56+
const SubItem = (menus: any) => {
57+
return (
58+
<Menu.SubMenu key={menus.path}>
59+
{{
60+
title: () => (
61+
<>
62+
{menus.meta?.icon && (
63+
<span class={`iconfont ${menus.meta.icon} menu-icon`}></span>
64+
)}
65+
<span>{menus.meta?.title}</span>
66+
</>
67+
),
68+
default: () => (
69+
<>
70+
{menus.children.map((menu: any) => {
71+
if (!menu.children || !menu.children.length) {
72+
return (
73+
<Menu.Item key={menu.path}>
74+
<span>{menu.meta?.title}</span>
75+
</Menu.Item>
76+
)
77+
} else {
78+
return SubItem(menu)
79+
}
80+
})}
81+
</>
82+
),
83+
}}
84+
</Menu.SubMenu>
85+
)
86+
}
4487

4588
return () => (
4689
<div
@@ -50,7 +93,9 @@ const Menus = defineComponent({
5093
theme="dark"
5194
selectedKeys={[activeRoute.value]}
5295
openKeys={openKeys.value}
96+
mode={props.mode}
5397
style={{ lineHeight: '54px' }}
98+
onClick={handleMenuClick}
5499
>
55100
{menuLists['value'].map((menu) => {
56101
if (!menu.children || !menu.children.length) {
@@ -62,6 +107,8 @@ const Menus = defineComponent({
62107
<span>{menu.meta?.title}</span>
63108
</Menu.Item>
64109
)
110+
} else {
111+
return SubItem(menu)
65112
}
66113
})}
67114
</Menu>

src/components/GlobalHeader/index.module.less

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,34 @@
7676
font-size: 15px;
7777
border-bottom: none;
7878
top: 0;
79+
&:hover {
80+
background-color: rgba(255, 255, 255, 0);
81+
}
7982
&-active {
8083
color: rgba(255, 255, 255, 0.9);
84+
background-color: rgba(255, 255, 255, 0.7);
8185
}
8286
&-selected {
83-
background: #4a4b4c;
87+
background-color: #4a4b4c !important;
8488
position: relative;
8589
font-weight: 700;
8690
color: rgba(255, 255, 255, 0.9);
8791
border-bottom: none;
92+
margin: 0;
93+
height: 55px;
94+
line-height: 55px;
8895
&::after {
8996
content: '';
9097
position: absolute;
9198
bottom: 0;
92-
height: 3px;
99+
height: 4px;
93100
width: 100%;
94101
background: #0972fe;
95102
left: 0;
103+
z-index: 111;
104+
opacity: 1;
105+
transform: scaleY(1);
106+
top: auto;
96107
}
97108
}
98109
}

src/router/router.config.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RouteRecordRaw } from 'vue-router'
2-
import { LevelBasicLayout } from '@/layouts';
2+
import { LevelBasicLayout, RouteLayout } from '@/layouts';
33

44
// 导航路由
55
const Routes: Array<RouteRecordRaw> = [
@@ -14,6 +14,32 @@ const Routes: Array<RouteRecordRaw> = [
1414
name: 'database',
1515
component: () => import(/* webpackChunkName: "database" */ '@/views/database'),
1616
meta: { title: '数据库配置', hidden: false, icon: 'icon-zichan' }
17+
},
18+
{
19+
path: '/smart',
20+
name: 'smart',
21+
component: () => import(/* webpackChunkName: "smart" */ '@/views/smart'),
22+
meta: { title: '物联管理', hidden: false, icon: 'icon-wulianwang' }
23+
},
24+
{
25+
path: '/eoms',
26+
name: 'eoms',
27+
component: RouteLayout,
28+
meta: { title: '运维配置', hidden: false, icon: 'icon-yunwei1' },
29+
children: [
30+
{
31+
path: "/eoms/fault",
32+
name: 'fault',
33+
component: () => import(/* webpackChunkName: "fault" */ '@/views/eoms/fault'),
34+
meta: { title: '故障处理方案', hidden: false },
35+
},
36+
{
37+
path: "/eoms/alarm",
38+
name: 'alarm',
39+
component: () => import(/* webpackChunkName: "alarm" */ '@/views/eoms/alarm'),
40+
meta: { title: '告警模板管理', hidden: false }
41+
}
42+
]
1743
}
1844
]
1945

src/views/eoms/alarm/index.module.less

Whitespace-only changes.

src/views/eoms/alarm/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineComponent } from 'vue'
2+
3+
import styles from './index.module.less'
4+
5+
const Alarm = defineComponent({
6+
name: 'Alarm',
7+
setup() {
8+
return () => <div>这是内容区</div>
9+
},
10+
})
11+
12+
export default Alarm

src/views/eoms/fault/index.module.less

Whitespace-only changes.

src/views/eoms/fault/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineComponent } from 'vue'
2+
3+
import styles from './index.module.less'
4+
5+
const Fault = defineComponent({
6+
name: 'Fault',
7+
setup() {
8+
return () => <div>这是内容区</div>
9+
},
10+
})
11+
12+
export default Fault

src/views/smart/index.module.less

Whitespace-only changes.

src/views/smart/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineComponent } from 'vue'
2+
import { RouteLayout } from '@/layouts'
3+
4+
import styles from './index.module.less'
5+
6+
const Smart = defineComponent({
7+
name: 'Smart',
8+
setup() {
9+
const slots = {
10+
default: () => <div>这是内容区</div>,
11+
}
12+
return () => <RouteLayout v-slots={slots} isSubView={false}></RouteLayout>
13+
},
14+
})
15+
16+
export default Smart

0 commit comments

Comments
 (0)