Commit b0304711 by tangqy

调整 根据路由改变边侧栏

parent a07aa773
...@@ -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'])
} }
......
...@@ -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'),
} }
] ]
}) })
...@@ -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)
......
...@@ -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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment