Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ant-design-pro-vue
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tianzhuanghu
ant-design-pro-vue
Commits
55d26ac5
Commit
55d26ac5
authored
Dec 15, 2018
by
musnow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update indexOf rewrite to includes
parent
0b6fbe66
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
59 deletions
+43
-59
index.js
src/components/menu/index.js
+38
-53
permission.js
src/store/modules/permission.js
+5
-6
Index.vue
src/views/account/center/Index.vue
+0
-0
No files found.
src/components/menu/index.js
View file @
55d26ac5
...
...
@@ -26,7 +26,7 @@ export default {
default
:
false
}
},
data
()
{
data
()
{
return
{
openKeys
:
[],
selectedKeys
:
[],
...
...
@@ -34,17 +34,17 @@ export default {
}
},
computed
:
{
rootSubmenuKeys
:
(
vm
)
=>
{
rootSubmenuKeys
:
vm
=>
{
const
keys
=
[]
vm
.
menu
.
forEach
(
item
=>
keys
.
push
(
item
.
path
))
return
keys
}
},
created
()
{
created
()
{
this
.
updateMenu
()
},
watch
:
{
collapsed
(
val
)
{
collapsed
(
val
)
{
if
(
val
)
{
this
.
cachedOpenKeys
=
this
.
openKeys
this
.
openKeys
=
[]
...
...
@@ -52,94 +52,79 @@ export default {
this
.
openKeys
=
this
.
cachedOpenKeys
}
},
'$route'
:
function
()
{
$route
:
function
()
{
this
.
updateMenu
()
}
},
methods
:
{
renderIcon
:
function
(
h
,
icon
)
{
return
icon
===
'none'
||
icon
===
undefined
?
null
:
h
(
Icon
,
{
props
:
{
type
:
icon
!==
undefined
?
icon
:
''
}
})
renderIcon
:
function
(
h
,
icon
)
{
return
icon
===
'none'
||
icon
===
undefined
?
null
:
h
(
Icon
,
{
props
:
{
type
:
icon
!==
undefined
?
icon
:
''
}
})
},
renderMenuItem
:
function
(
h
,
menu
,
pIndex
,
index
)
{
return
h
(
Item
,
{
key
:
menu
.
path
?
menu
.
path
:
'item_'
+
pIndex
+
'_'
+
index
},
[
h
(
'router-link'
,
{
attrs
:
{
to
:
{
name
:
menu
.
name
}
}
},
[
this
.
renderIcon
(
h
,
menu
.
meta
.
icon
),
h
(
'span'
,
[
menu
.
meta
.
title
])
]
)
]
)
renderMenuItem
:
function
(
h
,
menu
,
pIndex
,
index
)
{
return
h
(
Item
,
{
key
:
menu
.
path
?
menu
.
path
:
'item_'
+
pIndex
+
'_'
+
index
},
[
h
(
'router-link'
,
{
attrs
:
{
to
:
{
name
:
menu
.
name
}
}
},
[
this
.
renderIcon
(
h
,
menu
.
meta
.
icon
),
h
(
'span'
,
[
menu
.
meta
.
title
])
])
])
},
renderSubMenu
:
function
(
h
,
menu
,
pIndex
,
index
)
{
renderSubMenu
:
function
(
h
,
menu
,
pIndex
,
index
)
{
const
this2_
=
this
const
subItem
=
[
h
(
'span'
,
{
slot
:
'title'
},
[
this
.
renderIcon
(
h
,
menu
.
meta
.
icon
),
h
(
'span'
,
[
menu
.
meta
.
title
])
]
)
]
const
subItem
=
[
h
(
'span'
,
{
slot
:
'title'
},
[
this
.
renderIcon
(
h
,
menu
.
meta
.
icon
),
h
(
'span'
,
[
menu
.
meta
.
title
])])]
const
itemArr
=
[]
const
pIndex_
=
pIndex
+
'_'
+
index
if
(
!
menu
.
alwaysShow
)
{
menu
.
children
.
forEach
(
function
(
item
,
i
)
{
menu
.
children
.
forEach
(
function
(
item
,
i
)
{
itemArr
.
push
(
this2_
.
renderItem
(
h
,
item
,
pIndex_
,
i
))
})
}
return
h
(
SubMenu
,
{
key
:
menu
.
path
?
menu
.
path
:
'submenu_'
+
pIndex
+
'_'
+
index
},
subItem
.
concat
(
itemArr
)
)
return
h
(
SubMenu
,
{
key
:
menu
.
path
?
menu
.
path
:
'submenu_'
+
pIndex
+
'_'
+
index
},
subItem
.
concat
(
itemArr
))
},
renderItem
:
function
(
h
,
menu
,
pIndex
,
index
)
{
renderItem
:
function
(
h
,
menu
,
pIndex
,
index
)
{
if
(
!
menu
.
hidden
)
{
return
menu
.
children
&&
!
menu
.
alwaysShow
?
this
.
renderSubMenu
(
h
,
menu
,
pIndex
,
index
)
:
this
.
renderMenuItem
(
h
,
menu
,
pIndex
,
index
)
return
menu
.
children
&&
!
menu
.
alwaysShow
?
this
.
renderSubMenu
(
h
,
menu
,
pIndex
,
index
)
:
this
.
renderMenuItem
(
h
,
menu
,
pIndex
,
index
)
}
},
renderMenu
:
function
(
h
,
menuTree
)
{
renderMenu
:
function
(
h
,
menuTree
)
{
const
this2_
=
this
const
menuArr
=
[]
menuTree
.
forEach
(
function
(
menu
,
i
)
{
menuTree
.
forEach
(
function
(
menu
,
i
)
{
if
(
!
menu
.
hidden
)
{
menuArr
.
push
(
this2_
.
renderItem
(
h
,
menu
,
'0'
,
i
))
}
})
return
menuArr
},
onOpenChange
(
openKeys
)
{
const
latestOpenKey
=
openKeys
.
find
(
key
=>
this
.
openKeys
.
indexOf
(
key
)
===
-
1
)
if
(
this
.
rootSubmenuKeys
.
indexOf
(
latestOpenKey
)
===
-
1
)
{
onOpenChange
(
openKeys
)
{
const
latestOpenKey
=
openKeys
.
find
(
key
=>
!
this
.
openKeys
.
includes
(
key
)
)
if
(
!
this
.
rootSubmenuKeys
.
includes
(
latestOpenKey
)
)
{
this
.
openKeys
=
openKeys
}
else
{
this
.
openKeys
=
latestOpenKey
?
[
latestOpenKey
]
:
[]
this
.
openKeys
=
latestOpenKey
?
[
latestOpenKey
]
:
[]
}
},
updateMenu
()
{
updateMenu
()
{
const
routes
=
this
.
$route
.
matched
.
concat
()
if
(
routes
.
length
>=
4
&&
this
.
$route
.
meta
.
hidden
)
{
routes
.
pop
()
this
.
selectedKeys
=
[
routes
[
2
].
path
]
this
.
selectedKeys
=
[
routes
[
2
].
path
]
}
else
{
this
.
selectedKeys
=
[
routes
.
pop
().
path
]
this
.
selectedKeys
=
[
routes
.
pop
().
path
]
}
const
openKeys
=
[]
if
(
this
.
mode
===
'inline'
)
{
routes
.
forEach
(
(
item
)
=>
{
routes
.
forEach
(
item
=>
{
openKeys
.
push
(
item
.
path
)
})
}
this
.
collapsed
?
this
.
cachedOpenKeys
=
openKeys
:
this
.
openKeys
=
openKeys
this
.
collapsed
?
(
this
.
cachedOpenKeys
=
openKeys
)
:
(
this
.
openKeys
=
openKeys
)
}
},
render
(
h
)
{
render
(
h
)
{
return
h
(
Menu
,
{
...
...
@@ -151,12 +136,13 @@ export default {
},
on
:
{
openChange
:
this
.
onOpenChange
,
select
:
(
obj
)
=>
{
select
:
obj
=>
{
this
.
selectedKeys
=
obj
.
selectedKeys
this
.
$emit
(
'select'
,
obj
)
}
}
},
this
.
renderMenu
(
h
,
this
.
menu
)
},
this
.
renderMenu
(
h
,
this
.
menu
)
)
}
}
\ No newline at end of file
}
src/store/modules/permission.js
View file @
55d26ac5
...
...
@@ -9,10 +9,10 @@ import { asyncRouterMap, constantRouterMap } from '@/config/router.config'
*/
function
hasPermission
(
permission
,
route
)
{
if
(
route
.
meta
&&
route
.
meta
.
permission
)
{
let
flag
=
-
1
let
flag
=
false
for
(
let
i
=
0
,
len
=
permission
.
length
;
i
<
len
;
i
++
)
{
flag
=
route
.
meta
.
permission
.
in
dexOf
(
permission
[
i
])
if
(
flag
>=
0
)
{
flag
=
route
.
meta
.
permission
.
in
cludes
(
permission
[
i
])
if
(
flag
)
{
return
true
}
}
...
...
@@ -31,7 +31,7 @@ function hasPermission(permission, route) {
// eslint-disable-next-line
function
hasRole
(
roles
,
route
)
{
if
(
route
.
meta
&&
route
.
meta
.
roles
)
{
return
route
.
meta
.
roles
.
in
dexOf
(
roles
.
id
)
return
route
.
meta
.
roles
.
in
cludes
(
roles
.
id
)
}
else
{
return
true
}
...
...
@@ -73,4 +73,4 @@ const permission = {
}
}
export
default
permission
\ No newline at end of file
export
default
permission
src/views/account/center/Index.vue
View file @
55d26ac5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment