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
b0304711
Commit
b0304711
authored
Nov 13, 2018
by
tangqy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整 根据路由改变边侧栏
parent
a07aa773
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
23 deletions
+68
-23
index.vue
src/components/Sidebar/index.vue
+34
-14
index.js
src/router/index.js
+5
-0
index.js
src/store/global/index.js
+1
-9
index.js
src/utils/index.js
+28
-0
No files found.
src/components/Sidebar/index.vue
View file @
b0304711
...
@@ -4,16 +4,16 @@
...
@@ -4,16 +4,16 @@
.sidebar('@mouseover'="showUnfoldBtn()",'@mouseout'="hiddenUnfoldBtn()")
.sidebar('@mouseover'="showUnfoldBtn()",'@mouseout'="hiddenUnfoldBtn()")
.logo
.logo
img(':src'="logo")
img(':src'="logo")
.item('v-if'="menus.length",'v-for'="(
data,itemIndex) in menus" ,':key'="data.
item.id",'@click'='choseMenu(data,itemIndex)',':class'="{active:currentMenusIndex === itemIndex}")
.item('v-if'="menus.length",'v-for'="(
item,itemIndex) in menus" ,':key'="
item.id",'@click'='choseMenu(data,itemIndex)',':class'="{active:currentMenusIndex === itemIndex}")
sidebar-item&attributes({
sidebar-item&attributes({
':icon':'
data.
item.ico',
':icon':'item.ico',
':link':'
data.
item.link',
':link':'item.link',
':type':'
data.
item.type',
':type':'item.type',
':id':'
data.
item.id',
':id':'item.id',
':name':'
data.
item.name',
':name':'item.name',
':pid':'
data.
item.pid',
':pid':'item.pid',
':grade':'
data.
item.grade',
':grade':'item.grade',
':sort':'
data.
item.sort'
':sort':'item.sort'
})
})
transition(name="fade",mode="out-in",appear)
transition(name="fade",mode="out-in",appear)
.childrens-meuns('v-show'="sidebarUnfoldInfo",'v-if'="currentMenus")
.childrens-meuns('v-show'="sidebarUnfoldInfo",'v-if'="currentMenus")
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
mapGetters
,
mapActions
}
from
'vuex'
import
{
mapGetters
,
mapActions
}
from
'vuex'
import
{
calcIndexPathByCurrentRouter
}
from
'@/utils'
import
sidebarItem
from
'../sidebarItem'
import
sidebarItem
from
'../sidebarItem'
const
CrossStorageClient
=
require
(
'cross-storage'
).
CrossStorageClient
;
const
CrossStorageClient
=
require
(
'cross-storage'
).
CrossStorageClient
;
const
crmDomain
=
location
.
hostname
const
crmDomain
=
location
.
hostname
...
@@ -51,12 +52,10 @@ const logo = require('@/assets/images/sidebar/logo-blue.png')
...
@@ -51,12 +52,10 @@ const logo = require('@/assets/images/sidebar/logo-blue.png')
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
currentIndexPath
:
[
1
,
0
],
collapse
:
false
,
collapse
:
false
,
logo
,
logo
,
// unfold: false, // 水平展开
// unfold: false, // 水平展开
unfoldBtn
:
false
,
// 展开按钮
unfoldBtn
:
false
,
// 展开按钮
currentMenusIndex
:
2
}
}
},
},
filters
:
{
filters
:
{
...
@@ -77,10 +76,13 @@ export default {
...
@@ -77,10 +76,13 @@ export default {
project
:
'getProjectInfo'
,
project
:
'getProjectInfo'
,
sidebarUnfoldInfo
:
'getSidebarUnfoldInfo'
,
sidebarUnfoldInfo
:
'getSidebarUnfoldInfo'
,
}),
}),
currentMenusIndex
()
{
return
(
this
.
selectIndexPath
&&
this
.
selectIndexPath
.
length
)
?
this
.
selectIndexPath
[
0
]
:
-
1
},
currentMenus
:
{
currentMenus
:
{
get
()
{
get
()
{
const
currentIndex
=
this
.
currentMenusIndex
const
currentIndex
=
this
.
currentMenusIndex
const
currentMenus
=
currentIndex
===
-
1
?
this
.
getCurrentMenus
(
0
)
:
this
.
getCurrentMenus
(
currentIndex
)
const
currentMenus
=
currentIndex
===
-
1
?
this
.
handerNoSidebar
(
)
:
this
.
getCurrentMenus
(
currentIndex
)
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
if
(
this
.
currentMenus
)
{
if
(
this
.
currentMenus
)
{
this
.
handleOpen
()
this
.
handleOpen
()
...
@@ -88,6 +90,13 @@ export default {
...
@@ -88,6 +90,13 @@ export default {
})
})
return
currentMenus
return
currentMenus
}
}
},
calc
()
{
const
hasMenus
=
this
.
menus
&&
this
.
menus
.
length
if
(
hasMenus
)
{
this
.
calcRouter
(
this
.
menus
)
}
return
hasMenus
}
}
},
},
mounted
()
{
mounted
()
{
...
@@ -96,7 +105,18 @@ export default {
...
@@ -96,7 +105,18 @@ export default {
methods
:
{
methods
:
{
handleOpen
()
{
handleOpen
()
{
const
menus
=
this
.
$refs
.
menu
const
menus
=
this
.
$refs
.
menu
menus
.
open
(
0
)
const
openIndex
=
(
this
.
selectIndexPath
.
length
===
3
)
?
this
.
selectIndexPath
[
1
]
:
0
menus
.
open
(
openIndex
)
},
calcRouter
(
menus
)
{
debugger
const
currentRoute
=
location
.
href
const
indexPath
=
calcIndexPathByCurrentRouter
(
menus
,
currentRoute
)
this
.
selectIndexPath
=
indexPath
},
// 隐藏边侧栏,边侧栏最小化
handerNoSidebar
()
{
this
.
setSidebarUnfold
(
false
)
},
},
/**
/**
* 选择边测菜单主菜单
* 选择边测菜单主菜单
...
@@ -160,7 +180,7 @@ export default {
...
@@ -160,7 +180,7 @@ export default {
})
})
},
},
getCurrentMenus
(
index
)
{
getCurrentMenus
(
index
)
{
return
this
.
menus
[
index
]
.
item
return
this
.
menus
[
index
]
},
},
...
mapActions
([
'setSidebarUnfold'
])
...
mapActions
([
'setSidebarUnfold'
])
}
}
...
...
src/router/index.js
View file @
b0304711
...
@@ -29,6 +29,11 @@ export default new Router({
...
@@ -29,6 +29,11 @@ export default new Router({
path
:
'/login'
,
path
:
'/login'
,
name
:
'Login'
,
name
:
'Login'
,
component
:
()
=>
import
(
/* webpackChunkName: 'wxlogin' */
'pages/login'
)
component
:
()
=>
import
(
/* webpackChunkName: 'wxlogin' */
'pages/login'
)
},
{
path
:
'/changelCenter/store/storeManage/storeOrgManage.do'
,
name
:
'test'
,
component
:
()
=>
import
(
/* web packChunkName: 'wxhome' */
'pages/home'
),
}
}
]
]
})
})
src/store/global/index.js
View file @
b0304711
...
@@ -29,15 +29,7 @@ const actions = {
...
@@ -29,15 +29,7 @@ const actions = {
},
parmas
)
{
},
parmas
)
{
let
res
=
await
globalApi
.
getMenus
(
parmas
)
let
res
=
await
globalApi
.
getMenus
(
parmas
)
let
menus
=
res
.
data
.
data
let
menus
=
res
.
data
.
data
let
menus2
=
menus
.
map
((
item
,
index
)
=>
{
commit
(
GET_MEUMS
,
menus
)
return
{
index
,
item
:
{
...
item
}
}
})
console
.
log
(
menus2
)
commit
(
GET_MEUMS
,
menus2
)
},
},
showEditMenus
({
commit
})
{
showEditMenus
({
commit
})
{
commit
(
SHOW_EDIT_MENUS
,
true
)
commit
(
SHOW_EDIT_MENUS
,
true
)
...
...
src/utils/index.js
View file @
b0304711
...
@@ -17,3 +17,31 @@ export function getCookie(name) {
...
@@ -17,3 +17,31 @@ export function getCookie(name) {
}
}
return
''
return
''
}
}
// 获取边侧栏路径indexPath与点击跳转链接link的mapping
export
function
indexPathMapping
(
menus
=
[],
mapping
=
{},
indexPath
=
[])
{
menus
.
forEach
((
item
,
index
)
=>
{
let
indexTemp
=
[...
indexPath
]
indexTemp
.
push
(
index
)
if
(
item
.
children
&&
indexPath
<=
3
)
{
indexPathMapping
(
item
.
children
,
mapping
,
indexTemp
)
}
if
(
item
.
link
)
{
let
link
=
item
.
link
mapping
[
link
]
=
indexTemp
}
})
}
export
function
calcIndexPathByRouter
(
mapping
=
{},
route
=
''
)
{
const
key
=
Object
.
keys
(
mapping
)
.
filter
((
item
)
=>
route
.
indexOf
(
item
))[
0
]
return
mapping
[
key
]
}
export
function
calcIndexPathByCurrentRouter
(
menus
=
[],
currentRoute
=
''
)
{
let
indexPathMappingWithLink
=
{}
indexPathMapping
(
menus
,
indexPathMappingWithLink
)
return
calcIndexPathByRouter
(
indexPathMappingWithLink
,
currentRoute
)
}
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