Commit e5c469fd by tangqy

根据路由边侧栏显示

parent b0304711
......@@ -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.selectIndexPath[1] : 0
const openIndex = (this.currentPath.length === 3) ? this.currentPath[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 {
......
......@@ -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'),
}
......
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,
currentMenus: [],
currentPath: [],
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]
}
}
......
......@@ -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]
}
......
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