Skip to content

Commit 7efa409

Browse files
committed
fixed: menu 3 children selected
1 parent f9e96ce commit 7efa409

File tree

5 files changed

+100
-25
lines changed

5 files changed

+100
-25
lines changed

src/components/menu/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ export default {
122122
},
123123
updateMenu () {
124124
let routes = this.$route.matched.concat()
125-
this.selectedKeys = [ routes.pop().path ]
125+
if (routes.length >= 3 && this.$route.meta.hidden) {
126+
routes.pop()
127+
this.selectedKeys = [ routes[1].path ]
128+
} else {
129+
this.selectedKeys = [ routes.pop().path ]
130+
}
126131
let openKeys = []
127132
routes.forEach((item) => {
128133
openKeys.push(item.path)

src/router/index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,42 +244,51 @@ export const asyncRouterMap = [
244244
path: '/account',
245245
component: Layout,
246246
name: 'account',
247-
meta: { title: '个人页', icon: 'user' },
247+
meta: { title: '个人页', icon: 'user', keepAlive: true },
248248
children: [
249249
{
250-
path: 'center',
250+
path: '/account/center',
251251
name: 'center',
252252
component: () => import('@/views/account/Index'),
253-
meta: { title: '个人中心' }
253+
meta: { title: '个人中心', keepAlive: true }
254254
},
255255
{
256-
path: 'settings',
256+
path: '/account/settings',
257257
name: 'settings',
258258
component: () => import('@/views/account/Index'),
259-
meta: { title: '个人设置', hideHeader: true },
259+
meta: { title: '个人设置', hideHeader: true, keepAlive: true },
260260
redirect: '/account/settings/base',
261261
alwaysShow: true,
262262
children: [
263263
{
264-
path: 'base',
264+
path: '/account/settings/base',
265265
name: 'BaseSettings',
266266
component: () => import('@/views/account/BaseSetting'),
267-
hidden: true,
268-
meta: { title: '基本设置' }
267+
meta: { title: '基本设置', hidden: true, keepAlive: true }
269268
},
270269
{
271-
path: 'security',
270+
path: '/account/settings/security',
272271
name: 'SecuritySettings',
273272
component: () => import('@/views/account/Security'),
274-
hidden: true,
275-
meta: { title: '安全设置' }
273+
meta: { title: '安全设置', hidden: true, keepAlive: true }
276274
},
277275
{
278-
path: 'custom',
276+
path: '/account/settings/custom',
279277
name: 'CustomSettings',
280278
component: () => import('@/views/account/Custom'),
281-
hidden: true,
282-
meta: { title: '个性化设置' }
279+
meta: { title: '个性化设置', hidden: true, keepAlive: true }
280+
},
281+
{
282+
path: '/account/settings/binding',
283+
name: 'BindingSettings',
284+
component: () => import('@/views/account/Binding'),
285+
meta: { title: '账户绑定', hidden: true, keepAlive: true }
286+
},
287+
{
288+
path: '/account/settings/notification',
289+
name: 'NotificationSettings',
290+
component: () => import('@/views/account/Notification'),
291+
meta: { title: '新消息通知', hidden: true, keepAlive: true }
283292
},
284293
]
285294
},

src/views/account/Binding.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<a-list
3+
itemLayout="horizontal"
4+
:dataSource="data"
5+
>
6+
7+
</a-list>
8+
</template>
9+
10+
<script>
11+
export default {
12+
data () {
13+
return {
14+
15+
}
16+
},
17+
methods: {
18+
19+
}
20+
}
21+
</script>
22+
23+
<style scoped>
24+
25+
</style>

src/views/account/Index.vue

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
<template>
2-
<a-card :bordered="false" :bodyStyle="{ padding: '16px 0' }">
2+
<a-card :bordered="false" :bodyStyle="{ padding: '16px 0', height: '100%' }" :style="{ height: '100%' }">
33
<div class="account-settings-info-main">
44
<div class="account-settings-info-left">
55
<a-menu
66
mode="inline"
7-
:defaultSelectedKeys="['1']"
7+
:style="{ border: '0' }"
8+
:defaultSelectedKeys="defaultSelectedKeys"
89
type="inner"
910
@openChange="onOpenChange"
1011
>
11-
<a-menu-item key="1">
12+
<a-menu-item key="/account/settings/base">
1213
<router-link :to="{ name: 'BaseSettings' }">
1314
基本设置
1415
</router-link>
1516
</a-menu-item>
16-
<a-menu-item key="2">
17+
<a-menu-item key="/account/settings/security">
1718
<router-link :to="{ name: 'SecuritySettings' }">
1819
安全设置
1920
</router-link>
2021
</a-menu-item>
21-
<a-menu-item key="3">
22+
<a-menu-item key="/account/settings/custom">
2223
<router-link :to="{ name: 'CustomSettings' }">
2324
个性化
2425
</router-link>
2526
</a-menu-item>
26-
<a-menu-item key="4">
27-
账户绑定
27+
<a-menu-item key="/account/settings/binding">
28+
<router-link :to="{ name: 'BindingSettings' }">
29+
账户绑定
30+
</router-link>
2831
</a-menu-item>
29-
<a-menu-item key="5">
30-
新消息通知
32+
<a-menu-item key="/account/settings/notification">
33+
<router-link :to="{ name: 'NotificationSettings' }">
34+
新消息通知
35+
</router-link>
3136
</a-menu-item>
3237
</a-menu>
3338
</div>
@@ -52,6 +57,8 @@
5257
},
5358
data () {
5459
return {
60+
defaultSelectedKeys: [],
61+
5562
// cropper
5663
preview: {},
5764
option: {
@@ -74,12 +81,16 @@
7481
}
7582
},
7683
created () {
77-
84+
this.updateMenu()
7885
},
7986
methods: {
8087
onOpenChange (openKeys) {
8188
8289
},
90+
updateMenu () {
91+
let routes = this.$route.matched.concat()
92+
this.defaultSelectedKeys = [ routes.pop().path ]
93+
}
8394
},
8495
}
8596
</script>

src/views/account/Notification.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<a-list
3+
itemLayout="horizontal"
4+
:dataSource="data"
5+
>
6+
7+
</a-list>
8+
</template>
9+
10+
<script>
11+
export default {
12+
data () {
13+
return {
14+
15+
}
16+
},
17+
methods: {
18+
19+
}
20+
}
21+
</script>
22+
23+
<style scoped>
24+
25+
</style>

0 commit comments

Comments
 (0)