diff --git a/src/api/paperLevel.js b/src/api/paperLevel.js new file mode 100644 index 0000000..d2ec01a --- /dev/null +++ b/src/api/paperLevel.js @@ -0,0 +1,33 @@ +import request from '@/utils/request' +export default { + deletepaperLevel(id) { + return request({ + url: `/paperLevel/Delete?ids=${id}`, + method: 'post' + }); + }, +} + +export function getpaperLevel(params) { + return request({ + url: `/paperLevel/Get`, + method: 'get', + params + }) +} + +export function GetpaperLevelList(params) { + return request({ + url: `/paperLevel/List`, + method: 'get', + params + }) +} +// 修改 | 保存 +export function Save(params) { + return request({ + url: `/paperLevel/Update`, + method: 'post', + data: params + }) +} \ No newline at end of file diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index 76575cb..5b17e3c 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -34,7 +34,8 @@ export default { }, computed: { ...mapGetters([ - 'sidebar' + 'sidebar', + 'permissions' ]), // routes() { // return this.$router.options.routes @@ -59,10 +60,10 @@ export default { return !this.sidebar.opened } }, - created() { - this.routes = getRoutes(); + created() { + this.routes = getRoutes(this.permissions); this.$bus.$on('relogin',()=>{ - this.routes = getRoutes(); + this.routes = getRoutes(this.permissions); }) }, } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index bada1e0..9f04008 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -16,7 +16,8 @@ const getDefaultState = () => { return { token: getToken(), name: '', - avatar: '' + avatar: '', + permissions: [] } } @@ -40,6 +41,9 @@ const mutations = { state.userInfo = val localStorage.userinfo = JSON.stringify(val) }, + setPermissions(state, permissions) { + state.permissions = permissions; + }, } const actions = { @@ -60,7 +64,7 @@ const actions = { data } = response commit('SET_TOKEN', data.token) - commit('SET_USERINFO', data.data) + // commit('SET_USERINFO', data.data) setToken(data.token) resolve() }).catch(error => { @@ -77,7 +81,7 @@ const actions = { return new Promise((resolve, reject) => { getInfo().then(response => { const { - data + data,permissions } = response.data if (!data) { return reject('Verification failed, please Login again.') @@ -88,6 +92,8 @@ const actions = { } = data commit('SET_NAME', DisplayName) commit('SET_AVATAR', avatar) + // commit("setPermissions", permissions); + commit('SET_USERINFO', data) resolve(data) }).catch(error => { reject(error) diff --git a/src/utils/routerList.js b/src/utils/routerList.js index 5c57165..71efe4a 100644 --- a/src/utils/routerList.js +++ b/src/utils/routerList.js @@ -2,15 +2,19 @@ import Layout from '@/layout' import { getInfo } from '../store/modules/user.js' -export function getRoutes() { - +export function getRoutes(permissions) { let userInfo = {} if (localStorage.userinfo) { userInfo = JSON.parse(localStorage.userinfo) } + var permissions = userInfo.permissions || []; + + + + console.log(userInfo) let constantRoutes1 = [] - if (userInfo.UserId == 1) { + if (userInfo.UserId == 1 || 1 == 1) { constantRoutes1 = [{ path: '/login', component: () => @@ -67,7 +71,8 @@ export function getRoutes() { name: 'Example', meta: { title: '题库管理', - icon: 'el-icon-s-help' + icon: 'el-icon-s-help', + permissions: ['admin'] }, children: [{ path: 'QuestionBank', @@ -76,7 +81,8 @@ export function getRoutes() { import('@/views/QuestionBank/index'), meta: { title: '题库', - icon: 'table' + icon: 'table', + permissions: ['admin'] } },] }, @@ -199,7 +205,7 @@ export function getRoutes() { name: 'user', meta: { title: '用户管理', - icon: 'el-icon-s-help' + icon: 'el-icon-s-help' }, children: [{ path: 'user', @@ -230,18 +236,14 @@ export function getRoutes() { title: '图片导入用户', } }, - - - - { path: 'admin', name: 'admin', - component: () => import('@/views/user/adminList'), meta: { title: '管理员列表', + permissions: ['admin'] } }, @@ -259,46 +261,50 @@ export function getRoutes() { { path: 'userdimset', name: 'impouserdimsetrtuser', - + component: () => import('@/views/user/userdimset'), meta: { title: '维度规则设置', + permissions:['admin' ] } }, { - path: 'index', - name: 'index', - component: () => - import('@/views/password/index'), - meta: { - title: '忘记密码', - } - }, { - path: 'TestPaperClass', - name: 'Table', - component: () => - import('@/views/TestPaper/TestPaperClass'), - meta: { - title: '分类管理', - } - }, { - path: 'carousel', - name: 'carousel', - component: () => - import('@/views/carousel/index'), - meta: { - title: '轮播图', - } - }, { - path: 'new', - name: 'new', - component: () => - import('@/views/carousel/new'), - meta: { - title: '最新资讯', - } - }] + path: 'index', + name: 'index', + component: () => + import('@/views/password/index'), + meta: { + title: '忘记密码', + } + }, { + path: 'TestPaperClass', + name: 'Table', + component: () => + import('@/views/TestPaper/TestPaperClass'), + meta: { + title: '分类管理', + permissions:['admin' ] + } + }, { + path: 'carousel', + name: 'carousel', + component: () => + import('@/views/carousel/index'), + meta: { + title: '轮播图', + permissions:['admin' ] + } + }, { + path: 'new', + name: 'new', + component: () => + import('@/views/carousel/new'), + meta: { + title: '最新资讯', + permissions:['admin'] + } + }] }, // 404 page must be placed at the end !!! { @@ -308,6 +314,7 @@ export function getRoutes() { } ] } else { + return ; constantRoutes1 = [{ path: '/login', component: () => @@ -329,7 +336,8 @@ export function getRoutes() { name: 'Example', meta: { title: '题库管理', - icon: 'el-icon-s-help' + icon: 'el-icon-s-help', + permissions: ["admin", "user"], }, children: [{ path: 'QuestionBank', @@ -481,8 +489,7 @@ export function getRoutes() { meta: { title: '人才库', } - }, - + } ] }, { @@ -492,7 +499,8 @@ export function getRoutes() { name: 'password', meta: { title: '系统管理', - icon: 'el-icon-s-platform' + icon: 'el-icon-s-platform', + permissions:['admin','user'] }, children: [{ path: 'index', @@ -509,6 +517,7 @@ export function getRoutes() { import('@/views/TestPaper/TestPaperClass'), meta: { title: '分类管理', + permissions: ['admin'] } }, { path: 'carousel', @@ -517,6 +526,7 @@ export function getRoutes() { import('@/views/carousel/index'), meta: { title: '轮播图', + permissions: ['admin'] } }, { path: 'new', @@ -525,6 +535,7 @@ export function getRoutes() { import('@/views/carousel/new'), meta: { title: '最新资讯', + permissions: ['admin'] } }] }, @@ -538,5 +549,29 @@ export function getRoutes() { } + function hasPermission(permissions, route) { + if (route.meta && route.meta.permissions) { + return permissions.some((role) => route.meta.permissions.includes(role)); + } else { + return true; + } + } + + + function filterAsyncRoutes(routes, permissions) { + const finallyRoutes = []; + routes.forEach((route) => { + const item = { ...route }; + if (hasPermission(permissions, item)) { + if (item.children) { + item.children = filterAsyncRoutes(item.children, permissions); + } + finallyRoutes.push(item); + } + }); + return finallyRoutes; + } + constantRoutes1 = filterAsyncRoutes(constantRoutes1, permissions); + return constantRoutes1; } \ No newline at end of file diff --git a/src/views/TestPaper/ManualTestPaper.vue b/src/views/TestPaper/ManualTestPaper.vue index 05b4007..bb7d9a9 100644 --- a/src/views/TestPaper/ManualTestPaper.vue +++ b/src/views/TestPaper/ManualTestPaper.vue @@ -84,7 +84,12 @@ - + + + + + @@ -135,10 +140,15 @@