Commit e5c469fd by tangqy

根据路由边侧栏显示

parent b0304711
...@@ -73,16 +73,24 @@ export default { ...@@ -73,16 +73,24 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
menus: 'getMenus', menus: 'getMenus',
currentPath:'getCurrentPath',
project: 'getProjectInfo', project: 'getProjectInfo',
sidebarUnfoldInfo: 'getSidebarUnfoldInfo', sidebarUnfoldInfo: 'getSidebarUnfoldInfo',
}), }),
currentMenusIndex () { 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: { currentMenus: {
get () { get () {
const currentIndex = this.currentMenusIndex 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(() => { this.$nextTick(() => {
if (this.currentMenus) { if (this.currentMenus) {
this.handleOpen() this.handleOpen()
...@@ -90,13 +98,6 @@ export default { ...@@ -90,13 +98,6 @@ export default {
}) })
return currentMenus return currentMenus
} }
},
calc () {
const hasMenus = this.menus && this.menus.length
if (hasMenus ) {
this.calcRouter(this.menus)
}
return hasMenus
} }
}, },
mounted () { mounted () {
...@@ -105,17 +106,18 @@ export default { ...@@ -105,17 +106,18 @@ export default {
methods: { methods: {
handleOpen () { handleOpen () {
const menus = this.$refs.menu 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) menus.open(openIndex)
}, },
calcRouter (menus) { calcRouter (menus) {
debugger
const currentRoute = location.href const currentRoute = location.href
const indexPath = calcIndexPathByCurrentRouter(menus,currentRoute) const indexPath = calcIndexPathByCurrentRouter(menus,currentRoute)
this.selectIndexPath = indexPath this.selectIndexPath = indexPath
console.log(this.selectIndexPath)
}, },
// 隐藏边侧栏,边侧栏最小化 // 隐藏边侧栏,边侧栏最小化
handerNoSidebar () { handerNoSidebar () {
console.log('handerNoSidebar')
this.setSidebarUnfold(false) this.setSidebarUnfold(false)
}, },
/** /**
...@@ -162,6 +164,7 @@ export default { ...@@ -162,6 +164,7 @@ export default {
} }
}, },
toggleUnfold (...args) { toggleUnfold (...args) {
console.log(args)
if (!args.length) { if (!args.length) {
this.setSidebarUnfold(!this.sidebarUnfoldInfo) this.setSidebarUnfold(!this.sidebarUnfoldInfo)
} else { } else {
......
...@@ -31,7 +31,7 @@ export default new Router({ ...@@ -31,7 +31,7 @@ export default new Router({
component: () => import(/* webpackChunkName: 'wxlogin' */ 'pages/login') component: () => import(/* webpackChunkName: 'wxlogin' */ 'pages/login')
}, },
{ {
path: '/changelCenter/store/storeManage/storeOrgManage.do', path: '/salesCenter/activity/lotteryActivity.do',
name: 'test', name: 'test',
component: () => import(/* web packChunkName: 'wxhome' */ 'pages/home'), component: () => import(/* web packChunkName: 'wxhome' */ 'pages/home'),
} }
......
import { globalApi } from '@/api' import { globalApi } from '@/api'
import { calcIndexPathByCurrentRouter } from '@/utils'
// 获取菜单数据 // 获取菜单数据
const GET_MEUMS = 'GET_MEUMS' const GET_MEUMS = 'GET_MEUMS'
...@@ -15,11 +16,14 @@ const SIDEBAR_UNFOLD = 'SIDEBAR_UNFOLD' ...@@ -15,11 +16,14 @@ const SIDEBAR_UNFOLD = 'SIDEBAR_UNFOLD'
// 基本信息 // 基本信息
const GET_PROJECT_INFO = 'GET_PROJECT_INFO' const GET_PROJECT_INFO = 'GET_PROJECT_INFO'
//
const CALC_TOUTER_INDEX = 'CALC_TOUTER_INDEX'
const state = { const state = {
menus: [], menus: [],
editMenus: false, editMenus: false,
projectInfo: null, projectInfo: null,
currentMenus: [], currentPath: [],
sidebarUnfold: true // false:边侧菜单收缩, true:边侧菜单展开 sidebarUnfold: true // false:边侧菜单收缩, true:边侧菜单展开
} }
...@@ -29,36 +33,12 @@ const actions = { ...@@ -29,36 +33,12 @@ 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
dispatch('calcIndexPathByrouter', menus)
commit(GET_MEUMS, menus) commit(GET_MEUMS, menus)
}, },
showEditMenus({ commit }) { showEditMenus({ commit }) {
commit(SHOW_EDIT_MENUS, true) 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 }) { hideEditMenus({ commit }) {
commit(HIDE_EDIT_MENUS, false) commit(HIDE_EDIT_MENUS, false)
}, },
...@@ -66,6 +46,14 @@ const actions = { ...@@ -66,6 +46,14 @@ const actions = {
commit(SIDEBAR_UNFOLD, type) 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 }) { async getProjectInfo({ commit, dispatch }) {
let res = await globalApi.getProjectInfo() let res = await globalApi.getProjectInfo()
let projectInfo = res.data let projectInfo = res.data
...@@ -88,6 +76,9 @@ const getters = { ...@@ -88,6 +76,9 @@ const getters = {
}, },
getCurrentMenus(state) { getCurrentMenus(state) {
return state.currentMenus return state.currentMenus
},
getCurrentPath (state) {
return state.currentPath
} }
} }
...@@ -107,6 +98,10 @@ const mutations = { ...@@ -107,6 +98,10 @@ const mutations = {
}, },
[GET_PROJECT_INFO](state, projectInfo) { [GET_PROJECT_INFO](state, projectInfo) {
state.projectInfo = { ...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 = []) { ...@@ -35,8 +35,11 @@ export function indexPathMapping(menus = [], mapping = {}, indexPath = []) {
} }
export function calcIndexPathByRouter (mapping = {}, route = '') { export function calcIndexPathByRouter (mapping = {}, route = '') {
console.log(route)
const key = Object.keys(mapping) 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] 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