增加权限控制

master
yujialong 1 month ago
parent 15f2ca9b49
commit 86457cbb21
  1. 1
      src/api/index.js
  2. 35
      src/layouts/navbar/index.vue
  3. 7
      src/libs/auth/generateBtnPermission.js
  4. 23
      src/libs/route/addRoutes.js
  5. 8
      src/pages/allocationReview/list/index.vue
  6. 6
      src/plugins/auth/index.js
  7. 2
      src/setting.js

@ -2,6 +2,7 @@ import Setting from '@/setting'
const { apiBaseURL: host } = Setting const { apiBaseURL: host } = Setting
export default { export default {
getUserRolesPermissionMenu: `/users/users/user-role/getUserRolesPermissionMenu`,
getCurrentTime: `/competition/competition/management/getCurrentTime`, getCurrentTime: `/competition/competition/management/getCurrentTime`,
encrypt: `/nakadai/data/encrypt`, encrypt: `/nakadai/data/encrypt`,

@ -36,6 +36,7 @@
<script> <script>
import { mapState, mapActions } from 'vuex' import { mapState, mapActions } from 'vuex'
import Setting from '@/setting' import Setting from '@/setting'
import addRoutes from '@/libs/route/addRoutes'
export default { export default {
data () { data () {
return { return {
@ -70,7 +71,9 @@ export default {
} else if (path.includes('allocationReview/')) { } else if (path.includes('allocationReview/')) {
this.active = '/allocationReview' this.active = '/allocationReview'
} }
this.initMenu() },
mounted () {
localStorage.getItem('review_token') && this.getPer()
}, },
methods: { methods: {
...mapActions('user', [ ...mapActions('user', [
@ -85,26 +88,24 @@ export default {
initMenu () { initMenu () {
// store // store
if (Setting.dynamicRoute) { if (Setting.dynamicRoute) {
const { btns } = this const { btns, defaultMenus: all } = this
const menus = [] console.log("🚀 ~ initMenu ~ btns:", btns)
this.defaultMenus.map(e => { const menus = [all[0]]
if (btns.find(n => n.includes(e.index) || n === e.title)) { btns.find(e => e === '分配评阅任务') && menus.push(all[1])
// btns.find(e => e === '专家管理') && menus.push(all[2])
if (e.subs && e.subs.length) {
const children = []
e.subs.map((j, i) => {
btns.find(n => n.includes(j.index)) && children.push(j)
})
e.subs = children
}
menus.push(e)
}
})
this.menus = menus this.menus = menus
} else { } else {
this.menus = this.defaultMenus this.menus = this.defaultMenus
} }
} },
async getPer () {
const res = await this.$get(this.api.getUserRolesPermissionMenu, {
platformId: 3
})
const routes = res.permissionMenu[0].children.find(e => e.path === '/review') //
routes && addRoutes(routes.children)
this.initMenu()
},
} }
}; };
</script> </script>

@ -6,15 +6,16 @@ import store from '@/store'
const result = [] const result = []
// 递归组合权限 // 递归组合权限
function createAuth(data, auth) { function createAuth (data, auth) {
data.map(e => { data.map(e => {
const text = (auth ? auth + ':' : '') + (auth ? e.name : e.url) // 第一级是路由,取path,子级取name const text = (auth ? auth + ':' : '') + (auth ? e.name : e.name) // 第一级是路由,取path,子级取name
result.push(text) result.push(text)
e.children && e.children.length && createAuth(e.children, text) e.children && e.children.length && createAuth(e.children, text)
}) })
} }
export default function(data) { export default function (data) {
console.log("🚀 ~ data:", data)
createAuth(data) createAuth(data)
store.commit('auth/addBtnAuth', result) store.commit('auth/addBtnAuth', result)
} }

@ -1,28 +1,29 @@
import store from '@/store' import store from '@/store';
import generateBtnPermission from '../auth/generateBtnPermission' import generateBtnPermission from '../auth/generateBtnPermission';
const newRoutes = [] const newRoutes = []
function createMeta(item) { function createMeta (item) {
let meta = { title: item.name } let meta = { title: item.name }
return meta return meta
} }
function createRoute(data) { function createRoute (data) {
data.map(e => { data.map(e => {
const { url } = e if (e.path) {
// 有path则添加到路由里 let meta = createMeta(e)
url && newRoutes.push({ newRoutes.push({
path: url, path: e.path,
meta: createMeta(e) meta
}) })
}
// 递归生成路由集合 // 递归生成路由集合
e.children && e.children.length && createRoute(e.children) e.children && e.children.length && createRoute(e.children)
}) })
} }
export default function(data, path) { export default function (data, path) {
generateBtnPermission(data) generateBtnPermission(data)
// createRoute(data) // createRoute(data)
// store.commit('auth/addRoutes', newRoutes) // store.commit('addRoutes', newRoutes)
} }

@ -56,11 +56,11 @@
<el-table-column label="操作" align="center" width="220" fixed="right"> <el-table-column label="操作" align="center" width="220" fixed="right">
<template slot-scope="scope"> <template slot-scope="scope">
<template v-if="scope.row.seted"> <template v-if="scope.row.seted">
<el-button type="text" @click="toProgress(scope.row)">评阅进度</el-button> <el-button v-auth="'分配评阅任务:评阅进度'" type="text" @click="toProgress(scope.row)">评阅进度</el-button>
<el-button type="text" @click="toSetup(scope.row)">修改评阅设置</el-button> <el-button v-auth="'分配评阅任务:修改评阅设置'" type="text" @click="toSetup(scope.row)">修改评阅设置</el-button>
<el-button type="text" @click="toTask(scope.row)">任务分配</el-button> <el-button v-auth="'分配评阅任务:任务分配'" type="text" @click="toTask(scope.row)">任务分配</el-button>
</template> </template>
<el-button v-else type="text" @click="toSetup(scope.row)">评阅设置</el-button> <el-button v-auth="'分配评阅任务:评阅设置'" v-else type="text" @click="toSetup(scope.row)">评阅设置</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>

@ -7,11 +7,9 @@ import store from '@/store'
import Setting from '@/setting' import Setting from '@/setting'
export default { export default {
inserted(el, binding, vnode) { inserted (el, binding, vnode) {
if (!Setting.dynamicRoute) return false if (!Setting.dynamicRoute) return false
const val = binding.value const text = binding.value
// 如果有传值,判断是否有/,有就说说明传的是完整的值,否则就拿路由拼接传的值;如果没传值,就取按钮名字
const text = val && val.includes('/') ? val : vnode.context.$route.path + ':' + (val || el.innerText)
const { btns } = store.state.auth const { btns } = store.state.auth
if (text && btns && btns.length) { if (text && btns && btns.length) {
// 如果按钮集合里没有该权限,就把该按钮给去除 // 如果按钮集合里没有该权限,就把该按钮给去除

@ -55,7 +55,7 @@ const Setting = {
// 相同路由,不同参数间进行切换,是否强力更新 // 相同路由,不同参数间进行切换,是否强力更新
sameRouteForceUpdate: false, sameRouteForceUpdate: false,
// 是否使用动态路由(即角色权限,开启了的话就会取后端返回的权限树来显示头部导肮和页面按钮) // 是否使用动态路由(即角色权限,开启了的话就会取后端返回的权限树来显示头部导肮和页面按钮)
dynamicRoute: false dynamicRoute: true
}; };
export default Setting; export default Setting;

Loading…
Cancel
Save