Browse Source

修改

master
wen 2 years ago
parent
commit
0ebfa92a17
  1. 5
      src/layout/components/Sidebar/SidebarItem.vue
  2. 52
      src/layout/components/Sidebar/index.vue
  3. 36
      src/layout/components/Sidebar/leftMenusData.js
  4. 47
      src/permission.js
  5. 63
      src/router/index.js
  6. 1
      src/views/usermanage/index.vue

5
src/layout/components/Sidebar/SidebarItem.vue

@ -1,13 +1,15 @@ @@ -1,13 +1,15 @@
<template>
<div v-if="!item.hidden">
<!-- <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> -->
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" />
</el-menu-item>
</app-link>
</template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
<template slot="title">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
@ -50,7 +52,6 @@ export default { @@ -50,7 +52,6 @@ export default {
}
},
// mounted: function () {
// console.log(222);
// },
data() {
// To fix https://github.com/PanJiaChen/vue-admin-template/issues/237

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

@ -15,23 +15,37 @@ @@ -15,23 +15,37 @@
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
</el-menu>
</el-scrollbar>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss'
import menusdata from './leftMenusData.js'
import { mirlist } from '@/api/user'
//console.log(menusdata);
export default {
components: { SidebarItem, Logo },
created: function () {
this.getmunusdata();
},
data() {
return {
routes:menusdata
}
},
computed: {
...mapGetters([
'sidebar'
]),
routes() {
return this.$router.options.routes
},
// routes() {
// return this.$router.options.routes
// },
activeMenu() {
const route = this.$route
const { meta, path } = route
@ -50,6 +64,38 @@ export default { @@ -50,6 +64,38 @@ export default {
isCollapse() {
return !this.sidebar.opened
}
},
methods: {
getmunusdata() {
let thiss = this;
console.log(menusdata[0]);
mirlist().then(response => {
let datamain = response.data;
//routesData(datamain.data.menus);
//console.log(response);
datamain.data.menus.forEach(item => {
console.log(menusdata[0]);
menusdata[0].children.push(
{
path: '/usermange',
meta: { title: item.directory, icon: 'dashboard' }
}
);
});
this.$router.push({ path: 'usermange', query: { plan: 'private' }})
}).catch(function (error) {
thiss.$message({
showClose: true,
message: error,
type: 'error'
});
});
}
}
}
</script>

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

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
// 菜单栏生成
let menusdata = [
{
id: '0',
path: '/filemange',
meta: { title: '文件管理', icon: 'dashboard' },
children:[]
},
{
path: '/usermange',
meta: { title: '用户管理', icon: 'dashboard' }
},
{
path: '/systme',
meta: { title: '系统管理', icon: 'dashboard' },
children: [
{
path: 'changepass',
meta: { title: '修改密码', icon: 'table' }
},
{
path: 'userrelated',
meta: { title: '用户相关', icon: 'tree' }
},
{
path: 'userrelated2',
meta: { title: '皮肤更换', icon: 'tree' }
}
]
},
]
export default menusdata

47
src/permission.js

@ -11,53 +11,6 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -11,53 +11,6 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/login'] // no redirect whitelist
// 动态添加路由
import { mirlist } from '@/api/user'
mirlist().then(response => {
let datamain = response.data;
routesData(datamain.data.menus);
//console.log(response);
}).catch(function (error) {
Message({
showClose: true,
message: error,
type: 'error'
});
});
function routesData(data) {
// 重新加载一次 VueRouter
//router.reloadRouter()
let currentMenu = [
{
path: '/',
component: () => import('@/views/systme/changepass'),
children: []
}
]
console.log(router);
data.forEach(item => {
console.log(item);
const temp = {
name: item.directory,
path: item.directory,
component: () => import(`../page/${item.path}/${firstUppercase(i.path)}.vue`)
}
// 动态添加为 filemange 的子路由
router.addRoutes(currentMenu)
// item.children.forEach(i => {
// // 组装路由配置
// const temp = {
// name: i.path,
// path: i.path,
// component: () => import(`../page/${item.path}/${firstUppercase(i.path)}.vue`)
// }
// // 动态添加为 filemange 的子路由
// router.addRoute("filemange", temp)
// })
})
}
router.beforeEach(async(to, from, next) => {
// start progress bar
NProgress.start()

63
src/router/index.js

@ -30,6 +30,7 @@ import Layout from '@/layout' @@ -30,6 +30,7 @@ import Layout from '@/layout'
* all roles can be accessed
*/
export const constantRoutes = [
{
path: '/login',
@ -45,9 +46,7 @@ export const constantRoutes = [ @@ -45,9 +46,7 @@ export const constantRoutes = [
{
path: '/',
component: Layout,
redirect: '/filemange', // 重定向地址
name: 'filemange',
alwaysShow: false,
meta: { title: '文件管理', icon: 'el-icon-s-help' },
children: [
{
@ -56,14 +55,11 @@ export const constantRoutes = [ @@ -56,14 +55,11 @@ export const constantRoutes = [
component: () => import('@/views/filemange/index'),
meta: { title: '文件管理', icon: 'dashboard' }
}
]
},
{
path: '',
component: Layout,
redirect: '/usermange',
children: [{
path: 'usermange',
name: 'Usermange',
@ -71,6 +67,16 @@ export const constantRoutes = [ @@ -71,6 +67,16 @@ export const constantRoutes = [
meta: { title: '用户管理', icon: 'dashboard' }
}]
},
// {
// path: '/',
// component: Layout,
// children: [{
// path: 'filemangeff',
// name: 'filemangeff',
// component: () => import('@/views/usermanage/index'),
// meta: { title: 'text', icon: 'dashboard' }
// }]
// },
{
path: '/systme',
component: Layout,
@ -113,13 +119,52 @@ export const constantRoutes = [ @@ -113,13 +119,52 @@ export const constantRoutes = [
{ path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
const createRouter = (a) => new Router({
//mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
scrollBehavior: () => ({ y: 0 }),
routes: a
})
const router = createRouter()
//let router
const router = createRouter(constantRoutes)
// 动态添加路由
// import { mirlist } from '@/api/user'
// let pachs = () => import('@/views/filemange/index');
// mirlist().then(response => {
// let datamain = response.data;
// //routesData(datamain.data.menus);
// //console.log(response);
// datamain.data.menus.forEach(item => {
// menus.push(
// {
// path: item.directory,
// name: item.directory,
// component: pachs,
// meta: { title: item.directory, icon: 'dashboard' }
// }
// );
// });
// //console.log(menus);
// //router = createRouter(constantRoutes)
// console.log(router.options);
// router = createRouter(constantRoutes)
// // {
// // path: 'filemange',
// // name: 'Filemange',
// // component: () => import('@/views/filemange/index'),
// // meta: { title: '文件管理', icon: 'dashboard' }
// // }
// }).catch(function (error) {
// Message({
// showClose: true,
// message: error,
// type: 'error'
// });
// });
//router = createRouter(constantRoutes)
//router.addRoutes(constantRoutes);
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {

1
src/views/usermanage/index.vue

@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
</template>
<script>
import { getList } from '@/api/table'
export default {

Loading…
Cancel
Save