Browse Source

修改

master
wen 2 years ago
parent
commit
0ebfa92a17
  1. 3
      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

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

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

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

@ -15,23 +15,37 @@
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" /> <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
</div> </div>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import Logo from './Logo' import Logo from './Logo'
import SidebarItem from './SidebarItem' import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss' import variables from '@/styles/variables.scss'
import menusdata from './leftMenusData.js'
import { mirlist } from '@/api/user'
//console.log(menusdata);
export default { export default {
components: { SidebarItem, Logo }, components: { SidebarItem, Logo },
created: function () {
this.getmunusdata();
},
data() {
return {
routes:menusdata
}
},
computed: { computed: {
...mapGetters([ ...mapGetters([
'sidebar' 'sidebar'
]), ]),
routes() { // routes() {
return this.$router.options.routes // return this.$router.options.routes
}, // },
activeMenu() { activeMenu() {
const route = this.$route const route = this.$route
const { meta, path } = route const { meta, path } = route
@ -50,6 +64,38 @@ export default {
isCollapse() { isCollapse() {
return !this.sidebar.opened 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> </script>

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

@ -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
const whiteList = ['/login'] // no redirect whitelist 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) => { router.beforeEach(async(to, from, next) => {
// start progress bar // start progress bar
NProgress.start() NProgress.start()

63
src/router/index.js

@ -30,6 +30,7 @@ import Layout from '@/layout'
* all roles can be accessed * all roles can be accessed
*/ */
export const constantRoutes = [ export const constantRoutes = [
{ {
path: '/login', path: '/login',
@ -45,9 +46,7 @@ export const constantRoutes = [
{ {
path: '/', path: '/',
component: Layout, component: Layout,
redirect: '/filemange', // 重定向地址
name: 'filemange', name: 'filemange',
alwaysShow: false,
meta: { title: '文件管理', icon: 'el-icon-s-help' }, meta: { title: '文件管理', icon: 'el-icon-s-help' },
children: [ children: [
{ {
@ -56,14 +55,11 @@ export const constantRoutes = [
component: () => import('@/views/filemange/index'), component: () => import('@/views/filemange/index'),
meta: { title: '文件管理', icon: 'dashboard' } meta: { title: '文件管理', icon: 'dashboard' }
} }
] ]
}, },
{ {
path: '', path: '',
component: Layout, component: Layout,
redirect: '/usermange',
children: [{ children: [{
path: 'usermange', path: 'usermange',
name: 'Usermange', name: 'Usermange',
@ -71,6 +67,16 @@ export const constantRoutes = [
meta: { title: '用户管理', icon: 'dashboard' } meta: { title: '用户管理', icon: 'dashboard' }
}] }]
}, },
// {
// path: '/',
// component: Layout,
// children: [{
// path: 'filemangeff',
// name: 'filemangeff',
// component: () => import('@/views/usermanage/index'),
// meta: { title: 'text', icon: 'dashboard' }
// }]
// },
{ {
path: '/systme', path: '/systme',
component: Layout, component: Layout,
@ -113,13 +119,52 @@ export const constantRoutes = [
{ path: '*', redirect: '/404', hidden: true } { path: '*', redirect: '/404', hidden: true }
] ]
const createRouter = () => new Router({ const createRouter = (a) => new Router({
//mode: 'history', // require service support //mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }), scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes 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 // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() { export function resetRouter() {

1
src/views/usermanage/index.vue

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

Loading…
Cancel
Save