Browse Source

优化权限展示

master
李磊 3 years ago
parent
commit
a838655fb2
  1. 2
      .env.production
  2. 2
      .env.test
  3. 3
      src/directive/permission/permission.js
  4. 29
      src/views/user/role.vue

2
.env.production

@ -22,4 +22,4 @@ VUE_APP_SJ_API = 'http://${VUE_APP_SJ_BASE_IP_ADDRESS}:9092/SJSE/'
VUE_APP_PREVIEW_API = '${VUE_APP_SERVER_API}/sdma-preview/' VUE_APP_PREVIEW_API = '${VUE_APP_SERVER_API}/sdma-preview/'
# websocket连接地址 # websocket连接地址
VUE_APP_WEBSOCKET = 'ws://${VUE_APP_SERVER_ADDRESS}/sdma-websocket/websocket/' VUE_APP_WEBSOCKET = 'ws://${VUE_APP_SERVER_ADDRESS}:9100/sdma-websocket/websocket/'

2
.env.test

@ -22,4 +22,4 @@ VUE_APP_SJ_API = 'http://${VUE_APP_SJ_BASE_IP_ADDRESS}:9092/SJSE/'
VUE_APP_PREVIEW_API = '${VUE_APP_SERVER_API}/sdma-preview/' VUE_APP_PREVIEW_API = '${VUE_APP_SERVER_API}/sdma-preview/'
# websocket连接地址 # websocket连接地址
VUE_APP_WEBSOCKET = 'ws://${VUE_APP_SERVER_ADDRESS}/sdma-websocket/websocket/' VUE_APP_WEBSOCKET = 'ws://${VUE_APP_SERVER_ADDRESS}:9100/sdma-websocket/websocket/'

3
src/directive/permission/permission.js

@ -4,7 +4,6 @@ export default {
inserted(el, binding, vnode) { inserted(el, binding, vnode) {
const { value } = binding const { value } = binding
const roles = store.getters && store.getters.permissions const roles = store.getters && store.getters.permissions
console.log(roles)
if (value && value instanceof Array && value.length > 0) { if (value && value instanceof Array && value.length > 0) {
const permissionRoles = value const permissionRoles = value
const hasPermission = roles.some(role => { const hasPermission = roles.some(role => {
@ -17,4 +16,4 @@ export default {
throw new Error(`need roles! Like v-permission="['admin','editor']"`) throw new Error(`need roles! Like v-permission="['admin','editor']"`)
} }
} }
} }

29
src/views/user/role.vue

@ -52,7 +52,7 @@
<el-table-column label="功能选项"> <el-table-column label="功能选项">
<template v-if="scope.row.children.length === 0" slot-scope="scope"> <template v-if="scope.row.children.length === 0" slot-scope="scope">
<el-checkbox <el-checkbox
v-for="options in scope.row.resourcePermissionList" v-for="options in scope.row.resourcePermissions"
:key="options.id" :key="options.id"
v-model="options.checked" v-model="options.checked"
:label="options.permissionType" :label="options.permissionType"
@ -154,6 +154,7 @@ export default {
}, },
getRoleMenuList(roleId) { getRoleMenuList(roleId) {
getPermissionsByRoleId(roleId).then(data => { getPermissionsByRoleId(roleId).then(data => {
data = data.map(row => row.resourcePermissionId)
this.menuList.forEach(permission => { this.menuList.forEach(permission => {
if (permission.children.length > 0) { if (permission.children.length > 0) {
this.echoChildren(permission.children, data) this.echoChildren(permission.children, data)
@ -167,14 +168,14 @@ export default {
// //
if (val.children.length > 0) { if (val.children.length > 0) {
if (checked) { if (checked) {
this.checkedIds.add(val.resourcePermissionList[0].id) this.checkedIds.add(val.resourcePermissions[0].id)
} else { } else {
this.checkedIds.delete(val.resourcePermissionList[0].id) this.checkedIds.delete(val.resourcePermissions[0].id)
} }
this.findChildren(val.children, checked) this.findChildren(val.children, checked)
} else { } else {
// //
val.resourcePermissionList.forEach(options => { val.resourcePermissions.forEach(options => {
options.checked = checked options.checked = checked
if (checked) { if (checked) {
this.checkedIds.add(options.id) this.checkedIds.add(options.id)
@ -190,9 +191,9 @@ export default {
val.indeterminate = false val.indeterminate = false
}, },
handleCheckChange(val) { handleCheckChange(val) {
const length = val.resourcePermissionList.length const length = val.resourcePermissions.length
let checkedLength = 0 let checkedLength = 0
val.resourcePermissionList.forEach(options => { val.resourcePermissions.forEach(options => {
if (options.checked) { if (options.checked) {
this.checkedIds.add(options.id) this.checkedIds.add(options.id)
checkedLength++ checkedLength++
@ -211,7 +212,7 @@ export default {
list.forEach(children => { list.forEach(children => {
children.checked = checked children.checked = checked
children.indeterminate = false children.indeterminate = false
children.resourcePermissionList.forEach(options => { children.resourcePermissions.forEach(options => {
options.checked = checked options.checked = checked
if (checked) { if (checked) {
this.checkedIds.add(options.id) this.checkedIds.add(options.id)
@ -240,10 +241,12 @@ export default {
}) })
result.checked = parentCheckedLength === result.children.length result.checked = parentCheckedLength === result.children.length
result.indeterminate = (parentIndeterminateLength > 0 || parentCheckedLength > 0) && parentCheckedLength < result.children.length result.indeterminate = (parentIndeterminateLength > 0 || parentCheckedLength > 0) && parentCheckedLength < result.children.length
if (result.checked || result.indeterminate) { if (result.permission.component !== 'Layout') {
this.checkedIds.add(result.resourcePermissionList[0].id) if (result.checked || result.indeterminate) {
} else { this.checkedIds.add(result.resourcePermissions[0].id)
this.checkedIds.delete(result.resourcePermissionList[0].id) } else {
this.checkedIds.delete(result.resourcePermissions[0].id)
}
} }
// //
if (result.permission.pid !== 0) { if (result.permission.pid !== 0) {
@ -265,7 +268,7 @@ export default {
}, },
settingChecked(result, optionsIds) { settingChecked(result, optionsIds) {
let matching = false let matching = false
result.resourcePermissionList.forEach(options => { result.resourcePermissions.forEach(options => {
optionsIds.forEach(optionsId => { optionsIds.forEach(optionsId => {
if (options.id === optionsId) { if (options.id === optionsId) {
options.checked = true options.checked = true
@ -282,7 +285,7 @@ export default {
menuList.forEach(permission => { menuList.forEach(permission => {
permission.checked = false permission.checked = false
permission.indeterminate = false permission.indeterminate = false
permission.resourcePermissionList.forEach(options => { permission.resourcePermissions.forEach(options => {
options.checked = false options.checked = false
}) })
if (permission.children.length > 0) { if (permission.children.length > 0) {

Loading…
Cancel
Save