Commit 188783e4 authored by 黎博's avatar 黎博

优化菜单生成方式

parent 5f846a5c
......@@ -32,7 +32,7 @@
<script>
import { mapGetters } from 'vuex'
import menu from './menu.json'
// import { getUserDetail } from '@/api/getLogin/'
import { getUserDetail } from '@/api/Login/'
export default {
name: 'Aside',
data() {
......@@ -41,28 +41,22 @@ export default {
defaultOpen: ['0'],
// 激活的菜单
activePath: '',
menuList: [],
newNav: []
menuList: []
}
},
methods: {
getNav() {
this.nav = menu.menu
console.log('444', this.nav)
const tempNav = menu.menu
// 循环判断新列表里的是数据是否在旧列表里出现
this.nav.forEach((element) => {
tempNav.forEach((element) => {
var temp = {}
temp['id'] = element.id
temp['icon'] = element.icon
temp['title'] = element.title
temp['child'] = []
element.child.forEach((children) => {
console.log('children: ', children)
var flag = false
console.log(this.menuList)
this.menuList.forEach((menu) => {
console.log('menu: ', menu)
console.log('children.path', children.path)
if (menu === children.path) {
flag = true
}
......@@ -71,12 +65,13 @@ export default {
temp['child'].push(children)
}
})
this.newNav.push(temp)
// 判断子菜单是否为空,为空不添加
if (temp.child.length > 0) {
this.nav.push(temp)
}
})
console.log('newNav', this.newNav)
this.$store.dispatch('header/setNavs', {
// nav: this.nav
nav: this.newNav
nav: this.nav
})
},
......@@ -93,12 +88,11 @@ export default {
window.sessionStorage.setItem('activePath', activePath)
},
// 获取用户详细信息
async getUserDetail() {
// getUserDetail().then((resp) => {
// this.menuList = resp.data.data.menuList
// console.log('menuList----', this.menuList)
// })
// this.getNav()
getUserDetail() {
getUserDetail().then((resp) => {
this.menuList = resp.data.data.menuList
this.getNav()
})
}
},
computed: {
......@@ -113,7 +107,7 @@ export default {
created() {
this.activePath = window.sessionStorage.getItem('activePath')
this.getUserDetail()
this.getNav()
// this.getNav()
}
}
</script>
......
......@@ -24,7 +24,7 @@
<script>
import { getNamespaceList } from '@/api/getXyqbData/'
import { login } from '@/api/getLogin/'
import { login } from '@/api/Login/'
export default {
data() {
return {
......
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