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

优化菜单生成方式

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