3b1ebb39 by 任超

style:权限处理

1 parent 9724faa4
......@@ -19,7 +19,9 @@
"nprogress": "0.2.0",
"vue": "2.6.10",
"vue-router": "3.0.2",
"vuex": "3.1.0"
"vuex": "3.1.0",
"bpmn-js": "^7.4.0",
"diagram-js": "^6.8.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "4.4.4",
......
<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)">
<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" class="menu-icon" />
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title"
class="menu-icon" />
</el-menu-item>
</app-link>
</template>
......@@ -12,14 +13,8 @@
<template slot="title">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
</template>
<sidebar-item
v-for="child in item.children"
:key="child.path"
:is-nest="true"
:item="child"
:base-path="resolvePath(child.path)"
class="nest-menu"
/>
<sidebar-item v-for="child in item.children" :key="child.path" :is-nest="true" :item="child"
:base-path="resolvePath(child.path)" class="nest-menu" />
</el-submenu>
</div>
</template>
......@@ -50,14 +45,14 @@ export default {
default: ''
}
},
data() {
data () {
// To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
// TODO: refactor with render function
this.onlyOneChild = null
return {}
},
methods: {
hasOneShowingChild(children = [], parent) {
hasOneShowingChild (children = [], parent) {
const showingChildren = children.filter(item => {
if (item.hidden) {
return false
......@@ -75,13 +70,13 @@ export default {
// Show parent if there are no child router to display
if (showingChildren.length === 0) {
this.onlyOneChild = { ... parent, path: '', noShowingChildren: true }
this.onlyOneChild = { ...parent, path: '', noShowingChildren: true }
return true
}
return false
},
resolvePath(routePath) {
resolvePath (routePath) {
if (isExternal(routePath)) {
return routePath
}
......
......@@ -5,9 +5,9 @@
:unique-opened="true" :active-text-color="variables.menuActiveText" :collapse-transition="false"
mode="vertical">
<!-- 权限菜单 -->
<!-- <sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" /> -->
<sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" />
<!-- 菜单全部展示 -->
<sidebar-item v-for="route in asyncRoutes" :key="route.path" :item="route" :base-path="route.path" />
<!-- <sidebar-item v-for="route in asyncRoutes" :key="route.path" :item="route" :base-path="route.path" /> -->
</el-menu>
</el-scrollbar>
</div>
......
......@@ -20,17 +20,16 @@ router.beforeEach(async (to, from, next) => {
next()
} else {
const { result: getMenuData } = await getMenuInfo()
console.log(getMenuData);
// const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData)
// router.addRoutes(accessRoutes)
next()
const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData)
router.addRoutes(accessRoutes)
console.log(router);
next({ ...to, replace: true })
}
NProgress.done()
})
router.afterEach(to => {
// 解决刷新页面报404问题
sessionStorage.setItem('routerTo', to.fullPath)
Cookies.set("routerTo", to.fullPath)
NProgress.done()
})
......
......@@ -25,7 +25,6 @@ export const constantRoutes = [
component: () => import('@/views/error-page/404'),
hidden: true
},
{ path: '*', redirect: '/404', hidden: true },
// 业务流程框架
{
path: '/workFrame',
......@@ -58,7 +57,7 @@ export const asyncRoutes = [
{
path: 'home',
component: () => import('@/views/home/index'),
name: 'Dashboard',
name: 'home',
meta: { title: '工作台', icon: 'workbench', affix: true }
}
]
......@@ -273,7 +272,7 @@ export const asyncRoutes = [
const createRouter = () =>
new Router({
scrollBehavior: () => ({ y: 0 }),
routes: [...constantRoutes, ...asyncRoutes]
routes: [...constantRoutes]
})
const router = createRouter()
......
import { asyncRoutes, constantRoutes, resetRouter } from '@/router'
import asyncRouter from '@/utils/asyncRouter.js'
const state = {
routes: [],
addRoutes: false,
......@@ -8,26 +8,18 @@ const state = {
const mutations = {
SET_ROUTES: (state, routes) => {
state.addRoutes = true
state.routes = constantRoutes.concat(routes)
state.routes = routes
},
RESET_ROUTE: (state) => {
state.addRoutes = false
}
}
const actions = {
// 添加全部菜单
generateRoutes ({ commit }, getMenuInfo) {
return new Promise(resolve => {
// 将路由树数据转成数组结构
let arr1 = []
dfs(_.cloneDeep(asyncRoutes), node => arr1.push(node))
_.each(arr1, i => {
i.parentId = i.parentId ? i.parentId : null
})
let permission_arr = _.intersectionBy(arr1, getMenuInfo, 'name')
// 将权限菜单数组转成路由树数据结构
let permission_tree = array2Tree(permission_arr, null)
let permission_tree = asyncRouter(getMenuInfo)
commit('SET_ROUTES', permission_tree)
resolve(permission_tree)
})
......
import Layout from '@/layout'
export default function filterAsyncRouter (routers) {
routers.forEach(item => {
if (!item.children) {
delete item.children
delete item.redirect
}
if (!item.parentId) {
item.component = Layout
} else {
item.component = loadView(item.uri)
}
item.meta.icon = item.icon
if (item.children) {
item.children = filterAsyncRouter(item.children)
}
})
return routers
}
function loadView (view) {
return r => require.ensure([], () => r(require(`@/views${view}.vue`)))
}
\ No newline at end of file
......@@ -11,9 +11,9 @@ const service = axios.create({
withCredentials: true, //是否允许跨域
headers: {
'Content-Type': 'application/json; charset=utf-8',
// 'Authorization': 'bearer AT-16-oqkOHiUSsDdFA-eAZ49k2rJQDTzQpClO'
'Authorization': 'bearer AT-16-oqkOHiUSsDdFA-eAZ49k2rJQDTzQpClO'
//token列表
'Authorization': 'bearer AT-12-eRKHta5I8ZWftIU86sSyJ8rUkPhMvMJU'
// 'Authorization': 'bearer AT-12-eRKHta5I8ZWftIU86sSyJ8rUkPhMvMJU'
//renc:bearer AT-30-KHB4LXc8-CZXwBEyaFJa9lRmMTc5sHVI
//tianh:bearer AT-33-3zFTGkhQ4eUv4nXvzAmbgN5RPZppzEY6
//zhangh:bearer AT-7-Tx8dlZH0LNRc33UjD1CX1xwa-1D7kQmQ
......