diff --git a/package.json b/package.json index ceb4be080059effe5038cdeabe137dcd18bf48bb..8c470e890ca99076e7377e2a42e6a05db0a6e655 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "new": "plop" }, "dependencies": { + "@riophae/vue-treeselect": "^0.4.0", "axios": "0.18.1", "element-ui": "2.13.0", "js-cookie": "2.2.0", diff --git a/src/api/admin/resource/module.js b/src/api/admin/resource/resource.js similarity index 60% rename from src/api/admin/resource/module.js rename to src/api/admin/resource/resource.js index daafa114f161ffe24412403240e30152ba9533c5..26284680a8b421e3d2dbb05986d8c0cbf15349d2 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-center/system/resources/save', + url: '/system-center/system/resource/save', method: 'post', data: module }) @@ -20,7 +20,7 @@ export const addResource = (module) => { */ export const updateResource = (module) => { return axios.request({ - url: '/system-center/system/resources/update', + url: '/system-center/system/resource/update', method: 'post', data: module }) @@ -33,7 +33,7 @@ export const updateResource = (module) => { */ export const deleteResourceById = (moduleId) => { return axios.request({ - url: '/system-center/system/resources/delete', + url: '/system-center/system/resource/delete', method: 'post', params: { id: moduleId @@ -41,38 +41,47 @@ 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-center/system/resources/deleteBatch', - method: 'post', - data: moduleIds + url: '/system-center/system/resource/getResourceTreeList' }) } /** - * 获取模块tree-table数据 - * @returns {*|AxiosPromise|ClientRequest|void|ClientHttp2Stream} + * 获取菜单列表 + * @returns {AxiosPromise} */ -export const getResourceTreeTableList = () => { +export const getMenuList = () => { return axios.request({ - url: '/system-center/system/resources/getResourceTreeTableList' + url: '/system-center/system/resource/getMenuList' }) } + /** * 获取tree列表数据 * @returns {*|AxiosPromise|ClientRequest|void|ClientHttp2Stream} */ -export const getResourceTreeList = (roleId) => { +export const getResourceIdListByRoleId = (roleId) => { return axios.request({ - url: '/system-center/system/resources/getResourceTreeListByRoleId', + url: '/system-center/system/resource/getResourceIdListByRoleId', params: { roleId: roleId } }) } + +/** + * 根据登录人获取目录和菜单路由 + * @returns {AxiosPromise} + */ +export const getRouterList = () => { + return axios.request({ + url: '/system-center/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/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue deleted file mode 100644 index ef21f195e9199d5d7abc873fc9bd03d9ce273c1d..0000000000000000000000000000000000000000 --- a/src/components/TreeSelect/index.vue +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - 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/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index fb014a23fa97acd98634e7fe5baa5193e764c530..5b577973cd9c7390e638b18d3109643bd37c647f 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -7,7 +7,7 @@ :collapse="isCollapse" :background-color="variables.menuBg" :text-color="variables.menuText" - :unique-opened="false" + :unique-opened="true" :active-text-color="variables.menuActiveText" :collapse-transition="false" mode="vertical" diff --git a/src/main.js b/src/main.js index fb05fe5599a09701437975682d88581c49cf8ada..5738fee7394d8d07b81809b079b7d11939591550 100644 --- a/src/main.js +++ b/src/main.js @@ -16,9 +16,12 @@ 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 +Vue.use(permission) Vue.use(Element, { size: Cookies.get('size') || 'medium' // set element-ui default size }) diff --git a/src/permission.js b/src/permission.js index fef1315b05fea6c955f173ef265371ee448a7b30..1b53828517362c299a4fde998a0bfcc115877f6e 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, removeToken } 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', '/404', '/401'] // 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,22 +39,23 @@ 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; - if(!roles || roles.length === 0){ + if (!roles || roles.length === 0) { removeToken() next('/401') } else { - console.log('roles=', roles); - // generate accessible routes map based on roles - const accessRoutes = await store.dispatch('permission/generateRoutes', roles) - - // dynamically add accessible routes + console.log(111) + // 过滤路由 + 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 }) + next({...to, replace: true}) } } catch (error) { // remove token and go to login page to re-login @@ -79,3 +84,24 @@ 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/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..9ff00cb5404a80da3239d7e815c0a696700e8ddb 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -1,4 +1,5 @@ import { asyncRoutes, constantRoutes } from '@/router' +import {getRouterList} from "@/api/admin/resource/resource"; /** * Use meta.role to determine if the current user has permission @@ -36,13 +37,17 @@ 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 } } @@ -58,6 +63,19 @@ 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) + console.log(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 628089e453b2ad4acd6fc81030832438140e6a12..102c0cba2a12200821cbde4809b6e7bb8ac41c58 100644 --- a/src/views/admin/config/config-manage.vue +++ b/src/views/admin/config/config-manage.vue @@ -8,8 +8,10 @@ 查询 重置 - 添加 - 删除 + 添加 + 删除 + @@ -22,12 +24,12 @@ @table-select-val="selectVal"> @@ -65,171 +67,163 @@