diff --git a/package.json b/package.json index 80729110271217cb46e284eaaf40fb839952a42e..7da8af3c4f2b832807ccbccc7fd025657340b545 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "new": "plop" }, "dependencies": { + "@riophae/vue-treeselect": "^0.4.0", "axios": "0.18.1", + "bpmn-js": "^7.2.1", "element-ui": "2.13.0", "js-cookie": "2.2.0", "normalize.css": "7.0.0", @@ -23,9 +25,9 @@ "path-to-regexp": "2.4.0", "screenfull": "4.2.0", "vue": "2.6.10", + "vue-drag-formdesign": "^2.0.10", "vue-router": "3.1.3", "vuex": "3.1.2", - "bpmn-js": "^7.2.1", "xcrud": "0.4.1" }, "devDependencies": { diff --git a/src/api/admin/dept/dept.js b/src/api/admin/dept/dept.js index 3faa0508acac9e69fe393267db5c6c2a87a14758..5cdaae9f81e26523b937bdb4df8c538a9e380bc8 100644 --- a/src/api/admin/dept/dept.js +++ b/src/api/admin/dept/dept.js @@ -46,9 +46,9 @@ export const deleteDeptById = (deptId) => { * @param deptId * @returns {AxiosPromise} */ -export const getDeptTreeTableList = () => { +export const getDeptTreeList = () => { return axios.request({ - url: '/system/dept/getDeptTreeTableList', + url: '/system/dept/getDeptTreeList', method: 'get' }) } diff --git a/src/api/admin/resource/module.js b/src/api/admin/resource/resource.js similarity index 64% rename from src/api/admin/resource/module.js rename to src/api/admin/resource/resource.js index 697bf658c1299137f5f30d3e08256b8f9cabab64..6d12f990bd672ca0518789fd58dce5ac21167346 100644 --- a/src/api/admin/resource/module.js +++ b/src/api/admin/resource/resource.js @@ -7,7 +7,7 @@ import axios from '_l/api.request' */ export const addResource = (module) => { return axios.request({ - url: '/system/resources/save', + url: '/system/resource/save', method: 'post', data: module }) @@ -20,7 +20,7 @@ export const addResource = (module) => { */ export const updateResource = (module) => { return axios.request({ - url: '/system/resources/update', + url: '/system/resource/update', method: 'post', data: module }) @@ -33,7 +33,7 @@ export const updateResource = (module) => { */ export const deleteResourceById = (moduleId) => { return axios.request({ - url: '/system/resources/delete', + url: '/system/resource/delete', method: 'post', params: { id: moduleId @@ -42,25 +42,22 @@ export const deleteResourceById = (moduleId) => { } /** - * 批量删除模块 - * @param moduleIds - * @returns {ClientHttp2Stream | * | AxiosPromise | ClientRequest | void} + * 获取模块tree-table数据 + * @returns {*|AxiosPromise|ClientRequest|void|ClientHttp2Stream} */ -export const deleteBatchResourceById = (moduleIds) => { +export const getResourceTreeList = () => { return axios.request({ - url: '/system/resources/deleteBatch', - method: 'post', - data: moduleIds + url: '/system/resource/getResourceTreeList' }) } /** - * 获取模块tree-table数据 - * @returns {*|AxiosPromise|ClientRequest|void|ClientHttp2Stream} + * 获取菜单列表 + * @returns {AxiosPromise} */ -export const getResourceTreeTableList = () => { +export const getMenuList = () => { return axios.request({ - url: '/system/resources/getResourceTreeTableList' + url: '/system/resource/getMenuList' }) } @@ -68,11 +65,21 @@ export const getResourceTreeTableList = () => { * 获取tree列表数据 * @returns {*|AxiosPromise|ClientRequest|void|ClientHttp2Stream} */ -export const getResourceTreeList = (roleId) => { +export const getResourceIdListByRoleId = (roleId) => { return axios.request({ - url: '/system/resources/getResourceTreeListByRoleId', + url: '/system/resource/getResourceIdListByRoleId', params: { roleId: roleId } }) } + +/** + * 根据登录人获取目录和菜单路由 + * @returns {AxiosPromise} + */ +export const getRouterList = () => { + return axios.request({ + url: '/system/resource/getRouterList' + }) +} diff --git a/src/components/IconSelect/index.vue b/src/components/IconSelect/index.vue new file mode 100644 index 0000000000000000000000000000000000000000..b0ec9fa1a425324ae0bc974bbb0ddb343ff40632 --- /dev/null +++ b/src/components/IconSelect/index.vue @@ -0,0 +1,68 @@ + + + + + + diff --git a/src/components/IconSelect/requireIcons.js b/src/components/IconSelect/requireIcons.js new file mode 100644 index 0000000000000000000000000000000000000000..83a339550e2dd74fb33942e00f520079cf274088 --- /dev/null +++ b/src/components/IconSelect/requireIcons.js @@ -0,0 +1,11 @@ + +const req = require.context('../../icons/svg', false, /\.svg$/) +const requireAll = requireContext => requireContext.keys() + +const re = /\.\/(.*)\.svg/ + +const icons = requireAll(req).map(i => { + return i.match(re)[1] +}) + +export default icons diff --git a/src/icons/svg/Steve-Jobs.svg b/src/icons/svg/Steve-Jobs.svg new file mode 100644 index 0000000000000000000000000000000000000000..53843e2461e59a862d5a570df5f7a8faed859a3f --- /dev/null +++ b/src/icons/svg/Steve-Jobs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/alipay.svg b/src/icons/svg/alipay.svg new file mode 100644 index 0000000000000000000000000000000000000000..9138981301f78765570b1d95bc4f3dfd2c16f24c --- /dev/null +++ b/src/icons/svg/alipay.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/anq.svg b/src/icons/svg/anq.svg new file mode 100644 index 0000000000000000000000000000000000000000..a466608db5f490179f45d48b703995056e9fd8a4 --- /dev/null +++ b/src/icons/svg/anq.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/app.svg b/src/icons/svg/app.svg new file mode 100644 index 0000000000000000000000000000000000000000..0796da351039ad54819ba3daf22a0318443f916a --- /dev/null +++ b/src/icons/svg/app.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/backup.svg b/src/icons/svg/backup.svg new file mode 100644 index 0000000000000000000000000000000000000000..a3272a4697575606c10edc73f455bf1aa6b6d425 --- /dev/null +++ b/src/icons/svg/backup.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/chain.svg b/src/icons/svg/chain.svg new file mode 100644 index 0000000000000000000000000000000000000000..ed3317f4f283a2639f42ff3909c3c23e270636c7 --- /dev/null +++ b/src/icons/svg/chain.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/codeConsole.svg b/src/icons/svg/codeConsole.svg new file mode 100644 index 0000000000000000000000000000000000000000..672ec6e4e34647f0b130775b7849c2f0c0061d25 --- /dev/null +++ b/src/icons/svg/codeConsole.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/database.svg b/src/icons/svg/database.svg new file mode 100644 index 0000000000000000000000000000000000000000..7fbad9b802129a52d43da1bb3211014d1b669fdb --- /dev/null +++ b/src/icons/svg/database.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/date.svg b/src/icons/svg/date.svg new file mode 100644 index 0000000000000000000000000000000000000000..0540e99355605fc600b2444c00bcfb83ab133279 --- /dev/null +++ b/src/icons/svg/date.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/deploy.svg b/src/icons/svg/deploy.svg new file mode 100644 index 0000000000000000000000000000000000000000..f4a1c56e6314367454db0ac23ff62d876abbc81a --- /dev/null +++ b/src/icons/svg/deploy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/dept.svg b/src/icons/svg/dept.svg new file mode 100644 index 0000000000000000000000000000000000000000..894e4bff6cf1d240931ce7acb96a73cbedcc7c95 --- /dev/null +++ b/src/icons/svg/dept.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/dev.svg b/src/icons/svg/dev.svg new file mode 100644 index 0000000000000000000000000000000000000000..ed4d23cf4021f72022fa8f99ff89154c3741b3d6 --- /dev/null +++ b/src/icons/svg/dev.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/develop.svg b/src/icons/svg/develop.svg new file mode 100644 index 0000000000000000000000000000000000000000..e189223dd5bf38ad33c9ba247777f0e4a6abda97 --- /dev/null +++ b/src/icons/svg/develop.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/dictionary.svg b/src/icons/svg/dictionary.svg new file mode 100644 index 0000000000000000000000000000000000000000..6e83c4354041b10fe58a6462e37bcc332b783d3b --- /dev/null +++ b/src/icons/svg/dictionary.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/doc.svg b/src/icons/svg/doc.svg new file mode 100644 index 0000000000000000000000000000000000000000..9160de8c90e741555c03c49caf0f19aa467bf15b --- /dev/null +++ b/src/icons/svg/doc.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/download.svg b/src/icons/svg/download.svg new file mode 100644 index 0000000000000000000000000000000000000000..0243c6a7018bbe021059eea57a902b3a4951b531 --- /dev/null +++ b/src/icons/svg/download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/error.svg b/src/icons/svg/error.svg new file mode 100644 index 0000000000000000000000000000000000000000..fd935da9b74c5409f8ab7ebc25ade45019f43cfd --- /dev/null +++ b/src/icons/svg/error.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/fwb.svg b/src/icons/svg/fwb.svg new file mode 100644 index 0000000000000000000000000000000000000000..59933fc75d3bd95d7df99f4f00c37f578cc28b85 --- /dev/null +++ b/src/icons/svg/fwb.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/github.svg b/src/icons/svg/github.svg new file mode 100644 index 0000000000000000000000000000000000000000..8145e9579fffed0968b5d65485d1d62d2e209b9b --- /dev/null +++ b/src/icons/svg/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/gonggao.svg b/src/icons/svg/gonggao.svg new file mode 100644 index 0000000000000000000000000000000000000000..22aed08fdb0109e3cf651e3322137d5b97588c71 --- /dev/null +++ b/src/icons/svg/gonggao.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/image.svg b/src/icons/svg/image.svg new file mode 100644 index 0000000000000000000000000000000000000000..16d572fd142f092267cc7e199c328627a7088d35 --- /dev/null +++ b/src/icons/svg/image.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/index.svg b/src/icons/svg/index.svg new file mode 100644 index 0000000000000000000000000000000000000000..fdb38269c733c53643a0e95e6f6dd9a5774977fd --- /dev/null +++ b/src/icons/svg/index.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/ipvisits.svg b/src/icons/svg/ipvisits.svg new file mode 100644 index 0000000000000000000000000000000000000000..4ca473d702d9b89069006fb3c9ab4ab01b629e89 --- /dev/null +++ b/src/icons/svg/ipvisits.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/java.svg b/src/icons/svg/java.svg new file mode 100644 index 0000000000000000000000000000000000000000..e2effbbf0a9a46e85cb7b8593b9b52a81e9a5934 --- /dev/null +++ b/src/icons/svg/java.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/log.svg b/src/icons/svg/log.svg new file mode 100644 index 0000000000000000000000000000000000000000..4fefe747c6f4826edd731aacedb70d6f04e8e129 --- /dev/null +++ b/src/icons/svg/log.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/login.svg b/src/icons/svg/login.svg new file mode 100644 index 0000000000000000000000000000000000000000..cc5a854e096abd7011aaa420a2bde03b00811370 --- /dev/null +++ b/src/icons/svg/login.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/markdown.svg b/src/icons/svg/markdown.svg new file mode 100644 index 0000000000000000000000000000000000000000..7cd67475b392ea7ae8dd3f161f452daaaf7f7aec --- /dev/null +++ b/src/icons/svg/markdown.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/menu.svg b/src/icons/svg/menu.svg new file mode 100644 index 0000000000000000000000000000000000000000..e4360a021fa7379b19fe61f1abb08bac68bf15f4 --- /dev/null +++ b/src/icons/svg/menu.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/mnt.svg b/src/icons/svg/mnt.svg new file mode 100644 index 0000000000000000000000000000000000000000..502a7c055febecef0c732bcc7c17f2aecc2a249a --- /dev/null +++ b/src/icons/svg/mnt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/monitor.svg b/src/icons/svg/monitor.svg new file mode 100644 index 0000000000000000000000000000000000000000..fbf0a2f2a7b0493f6cf95dc49bc96d45b0348238 --- /dev/null +++ b/src/icons/svg/monitor.svg @@ -0,0 +1 @@ + diff --git a/src/icons/svg/permission.svg b/src/icons/svg/permission.svg new file mode 100644 index 0000000000000000000000000000000000000000..c4c7409102744dcfb21bad7e84f926cb4b6991b4 --- /dev/null +++ b/src/icons/svg/permission.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/phone.svg b/src/icons/svg/phone.svg new file mode 100644 index 0000000000000000000000000000000000000000..da339f978cce8d69fad98b1d9459dedecbdb4d9f --- /dev/null +++ b/src/icons/svg/phone.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/qiniu.svg b/src/icons/svg/qiniu.svg new file mode 100644 index 0000000000000000000000000000000000000000..c2f9f8b2465c2e1e0bc44bd5291f72e83717f73d --- /dev/null +++ b/src/icons/svg/qiniu.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/redis.svg b/src/icons/svg/redis.svg new file mode 100644 index 0000000000000000000000000000000000000000..bef111b63e238b4b1c22ab927c29823fc817a8e8 --- /dev/null +++ b/src/icons/svg/redis.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/role.svg b/src/icons/svg/role.svg new file mode 100644 index 0000000000000000000000000000000000000000..76cb18ff3a318a3aea2d83705f564a8a59a452ed --- /dev/null +++ b/src/icons/svg/role.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/server.svg b/src/icons/svg/server.svg new file mode 100644 index 0000000000000000000000000000000000000000..db6dcdf59f3b16860de37ff2abbfcc08cb74aa01 --- /dev/null +++ b/src/icons/svg/server.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/source.svg b/src/icons/svg/source.svg new file mode 100644 index 0000000000000000000000000000000000000000..1c3a03805dea252929dc84a9bc55ea456709e465 --- /dev/null +++ b/src/icons/svg/source.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/sqlMonitor.svg b/src/icons/svg/sqlMonitor.svg new file mode 100644 index 0000000000000000000000000000000000000000..950a430d15685be17e5e7a26c93ee36921c1bf92 --- /dev/null +++ b/src/icons/svg/sqlMonitor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/swagger.svg b/src/icons/svg/swagger.svg new file mode 100644 index 0000000000000000000000000000000000000000..ded7de81ac7f9240972ab281b2cfbe2a3dd43caf --- /dev/null +++ b/src/icons/svg/swagger.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/sys-tools.svg b/src/icons/svg/sys-tools.svg new file mode 100644 index 0000000000000000000000000000000000000000..324aa04f219a70fda00f39658dcf59f4c9e591f7 --- /dev/null +++ b/src/icons/svg/sys-tools.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/system.svg b/src/icons/svg/system.svg new file mode 100644 index 0000000000000000000000000000000000000000..9333c60ae8a2e84320923c23536de17634443ae2 --- /dev/null +++ b/src/icons/svg/system.svg @@ -0,0 +1 @@ + diff --git a/src/icons/svg/system1.svg b/src/icons/svg/system1.svg new file mode 100644 index 0000000000000000000000000000000000000000..37b0a0a8d92162373ed9f1da02a1daf1d48d7a09 --- /dev/null +++ b/src/icons/svg/system1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/timing.svg b/src/icons/svg/timing.svg new file mode 100644 index 0000000000000000000000000000000000000000..f8fdc6dd0c51937cbd13969fe7414d8fc6cd497e --- /dev/null +++ b/src/icons/svg/timing.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/tools.svg b/src/icons/svg/tools.svg new file mode 100644 index 0000000000000000000000000000000000000000..aba1a40194abdc09b4532a50b108cc5d0a86669e --- /dev/null +++ b/src/icons/svg/tools.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/unlock.svg b/src/icons/svg/unlock.svg new file mode 100644 index 0000000000000000000000000000000000000000..1219e41d4bc4116cf1f976a9f740a9f436de99ef --- /dev/null +++ b/src/icons/svg/unlock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/user1.svg b/src/icons/svg/user1.svg new file mode 100644 index 0000000000000000000000000000000000000000..14ca51e4e597bceebeab0ca6607f66061ac89e9c --- /dev/null +++ b/src/icons/svg/user1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/validCode.svg b/src/icons/svg/validCode.svg new file mode 100644 index 0000000000000000000000000000000000000000..a1feb74aed70cd04a0c1b2dfe999120cd6001bfc --- /dev/null +++ b/src/icons/svg/validCode.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/visits.svg b/src/icons/svg/visits.svg new file mode 100644 index 0000000000000000000000000000000000000000..8425662dacd43fc161a57b54a717270da4412faf --- /dev/null +++ b/src/icons/svg/visits.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/web.svg b/src/icons/svg/web.svg new file mode 100644 index 0000000000000000000000000000000000000000..9c574156f545c26d7edaaf97558a405d11f51a26 --- /dev/null +++ b/src/icons/svg/web.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/weixin.svg b/src/icons/svg/weixin.svg new file mode 100644 index 0000000000000000000000000000000000000000..8dbcfa5c2abfeb284133f46ff718a70a635a87ae --- /dev/null +++ b/src/icons/svg/weixin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/zujian.svg b/src/icons/svg/zujian.svg new file mode 100644 index 0000000000000000000000000000000000000000..2aba32fc7f971f3cb83948ea500de981d6115b18 --- /dev/null +++ b/src/icons/svg/zujian.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index fb05fe5599a09701437975682d88581c49cf8ada..dbe3b8d3183dbf76850e1467c6a4837b45d2bd1b 100644 --- a/src/main.js +++ b/src/main.js @@ -16,9 +16,20 @@ import router from './router' import './icons' // icon import './permission' // permission control +// 权限指令 +import permission from "@/directive/permission/index"; + import '@/libs/validate.form' import * as filters from './filters' // global filters +import VueDragFormdesign from 'vue-drag-formdesign' +import 'vue-drag-formdesign/lib/vue-drag-formdesign.css' +import VueTreeselect from '@riophae/vue-treeselect' +import '@riophae/vue-treeselect/dist/vue-treeselect.css' + +Vue.use(permission) +Vue.use(VueTreeselect) +Vue.use(VueDragFormdesign) Vue.use(Element, { size: Cookies.get('size') || 'medium' // set element-ui default size }) diff --git a/src/permission.js b/src/permission.js index e2bc0f441250e6be3dfaa987b238578031fcf632..acaa4fe78d1d2cbfa6096d063685ae9dfa3f8b6f 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,16 +1,20 @@ import router from './router' import store from './store' -import { Message } from 'element-ui' +import {Message} from 'element-ui' import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style -import { getToken } from '@/libs/auth' // get token from cookie +import {getToken, removeToken} from '@/libs/auth' // get token from cookie import getPageTitle from '@/libs/get-page-title' +import Layout from '@/layout' +import ParentView from '@/views/parent-view' -NProgress.configure({ showSpinner: false }) // NProgress Configuration +const _import = require('./router/_import_' + process.env.NODE_ENV) // 获取组件的方法 + +NProgress.configure({showSpinner: false}) // NProgress Configuration const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist -router.beforeEach(async(to, from, next) => { +router.beforeEach(async (to, from, next) => { // start progress bar NProgress.start() @@ -23,7 +27,7 @@ router.beforeEach(async(to, from, next) => { if (hasToken) { if (to.path === '/login') { // if is logged in, redirect to the home page - next({ path: '/' }) + next({path: '/'}) NProgress.done() } else { // determine whether the user has obtained his permission roles through getInfo @@ -35,19 +39,22 @@ router.beforeEach(async(to, from, next) => { // get user info // note: roles must be a object array! such as: ['admin'] or ,['developer','editor'] const userInfo = await store.dispatch('user/getInfo') - + await store.dispatch('permission/loadMenu') let roles = userInfo.resources; - - - // generate accessible routes map based on roles - const accessRoutes = await store.dispatch('permission/generateRoutes', roles) - - // dynamically add accessible routes - router.addRoutes(accessRoutes) - - // hack method to ensure that addRoutes is complete - // set the replace: true, so the navigation will not leave a history record - next({ ...to, replace: true }) + if (!roles || roles.length === 0) { + removeToken() + next('/401') + } else { + // 过滤路由 + const accessRoutes = filterAsyncRouter(store.getters.sidebarRouters); + // 添加动态路由 + router.addRoutes(accessRoutes) + // 保存路由 + store.commit('permission/SET_ROUTES', accessRoutes) + // hack method to ensure that addRoutes is complete + // set the replace: true, so the navigation will not leave a history record + next({...to, replace: true}) + } } catch (error) { // remove token and go to login page to re-login await store.dispatch('user/resetToken') @@ -75,3 +82,23 @@ router.afterEach(() => { // finish progress bar NProgress.done() }) + +// 遍历后台传来的路由字符串,转换为组件对象 +function filterAsyncRouter(asyncRouterMap) { + const accessedRouters = asyncRouterMap.filter(route => { + if (route.component) { + if (route.component === 'Layout') { + route.component = Layout + } else if (route.component === 'ParentView') { + route.component = ParentView + } else { + route.component = _import(route.component) // 导入组件 + } + } + if (route.children && route.children.length) { + route.children = filterAsyncRouter(route.children) + } + return true + }) + return accessedRouters +} diff --git a/src/router/_import_development.js b/src/router/_import_development.js new file mode 100644 index 0000000000000000000000000000000000000000..42de012da379a4c0677d5a5541f383c4b54696cc --- /dev/null +++ b/src/router/_import_development.js @@ -0,0 +1,2 @@ +// 开发环境导入组件 +module.exports = file => require('@/views/' + file + '.vue').default // vue-loader at least v13.0.0+ diff --git a/src/router/_import_production.js b/src/router/_import_production.js new file mode 100644 index 0000000000000000000000000000000000000000..796b0dac5127911bfc4814fe2e42af9299dfbb31 --- /dev/null +++ b/src/router/_import_production.js @@ -0,0 +1,2 @@ +// 生产环境导入组件 +module.exports = file => () => import('@/views/' + file + '.vue') diff --git a/src/router/index.js b/src/router/index.js index 7e242a88ec461aca6fe6f5165b634886bd608539..7975249e9cfa5ce886ed0298bd2ee5996461a287 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -121,9 +121,9 @@ export const asyncRoutes = [ meta: {title: '角色管理'} }, { - path: 'power-manage', + path: 'resource-manage', component: () => import('@/views/admin/resource/resource-manage'), - name: 'power-manage', + name: 'resource-manage', meta: {title: '资源管理'} }, { @@ -139,9 +139,9 @@ export const asyncRoutes = [ meta: {title: '岗位管理'} }, { - path: 'dictType-manage', + path: 'dict-manage', component: () => import('@/views/admin/dict/dict-type-manage'), - name: 'dictType-manage', + name: 'dict-manage', meta: {title: '字典管理'} }, { @@ -203,6 +203,12 @@ export const asyncRoutes = [ component: () => import('@/views/flow/process/process-manage'), name: 'process-manage', meta: {title: '流程管理'} + }, + { + path: 'form-manage', + component: () => import('@/views/flow/form/form-manager.vue'), + name: 'form-manage', + meta: {title: '表单管理'} } ] }, diff --git a/src/store/getters.js b/src/store/getters.js index c7625932aed71c7389b99f2ad374f9c09ba7d229..050d54ce63ed194a0ffaa8931f2c8308c3c69c58 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -11,6 +11,7 @@ const getters = { userId: state => state.user.userId, introduction: state => state.user.introduction, roles: state => state.user.roles, - permission_routes: state => state.permission.routes + permission_routes: state => state.permission.routes, + sidebarRouters: state => state.permission.sidebarRouters } export default getters diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index ef3ec905cd3d0b2295957a5dd34b84f90d3d0b62..e76b96eeb3002c9bfecbc0431e6106e57917d823 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -1,4 +1,5 @@ -import { asyncRoutes, constantRoutes } from '@/router' +import {asyncRoutes, constantRoutes} from '@/router' +import {getRouterList} from "@/api/admin/resource/resource"; /** * Use meta.role to determine if the current user has permission @@ -22,7 +23,7 @@ export function filterAsyncRoutes(routes, roles) { const res = [] routes.forEach(route => { - const tmp = { ...route } + const tmp = {...route} if (hasPermission(roles, tmp)) { if (tmp.children) { tmp.children = filterAsyncRoutes(tmp.children, roles) @@ -36,18 +37,22 @@ export function filterAsyncRoutes(routes, roles) { const state = { routes: [], - addRoutes: [] + addRoutes: [], + sidebarRouters: [] } const mutations = { SET_ROUTES: (state, routes) => { state.addRoutes = routes state.routes = constantRoutes.concat(routes) + }, + SET_SIDEBAR_ROUTERS: (state, routers) => { + state.sidebarRouters = routers } } const actions = { - generateRoutes({ commit }, roles) { + generateRoutes({commit}, roles) { return new Promise(resolve => { let accessedRoutes if (roles.includes('ROLE_ADMIN')) { @@ -58,6 +63,18 @@ const actions = { commit('SET_ROUTES', accessedRoutes) resolve(accessedRoutes) }) + }, + loadMenu({commit}) { + return new Promise((resolve, reject) => { + getRouterList().then(res => { + const {data} = res + data.push({ path: '*', redirect: '/404', hidden: true }) + commit('SET_SIDEBAR_ROUTERS', data) + resolve(data) + }).catch(error => { + reject(error) + }) + }) } } diff --git a/src/views/admin/config/config-manage.vue b/src/views/admin/config/config-manage.vue index b5e1eed7d1ff35813f94777c06d77a00147b33f7..d483d543f0d443229104764e90cb50fc1994ef93 100644 --- a/src/views/admin/config/config-manage.vue +++ b/src/views/admin/config/config-manage.vue @@ -8,8 +8,8 @@ 查询 重置 - 添加 - 删除 + 添加 + 删除 @@ -26,8 +26,8 @@ diff --git a/src/views/admin/dept/dept-manage.vue b/src/views/admin/dept/dept-manage.vue index 775bb44b8bd32ed261bde29578aa7d10f9f360fe..05e53bc355a3fff4b90fda934d80d4c70bdc4826 100644 --- a/src/views/admin/dept/dept-manage.vue +++ b/src/views/admin/dept/dept-manage.vue @@ -15,13 +15,14 @@ 查询 重置 + 添加 @@ -46,28 +46,48 @@ :close-on-click-modal="false" @close="handleReset('form')"> - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +