Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common-templete
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
汤强勇
common-templete
Commits
e5c469fd
Commit
e5c469fd
authored
Nov 13, 2018
by
tangqy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
根据路由边侧栏显示
parent
b0304711
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
39 deletions
+40
-39
index.vue
src/components/Sidebar/index.vue
+14
-11
index.js
src/router/index.js
+1
-1
index.js
src/store/global/index.js
+21
-26
index.js
src/utils/index.js
+4
-1
No files found.
src/components/Sidebar/index.vue
View file @
e5c469fd
...
...
@@ -73,16 +73,24 @@ export default {
computed
:
{
...
mapGetters
({
menus
:
'getMenus'
,
currentPath
:
'getCurrentPath'
,
project
:
'getProjectInfo'
,
sidebarUnfoldInfo
:
'getSidebarUnfoldInfo'
,
}),
currentMenusIndex
()
{
return
(
this
.
selectIndexPath
&&
this
.
selectIndexPath
.
length
)
?
this
.
selectIndexPath
[
0
]
:
-
1
let
res
=
-
1
if
(
this
.
currentPath
&&
this
.
currentPath
.
length
)
{
res
=
this
.
currentPath
[
0
]
this
.
$nextTick
(()
=>
{
this
.
handleOpen
()
})
}
return
res
},
currentMenus
:
{
get
()
{
const
currentIndex
=
this
.
currentMenusIndex
const
currentMenus
=
currentIndex
===
-
1
?
this
.
handerNoSidebar
(
)
:
this
.
getCurrentMenus
(
currentIndex
)
const
currentMenus
=
currentIndex
===
-
1
?
this
.
getCurrentMenus
(
0
)
:
this
.
getCurrentMenus
(
currentIndex
)
this
.
$nextTick
(()
=>
{
if
(
this
.
currentMenus
)
{
this
.
handleOpen
()
...
...
@@ -90,13 +98,6 @@ export default {
})
return
currentMenus
}
},
calc
()
{
const
hasMenus
=
this
.
menus
&&
this
.
menus
.
length
if
(
hasMenus
)
{
this
.
calcRouter
(
this
.
menus
)
}
return
hasMenus
}
},
mounted
()
{
...
...
@@ -105,17 +106,18 @@ export default {
methods
:
{
handleOpen
()
{
const
menus
=
this
.
$refs
.
menu
const
openIndex
=
(
this
.
selectIndexPath
.
length
===
3
)
?
this
.
selectIndex
Path
[
1
]
:
0
const
openIndex
=
(
this
.
currentPath
.
length
===
3
)
?
this
.
current
Path
[
1
]
:
0
menus
.
open
(
openIndex
)
},
calcRouter
(
menus
)
{
debugger
const
currentRoute
=
location
.
href
const
indexPath
=
calcIndexPathByCurrentRouter
(
menus
,
currentRoute
)
this
.
selectIndexPath
=
indexPath
console
.
log
(
this
.
selectIndexPath
)
},
// 隐藏边侧栏,边侧栏最小化
handerNoSidebar
()
{
console
.
log
(
'handerNoSidebar'
)
this
.
setSidebarUnfold
(
false
)
},
/**
...
...
@@ -162,6 +164,7 @@ export default {
}
},
toggleUnfold
(...
args
)
{
console
.
log
(
args
)
if
(
!
args
.
length
)
{
this
.
setSidebarUnfold
(
!
this
.
sidebarUnfoldInfo
)
}
else
{
...
...
src/router/index.js
View file @
e5c469fd
...
...
@@ -31,7 +31,7 @@ export default new Router({
component
:
()
=>
import
(
/* webpackChunkName: 'wxlogin' */
'pages/login'
)
},
{
path
:
'/
changelCenter/store/storeManage/storeOrgManage
.do'
,
path
:
'/
salesCenter/activity/lotteryActivity
.do'
,
name
:
'test'
,
component
:
()
=>
import
(
/* web packChunkName: 'wxhome' */
'pages/home'
),
}
...
...
src/store/global/index.js
View file @
e5c469fd
import
{
globalApi
}
from
'@/api'
import
{
calcIndexPathByCurrentRouter
}
from
'@/utils'
// 获取菜单数据
const
GET_MEUMS
=
'GET_MEUMS'
...
...
@@ -15,11 +16,14 @@ const SIDEBAR_UNFOLD = 'SIDEBAR_UNFOLD'
// 基本信息
const
GET_PROJECT_INFO
=
'GET_PROJECT_INFO'
//
const
CALC_TOUTER_INDEX
=
'CALC_TOUTER_INDEX'
const
state
=
{
menus
:
[],
editMenus
:
false
,
projectInfo
:
null
,
current
Menus
:
[],
current
Path
:
[],
sidebarUnfold
:
true
// false:边侧菜单收缩, true:边侧菜单展开
}
...
...
@@ -29,36 +33,12 @@ const actions = {
},
parmas
)
{
let
res
=
await
globalApi
.
getMenus
(
parmas
)
let
menus
=
res
.
data
.
data
dispatch
(
'calcIndexPathByrouter'
,
menus
)
commit
(
GET_MEUMS
,
menus
)
},
showEditMenus
({
commit
})
{
commit
(
SHOW_EDIT_MENUS
,
true
)
},
computedSidebarUnfoldRouter
({
commit
,
dispatch
},
{
route
,
menus
})
{
for
(
let
index
=
0
;
index
<
menus
.
length
;
index
++
)
{
const
element
=
menus
[
index
]
if
(
element
.
link
===
route
)
{
dispatch
(
'setCurrentMenus'
,
{
index
:
`
${
index
}
`
,
item
:
element
})
break
}
else
{
for
(
let
i
=
0
;
i
<
element
.
length
;
i
++
)
{
const
item
=
element
[
i
]
if
(
item
.
link
===
route
)
{
dispatch
(
'setCurrentMenus'
,
{
index
:
`
${
index
}
-
${
i
}
`
,
item
})
break
}
else
{
for
(
let
j
=
0
;
j
<
item
.
length
;
j
++
)
{
const
it
=
item
[
j
]
if
(
it
.
link
===
route
)
{
dispatch
(
'setCurrentMenus'
,
{
index
:
`
${
index
}
-
${
i
}
-
${
j
}
`
,
item
:
it
})
break
}
}
}
}
}
}
},
hideEditMenus
({
commit
})
{
commit
(
HIDE_EDIT_MENUS
,
false
)
},
...
...
@@ -66,6 +46,14 @@ const actions = {
commit
(
SIDEBAR_UNFOLD
,
type
)
},
calcIndexPathByrouter
({
commit
},
menus
)
{
const
currentRoute
=
location
.
href
const
indexPath
=
calcIndexPathByCurrentRouter
(
menus
,
currentRoute
)
console
.
log
(
'this is indexPath %O'
,
indexPath
)
commit
(
CALC_TOUTER_INDEX
,
indexPath
)
// calcIndexPathByCurrentRouter(menus)
},
async
getProjectInfo
({
commit
,
dispatch
})
{
let
res
=
await
globalApi
.
getProjectInfo
()
let
projectInfo
=
res
.
data
...
...
@@ -88,6 +76,9 @@ const getters = {
},
getCurrentMenus
(
state
)
{
return
state
.
currentMenus
},
getCurrentPath
(
state
)
{
return
state
.
currentPath
}
}
...
...
@@ -107,6 +98,10 @@ const mutations = {
},
[
GET_PROJECT_INFO
](
state
,
projectInfo
)
{
state
.
projectInfo
=
{
...
projectInfo
}
},
[
CALC_TOUTER_INDEX
](
state
,
indexPath
)
{
console
.
log
(
'this is CALC_TOUTER_INDEX %o'
,
indexPath
)
state
.
currentPath
=
[...
indexPath
]
}
}
...
...
src/utils/index.js
View file @
e5c469fd
...
...
@@ -35,8 +35,11 @@ export function indexPathMapping(menus = [], mapping = {}, indexPath = []) {
}
export
function
calcIndexPathByRouter
(
mapping
=
{},
route
=
''
)
{
console
.
log
(
route
)
const
key
=
Object
.
keys
(
mapping
)
.
filter
((
item
)
=>
route
.
indexOf
(
item
))[
0
]
.
filter
((
item
)
=>
route
.
indexOf
(
item
)
>
-
1
)[
0
]
console
.
log
(
'this is key %o'
,
mapping
[
key
])
return
mapping
[
key
]
}
...
...
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