增加权限控制

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

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

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

@ -8,13 +8,14 @@ const result = []
// 递归组合权限
function createAuth (data, auth) {
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)
e.children && e.children.length && createAuth(e.children, text)
})
}
export default function (data) {
console.log("🚀 ~ data:", data)
createAuth(data)
store.commit('auth/addBtnAuth', result)
}

@ -1,5 +1,5 @@
import store from '@/store'
import generateBtnPermission from '../auth/generateBtnPermission'
import store from '@/store';
import generateBtnPermission from '../auth/generateBtnPermission';
const newRoutes = []
@ -10,12 +10,13 @@ function createMeta(item) {
function createRoute (data) {
data.map(e => {
const { url } = e
// 有path则添加到路由里
url && newRoutes.push({
path: url,
meta: createMeta(e)
if (e.path) {
let meta = createMeta(e)
newRoutes.push({
path: e.path,
meta
})
}
// 递归生成路由集合
e.children && e.children.length && createRoute(e.children)
})
@ -24,5 +25,5 @@ function createRoute(data) {
export default function (data, path) {
generateBtnPermission(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">
<template slot-scope="scope">
<template v-if="scope.row.seted">
<el-button type="text" @click="toProgress(scope.row)">评阅进度</el-button>
<el-button 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="toProgress(scope.row)">评阅进度</el-button>
<el-button v-auth="'分配评阅任务:修改评阅设置'" type="text" @click="toSetup(scope.row)">修改评阅设置</el-button>
<el-button v-auth="'分配评阅任务:任务分配'" type="text" @click="toTask(scope.row)">任务分配</el-button>
</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>
</el-table-column>
</el-table>

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

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

Loading…
Cancel
Save