Skip to content

Commit 55d26ac

Browse files
committed
update indexOf rewrite to includes
1 parent 0b6fbe6 commit 55d26ac

File tree

3 files changed

+223
-233
lines changed

3 files changed

+223
-233
lines changed

β€Žsrc/components/menu/index.js

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,120 +26,105 @@ export default {
2626
default: false
2727
}
2828
},
29-
data () {
29+
data() {
3030
return {
3131
openKeys: [],
3232
selectedKeys: [],
3333
cachedOpenKeys: []
3434
}
3535
},
3636
computed: {
37-
rootSubmenuKeys: (vm) => {
37+
rootSubmenuKeys: vm => {
3838
const keys = []
3939
vm.menu.forEach(item => keys.push(item.path))
4040
return keys
4141
}
4242
},
43-
created () {
43+
created() {
4444
this.updateMenu()
4545
},
4646
watch: {
47-
collapsed (val) {
47+
collapsed(val) {
4848
if (val) {
4949
this.cachedOpenKeys = this.openKeys
5050
this.openKeys = []
5151
} else {
5252
this.openKeys = this.cachedOpenKeys
5353
}
5454
},
55-
'$route': function () {
55+
$route: function() {
5656
this.updateMenu()
5757
}
5858
},
5959
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 : '' } })
6362
},
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+
])
7770
},
78-
renderSubMenu: function (h, menu, pIndex, index) {
71+
renderSubMenu: function(h, menu, pIndex, index) {
7972
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])])]
8774
const itemArr = []
8875
const pIndex_ = pIndex + '_' + index
8976
if (!menu.alwaysShow) {
90-
menu.children.forEach(function (item, i) {
77+
menu.children.forEach(function(item, i) {
9178
itemArr.push(this2_.renderItem(h, item, pIndex_, i))
9279
})
9380
}
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))
9982
},
100-
renderItem: function (h, menu, pIndex, index) {
83+
renderItem: function(h, menu, pIndex, index) {
10184
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)
10388
}
10489
},
105-
renderMenu: function (h, menuTree) {
90+
renderMenu: function(h, menuTree) {
10691
const this2_ = this
10792
const menuArr = []
108-
menuTree.forEach(function (menu, i) {
93+
menuTree.forEach(function(menu, i) {
10994
if (!menu.hidden) {
11095
menuArr.push(this2_.renderItem(h, menu, '0', i))
11196
}
11297
})
11398
return menuArr
11499
},
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)) {
118103
this.openKeys = openKeys
119104
} else {
120-
this.openKeys = latestOpenKey ? [ latestOpenKey ] : []
105+
this.openKeys = latestOpenKey ? [latestOpenKey] : []
121106
}
122107
},
123-
updateMenu () {
108+
updateMenu() {
124109
const routes = this.$route.matched.concat()
125110
if (routes.length >= 4 && this.$route.meta.hidden) {
126111
routes.pop()
127-
this.selectedKeys = [ routes[2].path ]
112+
this.selectedKeys = [routes[2].path]
128113
} else {
129-
this.selectedKeys = [ routes.pop().path ]
114+
this.selectedKeys = [routes.pop().path]
130115
}
131116

132117
const openKeys = []
133118
if (this.mode === 'inline') {
134-
routes.forEach((item) => {
119+
routes.forEach(item => {
135120
openKeys.push(item.path)
136121
})
137122
}
138123

139-
this.collapsed ? this.cachedOpenKeys = openKeys : this.openKeys = openKeys
124+
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
140125
}
141126
},
142-
render (h) {
127+
render(h) {
143128
return h(
144129
Menu,
145130
{
@@ -151,12 +136,13 @@ export default {
151136
},
152137
on: {
153138
openChange: this.onOpenChange,
154-
select: (obj) => {
139+
select: obj => {
155140
this.selectedKeys = obj.selectedKeys
156141
this.$emit('select', obj)
157142
}
158143
}
159-
}, this.renderMenu(h, this.menu)
144+
},
145+
this.renderMenu(h, this.menu)
160146
)
161147
}
162-
}
148+
}

β€Žsrc/store/modules/permission.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { asyncRouterMap, constantRouterMap } from '@/config/router.config'
99
*/
1010
function hasPermission(permission, route) {
1111
if (route.meta && route.meta.permission) {
12-
let flag = -1
12+
let flag = false
1313
for (let i = 0, len = permission.length; i < len; i++) {
14-
flag = route.meta.permission.indexOf(permission[i])
15-
if (flag >= 0) {
14+
flag = route.meta.permission.includes(permission[i])
15+
if (flag) {
1616
return true
1717
}
1818
}
@@ -31,7 +31,7 @@ function hasPermission(permission, route) {
3131
// eslint-disable-next-line
3232
function hasRole(roles, route) {
3333
if (route.meta && route.meta.roles) {
34-
return route.meta.roles.indexOf(roles.id)
34+
return route.meta.roles.includes(roles.id)
3535
} else {
3636
return true
3737
}
@@ -73,4 +73,4 @@ const permission = {
7373
}
7474
}
7575

76-
export default permission
76+
export default permission

0 commit comments

Comments
Β (0)