提交 20df7690 authored 作者: 王鹏飞's avatar 王鹏飞

新增权限控制

上级 ddc37847
......@@ -53,3 +53,8 @@ export function checkCode(params) {
export function chooseRole(data) {
return httpRequest.post('/api/zy/user/choose-role', data)
}
// 获取所有权限
export function getPermissions() {
return httpRequest.get('/api/zy/user/get-permissions')
}
......@@ -10,7 +10,7 @@
</div>
<el-menu class="nav" :unique-opened="true" :default-active="activeLink">
<template v-for="item in currentMenus">
<el-submenu :index="item.title" :key="item.title" v-if="item.children">
<el-submenu :index="item.title" :key="item.title" v-show="menuVisible(item.tag)" v-if="item.children">
<template #title>
<i class="iconfont" :class="item.icon"></i><span>{{ item.title }}</span>
</template>
......@@ -19,6 +19,7 @@
:key="item.title"
v-for="item in item.children"
@click="handleClick(item.path, item)"
v-show="menuVisible(item.tag)"
>
<template #title>
<template v-if="item.href">
......@@ -29,7 +30,13 @@
</el-menu-item>
</el-submenu>
<el-menu-item :index="item.path" :key="item.title" @click="handleClick(item.path)" v-else>
<el-menu-item
:index="item.path"
:key="item.title"
@click="handleClick(item.path)"
v-show="menuVisible(item.tag)"
v-else
>
<i class="iconfont" :class="item.icon"></i>
<span slot="title">{{ item.title }}</span>
</el-menu-item>
......@@ -54,23 +61,26 @@ export default {
activeLink: '/course/learn',
studentMenus: [
{
tag: 'menu_course',
title: '我的课程',
icon: 'icon-bianzu6-hong',
children: [{ title: '课程学习', path: '/course/learn' }]
children: [{ tag: 'menu_course_learn', title: '课程学习', path: '/course/learn' }]
},
{
tag: 'menu_exam',
title: '模拟考试',
icon: 'icon-bianzuhong',
children: [
{ title: '模拟考试', path: '/testExam' },
{ title: '错题集合', path: '/my/questions/wrong' },
{ title: '收藏试题', path: '/my/questions/collection' }
{ tag: 'menu_exam_index', title: '模拟考试', path: '/testExam' },
{ tag: 'menu_exam_wq', title: '错题集合', path: '/my/questions/wrong' },
{ tag: 'menu_exam_cq', title: '收藏试题', path: '/my/questions/collection' }
]
},
{
tag: 'menu_training',
title: '实训练习',
icon: 'icon-kaoshihong',
children: [{ title: '实训案例练习', path: xtrainingUrl, href: xtrainingUrl }]
children: [{ tag: 'menu_tranining_test', title: '实训案例练习', path: xtrainingUrl, href: xtrainingUrl }]
}
],
techerMenus: [
......@@ -83,24 +93,27 @@ export default {
// ]
// },
{
tag: 'menu_course',
title: '课程中心',
icon: 'icon-bianzu6-hong',
children: [{ title: '课程库', path: '/course/learn' }]
children: [{ tag: 'menu_course_learn', title: '课程库', path: '/course/learn' }]
},
{
tag: 'menu_exam',
title: '模拟考试',
icon: 'icon-bianzuhong',
children: [
{ title: '考卷批阅', path: '/teacher/exam' },
{ title: '习题批阅', path: '/teacher/test' }
{ tag: 'menu_exam_paper_review', title: '考卷批阅', path: '/teacher/exam' },
{ tag: 'menu_exam_exercise_review', title: '习题批阅', path: '/teacher/test' }
]
},
{
tag: 'menu_training',
title: '实训资源',
icon: 'icon-kaoshihong',
children: [
// { title: '实训课程库', path: '/teacher/practicalCourse' },
{ title: '实训课程库', path: xtrainingUrl, href: xtrainingUrl }
{ tag: 'menu_tranining_test', title: '实训课程库', path: xtrainingUrl, href: xtrainingUrl }
]
}
// {
......@@ -115,21 +128,23 @@ export default {
],
defaultMenus: [
{
tag: 'menu_my',
title: '个人中心',
icon: 'icon-guanlizhongxinbeifen-hong',
children: [
{ title: '个人信息', path: '/account' },
{ title: '修改密码', path: '/account/password' },
{ title: '安全设置', path: '/account/safe' }
{ tag: 'menu_my_info', title: '个人信息', path: '/account' },
{ tag: 'menu_my_password', title: '修改密码', path: '/account/password' },
{ tag: 'menu_my_safe', title: '安全设置', path: '/account/safe' }
]
},
{
tag: 'menu_help',
title: '帮助与反馈',
icon: 'icon-bianzu8-hong',
children: [
{ title: '服务专区', path: '/contact' },
{ title: '系统说明', path: '/doc' },
{ title: '常见问题', path: '/help' }
{ tag: 'menu_help_services', title: '服务专区', path: '/contact' },
{ tag: 'menu_help_system', title: '系统说明', path: '/doc' },
{ tag: 'menu_help_qa', title: '常见问题', path: '/help' }
]
}
]
......@@ -145,10 +160,22 @@ export default {
: this.studentMenus.concat(this.defaultMenus)
},
user() {
return this.$store.state.user
return this.$store.state.user || {}
},
avatar() {
return this.user.avatar || defaultAvatar
},
// 菜单权限
menuPermissions() {
// role: 1学生,2老师
// system_tag: 2教师,3学生
return this.$store.state.permissions.filter(item => {
if (this.user.role === 2) {
return item.system_tag === 2
} else {
return item.system_tag === 3
}
})
}
},
watch: {
......@@ -160,6 +187,12 @@ export default {
}
},
methods: {
menuVisible(tag) {
if (!tag) {
return true
}
return !!this.menuPermissions.find(item => item.tag === tag)
},
genClasses(data) {
const isActive = this.$route.fullPath.includes(data.path)
return { 'is-active': isActive }
......
import Vue from 'vue'
import Vuex from 'vuex'
import { getUser, logout, getIsVip, createGuestUser } from '@/api/account'
import { getUser, logout, getIsVip, createGuestUser, getPermissions } from '@/api/account'
Vue.use(Vuex)
const store = new Vuex.Store({
......@@ -12,7 +12,8 @@ const store = new Vuex.Store({
isIos: /iphone|ipad|ipod/i.test(navigator.userAgent),
isAndroid: /android/i.test(navigator.userAgent),
isWeapp: /miniProgram/.test(navigator.userAgent),
guestUser: { user_id: '', student_id: '' }
guestUser: { user_id: '', student_id: '' },
permissions: []
},
mutations: {
setUser(state, user) {
......@@ -30,6 +31,9 @@ const store = new Vuex.Store({
setGuestUser(state, user) {
state.guestUser = user
window.localStorage.setItem('guestUser', JSON.stringify(user))
},
setPermissions(state, permissions) {
state.permissions = permissions
}
},
actions: {
......@@ -87,13 +91,23 @@ const store = new Vuex.Store({
}
}
commit('setGuestUser', guestUser)
},
// 获取所有权限列表
getPermissions({ commit }) {
getPermissions({ type: 1 }).then(res => {
if (res.data && res.data.items) {
commit('setPermissions', res.data.items)
}
})
}
}
})
export default store
store.dispatch('getPermissions')
// 加载本地游客用户
// store.dispatch('loadGuestUser')
// 检测是否付费
// store.dispatch('checkIsVip')
export default store
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论