diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 171dbe7..28149ed 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, logout, getInfo, getBizPerm } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, removeCurrentSys } from '@/utils/auth' const user = { state: { @@ -152,6 +152,7 @@ commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() + removeCurrentSys() resolve() }).catch(error => { reject(error) @@ -164,6 +165,7 @@ return new Promise(resolve => { commit('SET_TOKEN', '') removeToken() + removeCurrentSys() resolve() }) } diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 171dbe7..28149ed 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, logout, getInfo, getBizPerm } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, removeCurrentSys } from '@/utils/auth' const user = { state: { @@ -152,6 +152,7 @@ commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() + removeCurrentSys() resolve() }).catch(error => { reject(error) @@ -164,6 +165,7 @@ return new Promise(resolve => { commit('SET_TOKEN', '') removeToken() + removeCurrentSys() resolve() }) } diff --git a/src/utils/auth.js b/src/utils/auth.js index 213f5e6..5cbe390 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -2,6 +2,7 @@ const TokenKey = 'token' const PublicKey = 'public_key' +const CurrentSystem = 'current_system' export function getToken() { return Cookies.get(TokenKey) @@ -27,3 +28,23 @@ return window.localStorage.removeItem(PublicKey) } +export function getCurrentSys() { + let currentSystem = window.localStorage.getItem(CurrentSystem) + if (typeof (currentSystem) === 'undefined') { + return undefined + } else { + currentSystem = JSON.parse(currentSystem) + return currentSystem + } +} + +export function setCurrentSys(currentSystem) { + console.log('in auth setCurrentSys') + const currentSys = JSON.stringify(currentSystem) + return window.localStorage.setItem(CurrentSystem, currentSys) +} + +export function removeCurrentSys() { + return window.localStorage.removeItem(CurrentSystem) +} + diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 171dbe7..28149ed 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, logout, getInfo, getBizPerm } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, removeCurrentSys } from '@/utils/auth' const user = { state: { @@ -152,6 +152,7 @@ commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() + removeCurrentSys() resolve() }).catch(error => { reject(error) @@ -164,6 +165,7 @@ return new Promise(resolve => { commit('SET_TOKEN', '') removeToken() + removeCurrentSys() resolve() }) } diff --git a/src/utils/auth.js b/src/utils/auth.js index 213f5e6..5cbe390 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -2,6 +2,7 @@ const TokenKey = 'token' const PublicKey = 'public_key' +const CurrentSystem = 'current_system' export function getToken() { return Cookies.get(TokenKey) @@ -27,3 +28,23 @@ return window.localStorage.removeItem(PublicKey) } +export function getCurrentSys() { + let currentSystem = window.localStorage.getItem(CurrentSystem) + if (typeof (currentSystem) === 'undefined') { + return undefined + } else { + currentSystem = JSON.parse(currentSystem) + return currentSystem + } +} + +export function setCurrentSys(currentSystem) { + console.log('in auth setCurrentSys') + const currentSys = JSON.stringify(currentSystem) + return window.localStorage.setItem(CurrentSystem, currentSys) +} + +export function removeCurrentSys() { + return window.localStorage.removeItem(CurrentSystem) +} + diff --git a/src/utils/constant.js b/src/utils/constant.js new file mode 100644 index 0000000..3b735da --- /dev/null +++ b/src/utils/constant.js @@ -0,0 +1,2 @@ +// 定义全局常量 +window.systemName = '智慧城管平台' diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 171dbe7..28149ed 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, logout, getInfo, getBizPerm } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, removeCurrentSys } from '@/utils/auth' const user = { state: { @@ -152,6 +152,7 @@ commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() + removeCurrentSys() resolve() }).catch(error => { reject(error) @@ -164,6 +165,7 @@ return new Promise(resolve => { commit('SET_TOKEN', '') removeToken() + removeCurrentSys() resolve() }) } diff --git a/src/utils/auth.js b/src/utils/auth.js index 213f5e6..5cbe390 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -2,6 +2,7 @@ const TokenKey = 'token' const PublicKey = 'public_key' +const CurrentSystem = 'current_system' export function getToken() { return Cookies.get(TokenKey) @@ -27,3 +28,23 @@ return window.localStorage.removeItem(PublicKey) } +export function getCurrentSys() { + let currentSystem = window.localStorage.getItem(CurrentSystem) + if (typeof (currentSystem) === 'undefined') { + return undefined + } else { + currentSystem = JSON.parse(currentSystem) + return currentSystem + } +} + +export function setCurrentSys(currentSystem) { + console.log('in auth setCurrentSys') + const currentSys = JSON.stringify(currentSystem) + return window.localStorage.setItem(CurrentSystem, currentSys) +} + +export function removeCurrentSys() { + return window.localStorage.removeItem(CurrentSystem) +} + diff --git a/src/utils/constant.js b/src/utils/constant.js new file mode 100644 index 0000000..3b735da --- /dev/null +++ b/src/utils/constant.js @@ -0,0 +1,2 @@ +// 定义全局常量 +window.systemName = '智慧城管平台' diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 111d35c..934ac9c 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,44 +1,128 @@ diff --git a/index.html b/index.html index f0f1a0f..9a5a6eb 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - 协同办公子系统 + 智慧城管平台
diff --git a/src/api/login.js b/src/api/login.js index 5d69126..1e7ac52 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -14,11 +14,13 @@ method: 'get' }) } + // 获取用户权限(菜单、按钮) -export function getMenus() { +export function getMenus(params) { return request({ url: '/user/permission', - method: 'get' + method: 'get', + params }) } // 登出 diff --git a/src/icons/svg/icon-cooperate.svg b/src/icons/svg/icon-cooperate.svg new file mode 100644 index 0000000..6602008 --- /dev/null +++ b/src/icons/svg/icon-cooperate.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 48b0cb0..f82fef9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import Vue from 'vue' - import 'normalize.css/normalize.css' // A modern alternative to CSS resets import '../theme/index.css' // 引入自定义主题 import ElementUI from 'element-ui' diff --git a/src/permission.js b/src/permission.js index 75c7e4a..7587ebe 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,9 +1,11 @@ import router from './router' +import { createRouter } from './router' import store from './store' import NProgress from 'nprogress' // progress bar 进度条 import 'nprogress/nprogress.css' // progress bar style 进度条样式 import { Message } from 'element-ui' import { getToken } from '@/utils/auth' // getToken from cookie +import { getCurrentSys } from './utils/auth' NProgress.configure({ showSpinner: false })// NProgress configuration @@ -13,19 +15,30 @@ NProgress.start() // 加载进度条 // 如果有token if (getToken()) { + console.log('to Path:' + to.path) // 登录后进入登录页 if (to.path === '/login') { - next({ path: '/' }) + next({ path: '/login' }) + NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it + } else if (to.path === '/dashboard') { + next() NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - // 当进入非登陆页时 + // 当进入非登陆页或非主页时 if (store.getters.roleList.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetInfo').then(res => { // 拉取用户信息 - // 远程访问获取权限列表(菜单&按钮) - store.dispatch('GetMenus').then(() => { - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record - }) + // 如果已有当前可进入的子系统,刷新子系统菜单 + const currentSys = getCurrentSys() + if (currentSys) { + // 远程访问获取权限列表(菜单&按钮) + store.dispatch('GetMenus', currentSys).then(() => { + store.commit('SET_CHANGEFLAG', '0') + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + }) + } else { // 没有当前子系统信息,跳转到选择子系统页面 + next({ path: '/dashboard' }) + } }).catch((err) => { store.dispatch('FedLogOut').then(() => { Message.error(err || '权限验证失败,请重新登录系统') @@ -33,6 +46,28 @@ }) }) } else { + // console.log('************************') + // console.log(store.getters.changeFlag) + // if (store.getters.changeFlag === '1') { + // console.log('监测到子系统切换:') + // const currentSys = getCurrentSys() + // if (currentSys) { + // // 远程访问获取权限列表(菜单&按钮) + // store.dispatch('GetMenus', currentSys).then(() => { + // debugger + // console.log('========获取菜单成功========') + // store.commit('SET_CHANGEFLAG', '0') + // router.matcher = createRouter().matcher + // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + // console.log(router.routes) + // console.log(to) + // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // // next() // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record + // }) + // } else { // 没有当前子系统信息,跳转到选择子系统页面 + // next({ path: '/dashboard' }) + // } + // } next() } } @@ -40,7 +75,8 @@ if (whiteList.indexOf(to.path) !== -1) { // 免登录白名单,直接进入 next() } else { - next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + // next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 + next('/login') // 否则全部重定向到登录页 NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index 14801a6..058daef 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -49,16 +49,31 @@ // 主页 { path: '/', - component: Layout, - redirect: '/work', + redirect: '/dashboard', name: 'Dashboard', - hidden: true, - children: [{ - path: 'dashboard', - component: () => import('@/views/dashboard/index') - }] + hidden: true + }, + { path: '/dashboard', component: () => import('@/views/dashboard/index'), hidden: true }, + { + path: '/cooperate', + name: 'cooperate', + redirect: '/work', + hidden: true + }, + { + path: '/sys', + name: 'sys', + redirect: '/resource', + hidden: true } ] + +export const createRouter = () => { + return new Router({ + routes: constantRouterMap + }) +} + // 实例化vue的时候直挂载constantRouter export default new Router({ // mode: 'history', //后端支持可开 @@ -66,6 +81,7 @@ routes: constantRouterMap }) + // 异步挂载路由 // 动态需要根据权限加载的路由表 export const asyncRouterMap = [ @@ -247,6 +263,6 @@ // }, ...cooRouters, ...bmsRouters, - systemRouters, + ...systemRouters, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/router/modules/coo.js b/src/router/modules/coo.js index 1c2f04b..0fa4830 100644 --- a/src/router/modules/coo.js +++ b/src/router/modules/coo.js @@ -1,20 +1,31 @@ /* Layout */ import Layout from '../../views/layout/Layout' export const cooRouters = [ + // { + // path: '/cooperate', + // name: 'cooperate', + // redirect: '/work', + // hidden: true, + // meta: { + // title: '协同工作子系统', + // permission: ['/cooperate'] + // } + // }, { path: 'coorBusiness', component: Layout, name: 'CoorBusniess', meta: { title: '协调业务管理', - permission: ['/coorBusiness'] + permission: ['/coorBusiness'], + sys: '/cooperate' }, children: [ { path: '/work', component: () => import('@/views/coorBusiness/work/index'), name: 'Work', - meta: { title: '待办任务', icon: '', permission: '/work' } + meta: { title: '待办任务', icon: '', belongSys: '', permission: '/work' } }, { path: '/toRegister', @@ -132,7 +143,8 @@ name: 'SearchAll', meta: { title: '综合查询', - permission: ['/seo'] + permission: ['/seo'], + sys: '/cooperate' }, children: [ { @@ -149,7 +161,8 @@ name: 'Supervise', meta: { title: '案卷督办', - permission: ['/supervise'] + permission: ['/supervise'], + sys: '/cooperate' }, children: [ { @@ -166,7 +179,7 @@ }, { path: '/allCaseList', - component: () => import('@/views/supervise/overtimeCase'), + component: () => import('@/views/supervise/allCase'), name: 'AllCaseList', meta: { title: '综合查询', icon: '', permission: '/case/queryListPage' } } diff --git a/src/router/modules/system.js b/src/router/modules/system.js index 613f099..eac2b81 100644 --- a/src/router/modules/system.js +++ b/src/router/modules/system.js @@ -1,52 +1,64 @@ /* Layout */ import Layout from '../../views/layout/Layout' -export const systemRouters = { - path: 'system', - component: Layout, - redirect: '/resource', - name: 'System', - alwaysShow: true, - meta: { - title: '系统管理', - icon: 'icon-config', // 图标 - permission: ['/system']// 权限名称 - }, - children: [ - { - path: '/resource', - name: 'Resource', - component: () => import('@/views/system/resource/listResource'), - meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } +export const systemRouters = [ + // { + // path: '/sys', + // name: 'sys', + // redirect: '/resource', + // hidden: true, + // meta: { + // title: '应用维护子系统', + // permission: ['/sys'] + // } + // }, + { + path: 'system', + component: Layout, + redirect: '/resource', + name: 'System', + alwaysShow: true, + meta: { + title: '系统管理', + icon: 'icon-config', // 图标 + permission: ['/system'], // 权限名称 + sys: '/sys' }, - { - path: '/dept', - name: 'Dept', - component: () => import('@/views/system/dept/listDept'), - meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } - }, - { - path: '/role', - component: () => import('@/views/system/role/listRole'), // Parent router-view - name: 'Role', - meta: { title: '角色管理', permission: ['/role'] } - }, - { - path: '/user', - component: () => import('@/views/system/user/listUser'), // Parent router-view - name: 'User', - meta: { title: '用户管理', permission: ['/mgr'] } - }, - { - path: '/log', - component: () => import('@/views/system/log/listLog'), // Parent router-view - name: 'Log', - meta: { title: '日志管理', permission: ['/log'] } - }, - { - path: '/loginLog', - component: () => import('@/views/system/log/loginLog'), // Parent router-view - name: 'LoginLog', - meta: { title: '登录日志', permission: ['/loginLog'] } - } - ] -} + children: [ + { + path: '/resource', + name: 'Resource', + component: () => import('@/views/system/resource/listResource'), + meta: { title: '资源管理', icon: 'function', permission: ['/resource'] } + }, + { + path: '/dept', + name: 'Dept', + component: () => import('@/views/system/dept/listDept'), + meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] } + }, + { + path: '/role', + component: () => import('@/views/system/role/listRole'), // Parent router-view + name: 'Role', + meta: { title: '角色管理', permission: ['/role'] } + }, + { + path: '/user', + component: () => import('@/views/system/user/listUser'), // Parent router-view + name: 'User', + meta: { title: '用户管理', permission: ['/mgr'] } + }, + { + path: '/log', + component: () => import('@/views/system/log/listLog'), // Parent router-view + name: 'Log', + meta: { title: '日志管理', permission: ['/log'] } + }, + { + path: '/loginLog', + component: () => import('@/views/system/log/loginLog'), // Parent router-view + name: 'LoginLog', + meta: { title: '登录日志', permission: ['/loginLog'] } + } + ] } +] diff --git a/src/store/getters.js b/src/store/getters.js index 93860ed..9780358 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -4,6 +4,8 @@ kaptcha: state => state.app.kaptcha, // 验证码 publicKey: state => state.app.publicKey, // 公钥 sid: state => state.app.sid, // 用户标识 + currentSystem: state => state.app.currentSystem, // 用户标识 + changeFlag: state => state.app.changeFlag, // 切换子系统标志 token: state => state.user.token, // token name: state => state.user.name, // 姓名 roleList: state => state.user.roleList, // 角色列表 @@ -12,6 +14,7 @@ deptId: state => state.user.deptId, // 权属单位 deptName: state => state.user.deptName, // 权属单位名称 menus: state => state.permission.menus, // 菜单 + systems: state => state.permission.systems, // 子系统 permission_routers: state => state.permission.routers, // 用户有权限的路由 addRouters: state => state.permission.addRouters, // 添加的路由 btns: state => state.permission.btns, // 用户所有的按钮权限 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c592ba0..b259731 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,6 +1,7 @@ import Cookies from 'js-cookie' import { getConfig } from '@/api/login' import { getPublicKey, setPublicKey } from '../../utils/auth' +import { getCurrentSys, setCurrentSys } from '@/utils/auth' const app = { state: { @@ -9,9 +10,11 @@ withoutAnimation: false }, device: 'desktop', - kaptcha: '', - publicKey: getPublicKey(), - sid: '' + kaptcha: '', // 验证码 + publicKey: getPublicKey(), // 公钥 + sid: '', + currentSystem: getCurrentSys(), // 当前子系统 + changeFlag: '0' // 更换子系统标志,1为更换 0为未更换 }, mutations: { TOGGLE_SIDEBAR: state => { @@ -36,7 +39,15 @@ state.publicKey = config.publicKey state.sid = config.sid setPublicKey(config.publicKey) + }, + SET_SYSTEM: (state, system) => { + state.currentSystem = system + setCurrentSys(system) + }, + SET_CHANGEFLAG: (state, changeFlag) => { + state.changeFlag = changeFlag } + }, actions: { ToggleSideBar: ({ commit }) => { diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index c86845d..f90812b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -71,6 +71,7 @@ state: { routers: constantRouterMap, addRouters: [], + systems: [], // 子系统 menus: [], // 菜单 btns: [] // 按钮 }, @@ -79,6 +80,9 @@ state.addRouters = routers state.routers = constantRouterMap.concat(routers) }, + SET_SYSTEMS: (state, systems) => { + state.systems = Array.from(systems) + }, SET_MENUS: (state, menus) => { state.menus = Array.from(menus) }, @@ -87,18 +91,49 @@ } }, actions: { - // 获取用户权限 - GetMenus({ commit, state }) { - // console.log('in store.permission.js:GetMenus:') + // 获取用户子系统权限 + GetSystems({ commit, state }) { return new Promise((resolve, reject) => { - getMenus(state.token).then(response => { // 处理返回值 + const params = { + resourceType: '02' + } + getMenus(params).then(response => { // 处理返回值 + const data = response.data + const systems = [] // 子系统 + if (data.menus && data.menus.length > 0) { + commit('SET_SYSTEMS', data.menus) + for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 + const menu_tmp = {} + menu_tmp.id = menu.id + menu_tmp.url = menu.url + menu_tmp.icon = menu.icon + menu_tmp.name = menu.name + systems.push(menu_tmp) + } + } + resolve(response) + }).catch(error => { + reject(error) + }) + }) + }, + // 获取用户权限 + GetMenus({ commit, state }, currentSystem) { + // console.log('in store.permission.js:GetMenus:') + console.log('获取' + currentSystem.name + '的菜单') + return new Promise((resolve, reject) => { + // const params = { + // parentCode: currentSystem.code + // } + getMenus().then(response => { // 处理返回值 const data = response.data const menus = [] // 仅菜单 const btns = [] // 非菜单 if (data.menus && data.menus.length > 0) { - commit('SET_MENUS', data.menus) - for (const menu of data.menus) { // 遍历菜单,获取所有的权限项 - if (menu.ismenu === '1') { // 将是菜单的放入menus + const allmenus = [...data.menus] + commit('SET_MENUS', allmenus) + for (const menu of allmenus) { // 遍历菜单,获取所有的权限项 + if (menu.resourceType === '02' || menu.resourceType === '03') { // 将是菜单的放入menus const menu_tmp = {} menu_tmp.url = menu.url menu_tmp.icon = menu.icon diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 171dbe7..28149ed 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, logout, getInfo, getBizPerm } from '@/api/login' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, removeCurrentSys } from '@/utils/auth' const user = { state: { @@ -152,6 +152,7 @@ commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() + removeCurrentSys() resolve() }).catch(error => { reject(error) @@ -164,6 +165,7 @@ return new Promise(resolve => { commit('SET_TOKEN', '') removeToken() + removeCurrentSys() resolve() }) } diff --git a/src/utils/auth.js b/src/utils/auth.js index 213f5e6..5cbe390 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -2,6 +2,7 @@ const TokenKey = 'token' const PublicKey = 'public_key' +const CurrentSystem = 'current_system' export function getToken() { return Cookies.get(TokenKey) @@ -27,3 +28,23 @@ return window.localStorage.removeItem(PublicKey) } +export function getCurrentSys() { + let currentSystem = window.localStorage.getItem(CurrentSystem) + if (typeof (currentSystem) === 'undefined') { + return undefined + } else { + currentSystem = JSON.parse(currentSystem) + return currentSystem + } +} + +export function setCurrentSys(currentSystem) { + console.log('in auth setCurrentSys') + const currentSys = JSON.stringify(currentSystem) + return window.localStorage.setItem(CurrentSystem, currentSys) +} + +export function removeCurrentSys() { + return window.localStorage.removeItem(CurrentSystem) +} + diff --git a/src/utils/constant.js b/src/utils/constant.js new file mode 100644 index 0000000..3b735da --- /dev/null +++ b/src/utils/constant.js @@ -0,0 +1,2 @@ +// 定义全局常量 +window.systemName = '智慧城管平台' diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 111d35c..934ac9c 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,44 +1,128 @@ diff --git a/src/views/layout/components/AppHeader.vue b/src/views/layout/components/AppHeader.vue index 4b26091..0701d5c 100644 --- a/src/views/layout/components/AppHeader.vue +++ b/src/views/layout/components/AppHeader.vue @@ -1,8 +1,15 @@