Browse Source

修改优化以及修复动态生成的菜单栏点击和刷新页面不高亮问题

master
wen 2 years ago
parent
commit
96969eb5c3
  1. 38
      src/layout/components/Sidebar/index.vue
  2. 13
      src/layout/components/Sidebar/leftMenusData.js
  3. 34
      src/router/index.js
  4. 2
      src/settings.js

38
src/layout/components/Sidebar/index.vue

@ -29,12 +29,11 @@ import menusdata from './leftMenusData.js'
import { mirlist } from '@/api/user' import { mirlist } from '@/api/user'
//console.log(menusdata); //console.log(menusdata);
var dfdg = 10;
export default { export default {
components: { SidebarItem, Logo }, components: { SidebarItem, Logo },
created: function () { created: function () {
this.getmunusdata(); this.getmunusdata();
//this.menusdatas = ''
var fe = 10;
}, },
data() { data() {
return { return {
@ -48,12 +47,23 @@ export default {
// routes() { // routes() {
// return this.$router.options.routes // return this.$router.options.routes
// }, // },
// index
activeMenu() { activeMenu() {
const route = this.$route const route = this.$route
const { meta, path } = route const { meta, path } = route
const menusindex = window.location.href
// path
let getcan = menusindex.split('?id');
if (getcan[1]) {
//console.log(menusindex.split('/#'));
return menusindex.split('/#')[1]
}
// if set path, the sidebar will highlight the path you set // if set path, the sidebar will highlight the path you set
if (meta.activeMenu) { if (meta.activeMenu) {
return meta.activeMenu return meta.activeMenu //
} }
return path return path
}, },
@ -77,39 +87,29 @@ export default {
// this.$set(this.menusdata,'children', []) // this.$set(this.menusdata,'children', [])
// //menusdata[0].children = [] // //menusdata[0].children = []
// } // }
newMenu = { newMenu = {
path: '/subfile?id='+item.id, path: '/filemange/subfile?id='+item.id,
meta: { title: item.directory, icon: 'dashboard' }, meta: { title: item.directory, activeMenu:'subfile?id='+item.id, icon: 'dashboard' },
children:[] children:[]
} }
//console.log(item.directories.length);
if (item.directories && item.directories.length > 0) { if (item.directories && item.directories.length > 0) {
newMenu.children = this.SplicingMenuTree(item.directories,) newMenu.children = this.SplicingMenuTree(item.directories)
} }
arrMenus.push(newMenu); arrMenus.push(newMenu);
//console.log(arrMenus);
}); });
return arrMenus; return arrMenus;
}, },
getmunusdata() { getmunusdata() {
let thiss = this; let thiss = this;
// console.log(this.$route); //console.log(this.$route);
// console.log(this.$store); // console.log(this.$store);
mirlist().then(response => { mirlist().then(response => {
let datamain = response.data; let datamain = response.data;
//routesData(datamain.data.menus);
//console.log(response); this.routes[0].children = this.SplicingMenuTree(datamain.data.menus);
console.log(this.menusdatas);
menusdata[0].children = this.SplicingMenuTree(datamain.data.menus);
//menusdatas[0] = addmunst
console.log(menusdata);
//this.routes = menusdata
//console.log(menusdata);
}).catch(function (error) { }).catch(function (error) {
thiss.$message({ thiss.$message({

13
src/layout/components/Sidebar/leftMenusData.js

@ -8,19 +8,19 @@ var menusdata = [
// meta: { title: '文件管理', icon: 'dashboard' }, // meta: { title: '文件管理', icon: 'dashboard' },
// children: [ // children: [
// { // {
// path: '/subfile', // path: '/filemange/subfile?id=0',
// meta: { title: 'Menu1-1' } // meta: { title: 'Menu1-1' }
// }, // },
// { // {
// path: '/subfile', // path: '/filemange/subfile',
// meta: { title: 'Menu1-2' }, // meta: { title: 'Menu1-2' },
// children: [ // children: [
// { // {
// path: '/subfile', // path: '/filemange/subfile?id=1',
// meta: { title: 'Menu1-2-1' } // meta: { title: 'Menu1-2-1' }
// }, // },
// { // {
// path: '/subfile', // path: '/filemange/subfile',
// meta: { title: 'Menu1-2-2' } // meta: { title: 'Menu1-2-2' }
// } // }
// ] // ]
@ -56,6 +56,11 @@ var menusdata = [
} }
] ]
}, },
{
path: 'https://dev.filesite.io/',
meta: { title: '前端展示页面', icon: 'dashboard' }
}
] ]
export default menusdata export default menusdata

34
src/router/index.js

@ -44,16 +44,22 @@ export const constantRoutes = [
hidden: true hidden: true
}, },
{ {
path: '/', path: '/filemange',
component: Layout, component: Layout,
name: 'filemange', name: 'filemange',
meta: { title: '文件管理', icon: 'el-icon-s-help' }, meta: { title: '文件管理', icon: 'el-icon-s-help' },
children: [ children: [
{ {
path: 'filemange', path: 'createDirectory',
name: 'Filemange', name: 'CreateDirectory',
component: () => import('@/views/filemange/index'), component: () => import('@/views/filemange/index'),
meta: { title: '文件管理', icon: 'dashboard' } meta: { title: '创建目录', icon: 'dashboard' }
},
{
path: 'subfile',
name: 'Subfile',
component: () => import('@/views/subfile/index'),
meta: { title: '子文件', icon: 'dashboard' }
} }
] ]
}, },
@ -67,16 +73,16 @@ export const constantRoutes = [
meta: { title: '用户管理', icon: 'dashboard' } meta: { title: '用户管理', icon: 'dashboard' }
}] }]
}, },
{ // {
path: '/', // path: '/',
component: Layout, // component: Layout,
children: [{ // children: [{
path: 'subfile', // path: 'subfile',
name: 'Subfile', // name: 'Subfile',
component: () => import('@/views/subfile/index'), // component: () => import('@/views/subfile/index'),
meta: { title: '文件管理', icon: 'dashboard' } // meta: { title: '文件管理', icon: 'dashboard' }
}] // }]
}, // },
{ {
path: '/systme', path: '/systme',
component: Layout, component: Layout,

2
src/settings.js

@ -1,6 +1,6 @@
module.exports = { module.exports = {
title: 'Vue Admin Template', title: '嘉洛马',
/** /**
* @type {boolean} true | false * @type {boolean} true | false

Loading…
Cancel
Save