@@ -26,120 +26,105 @@ export default {
26
26
default : false
27
27
}
28
28
} ,
29
- data ( ) {
29
+ data ( ) {
30
30
return {
31
31
openKeys : [ ] ,
32
32
selectedKeys : [ ] ,
33
33
cachedOpenKeys : [ ]
34
34
}
35
35
} ,
36
36
computed : {
37
- rootSubmenuKeys : ( vm ) => {
37
+ rootSubmenuKeys : vm => {
38
38
const keys = [ ]
39
39
vm . menu . forEach ( item => keys . push ( item . path ) )
40
40
return keys
41
41
}
42
42
} ,
43
- created ( ) {
43
+ created ( ) {
44
44
this . updateMenu ( )
45
45
} ,
46
46
watch : {
47
- collapsed ( val ) {
47
+ collapsed ( val ) {
48
48
if ( val ) {
49
49
this . cachedOpenKeys = this . openKeys
50
50
this . openKeys = [ ]
51
51
} else {
52
52
this . openKeys = this . cachedOpenKeys
53
53
}
54
54
} ,
55
- ' $route' : function ( ) {
55
+ $route : function ( ) {
56
56
this . updateMenu ( )
57
57
}
58
58
} ,
59
59
methods : {
60
- renderIcon : function ( h , icon ) {
61
- return icon === 'none' || icon === undefined ? null
62
- : h ( Icon , { props : { type : icon !== undefined ? icon : '' } } )
60
+ renderIcon : function ( h , icon ) {
61
+ return icon === 'none' || icon === undefined ? null : h ( Icon , { props : { type : icon !== undefined ? icon : '' } } )
63
62
} ,
64
- renderMenuItem : function ( h , menu , pIndex , index ) {
65
- return h ( Item , { key : menu . path ? menu . path : 'item_' + pIndex + '_' + index } ,
66
- [
67
- h (
68
- 'router-link' ,
69
- { attrs : { to : { name : menu . name } } } ,
70
- [
71
- this . renderIcon ( h , menu . meta . icon ) ,
72
- h ( 'span' , [ menu . meta . title ] )
73
- ]
74
- )
75
- ]
76
- )
63
+ renderMenuItem : function ( h , menu , pIndex , index ) {
64
+ return h ( Item , { key : menu . path ? menu . path : 'item_' + pIndex + '_' + index } , [
65
+ h ( 'router-link' , { attrs : { to : { name : menu . name } } } , [
66
+ this . renderIcon ( h , menu . meta . icon ) ,
67
+ h ( 'span' , [ menu . meta . title ] )
68
+ ] )
69
+ ] )
77
70
} ,
78
- renderSubMenu : function ( h , menu , pIndex , index ) {
71
+ renderSubMenu : function ( h , menu , pIndex , index ) {
79
72
const this2_ = this
80
- const subItem = [ h ( 'span' ,
81
- { slot : 'title' } ,
82
- [
83
- this . renderIcon ( h , menu . meta . icon ) ,
84
- h ( 'span' , [ menu . meta . title ] )
85
- ]
86
- ) ]
73
+ const subItem = [ h ( 'span' , { slot : 'title' } , [ this . renderIcon ( h , menu . meta . icon ) , h ( 'span' , [ menu . meta . title ] ) ] ) ]
87
74
const itemArr = [ ]
88
75
const pIndex_ = pIndex + '_' + index
89
76
if ( ! menu . alwaysShow ) {
90
- menu . children . forEach ( function ( item , i ) {
77
+ menu . children . forEach ( function ( item , i ) {
91
78
itemArr . push ( this2_ . renderItem ( h , item , pIndex_ , i ) )
92
79
} )
93
80
}
94
- return h (
95
- SubMenu ,
96
- { key : menu . path ? menu . path : 'submenu_' + pIndex + '_' + index } ,
97
- subItem . concat ( itemArr )
98
- )
81
+ return h ( SubMenu , { key : menu . path ? menu . path : 'submenu_' + pIndex + '_' + index } , subItem . concat ( itemArr ) )
99
82
} ,
100
- renderItem : function ( h , menu , pIndex , index ) {
83
+ renderItem : function ( h , menu , pIndex , index ) {
101
84
if ( ! menu . hidden ) {
102
- return menu . children && ! menu . alwaysShow ? this . renderSubMenu ( h , menu , pIndex , index ) : this . renderMenuItem ( h , menu , pIndex , index )
85
+ return menu . children && ! menu . alwaysShow
86
+ ? this . renderSubMenu ( h , menu , pIndex , index )
87
+ : this . renderMenuItem ( h , menu , pIndex , index )
103
88
}
104
89
} ,
105
- renderMenu : function ( h , menuTree ) {
90
+ renderMenu : function ( h , menuTree ) {
106
91
const this2_ = this
107
92
const menuArr = [ ]
108
- menuTree . forEach ( function ( menu , i ) {
93
+ menuTree . forEach ( function ( menu , i ) {
109
94
if ( ! menu . hidden ) {
110
95
menuArr . push ( this2_ . renderItem ( h , menu , '0' , i ) )
111
96
}
112
97
} )
113
98
return menuArr
114
99
} ,
115
- onOpenChange ( openKeys ) {
116
- const latestOpenKey = openKeys . find ( key => this . openKeys . indexOf ( key ) === - 1 )
117
- if ( this . rootSubmenuKeys . indexOf ( latestOpenKey ) === - 1 ) {
100
+ onOpenChange ( openKeys ) {
101
+ const latestOpenKey = openKeys . find ( key => ! this . openKeys . includes ( key ) )
102
+ if ( ! this . rootSubmenuKeys . includes ( latestOpenKey ) ) {
118
103
this . openKeys = openKeys
119
104
} else {
120
- this . openKeys = latestOpenKey ? [ latestOpenKey ] : [ ]
105
+ this . openKeys = latestOpenKey ? [ latestOpenKey ] : [ ]
121
106
}
122
107
} ,
123
- updateMenu ( ) {
108
+ updateMenu ( ) {
124
109
const routes = this . $route . matched . concat ( )
125
110
if ( routes . length >= 4 && this . $route . meta . hidden ) {
126
111
routes . pop ( )
127
- this . selectedKeys = [ routes [ 2 ] . path ]
112
+ this . selectedKeys = [ routes [ 2 ] . path ]
128
113
} else {
129
- this . selectedKeys = [ routes . pop ( ) . path ]
114
+ this . selectedKeys = [ routes . pop ( ) . path ]
130
115
}
131
116
132
117
const openKeys = [ ]
133
118
if ( this . mode === 'inline' ) {
134
- routes . forEach ( ( item ) => {
119
+ routes . forEach ( item => {
135
120
openKeys . push ( item . path )
136
121
} )
137
122
}
138
123
139
- this . collapsed ? this . cachedOpenKeys = openKeys : this . openKeys = openKeys
124
+ this . collapsed ? ( this . cachedOpenKeys = openKeys ) : ( this . openKeys = openKeys )
140
125
}
141
126
} ,
142
- render ( h ) {
127
+ render ( h ) {
143
128
return h (
144
129
Menu ,
145
130
{
@@ -151,12 +136,13 @@ export default {
151
136
} ,
152
137
on : {
153
138
openChange : this . onOpenChange ,
154
- select : ( obj ) => {
139
+ select : obj => {
155
140
this . selectedKeys = obj . selectedKeys
156
141
this . $emit ( 'select' , obj )
157
142
}
158
143
}
159
- } , this . renderMenu ( h , this . menu )
144
+ } ,
145
+ this . renderMenu ( h , this . menu )
160
146
)
161
147
}
162
- }
148
+ }
0 commit comments