Browse Source

优化角色权限编辑页面

master
李磊 3 years ago
parent
commit
adeba4f549
  1. 2
      src/components/Crud/crud.js
  2. 8
      src/main.js
  3. 40
      src/styles/index.scss
  4. 102
      src/views/user/role.vue

2
src/components/Crud/crud.js

@ -291,7 +291,7 @@ function CRUD(options) {
if (!delAll) { if (!delAll) {
dataStatus.delete = CRUD.STATUS.PROCESSING dataStatus.delete = CRUD.STATUS.PROCESSING
} }
return crud.crudMethod.del(delAll ? { idArray: ids } : singleId).then(() => { return crud.crudMethod.del(delAll ? { ids: ids } : singleId).then(() => {
if (!delAll) { if (!delAll) {
dataStatus.delete = CRUD.STATUS.PREPARED dataStatus.delete = CRUD.STATUS.PREPARED
} }

8
src/main.js

@ -31,6 +31,9 @@ import adaptive from './directive/el-table'
import vueqr from 'vue-qr' import vueqr from 'vue-qr'
import JSONView from 'vue-json-viewer' import JSONView from 'vue-json-viewer'
import { checkPermission } from './utils/permission' import { checkPermission } from './utils/permission'
import Cookies from 'js-cookie'
Vue.use(JSONView) Vue.use(JSONView)
Vue.use(permission) Vue.use(permission)
@ -49,7 +52,10 @@ Vue.use(CellGroup)
Vue.use(Cell) Vue.use(Cell)
Vue.use(Col) Vue.use(Col)
Vue.use(ElementUI, { locale }) Vue.use(ElementUI, {
locale,
size: Cookies.get('size') || 'small' // set element-ui default size
})
// 全局的常量 // 全局的常量
Vue.prototype.checkPermission = checkPermission Vue.prototype.checkPermission = checkPermission

40
src/styles/index.scss

@ -87,7 +87,45 @@ a:hover {
} }
.app-container { .app-container {
padding: 5px 20px; padding: 20px 20px 5px 20px;
}
.components-container {
margin: 30px 50px;
position: relative;
}
.filter-container {
padding-bottom: 10px;
.filter-item {
display: inline-block;
vertical-align: middle;
margin-bottom: 10px;
}
}
.head-container {
padding-bottom: 10px;
.filter-item {
display: inline-block;
vertical-align: middle;
margin: 0 3px 10px 0;
}
.el-button+.el-button {
margin-left: 0 !important;
}
.el-select__caret.el-input__icon.el-icon-arrow-up{
line-height: 30.5px;
}
.date-item {
display: inline-block;
vertical-align: middle;
margin-bottom: 10px;
height: 30.5px;
width: 223px !important;
}
} }
fieldset { fieldset {

102
src/views/user/role.vue

@ -18,8 +18,10 @@
</CustomTable> </CustomTable>
<pagination /> <pagination />
<!--弹出框内容--> <!--弹出框内容-->
<el-dialog <el-drawer
width="80%" ref="roleDrawer"
direction="rtl"
size="90%"
:before-close="crud.cancelCU" :before-close="crud.cancelCU"
:visible="crud.status.editor > 0" :visible="crud.status.editor > 0"
:title="crud.status.title" :title="crud.status.title"
@ -33,14 +35,15 @@
</el-form-item> </el-form-item>
<el-form-item label="功能权限:"> <el-form-item label="功能权限:">
<el-table <el-table
ref="menuList" ref="permissions"
:data="menuList" :data="permissions"
border border
fit fit
height="680"
highlight-current-row highlight-current-row
row-key="permission.id" row-key="permission.id"
:default-expand-all="true"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
style="width: 99%;"
> >
<el-table-column label="菜单名称" width="400"> <el-table-column label="菜单名称" width="400">
<template slot-scope="scope"> <template slot-scope="scope">
@ -63,15 +66,27 @@
</el-table> </el-table>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <el-row :gutter="20">
<el-button @click="crud.cancelCU"> <el-col :span="4" :offset="2">
<el-select v-model="showMode" @change="changeShowMode">
</el-button> <el-option
v-for="(item, index) in showModes"
:key="index"
:label="item"
:value="index"
/>
</el-select>
</el-col>
<el-col :span="4" :offset="14">
<el-button type="primary" @click="crud.submitCU"> <el-button type="primary" @click="crud.submitCU">
</el-button> </el-button>
</div> <el-button @click="crud.cancelCU">
</el-dialog>
</el-button>
</el-col>
</el-row>
</el-drawer>
</div> </div>
</template> </template>
@ -98,7 +113,7 @@ const defaultForm = form({
id: null, id: null,
roleName: '', roleName: '',
roleCode: '', roleCode: '',
menuOptionIds: {} resourcePermissionIds: {}
}) })
export default { export default {
@ -107,7 +122,7 @@ export default {
mixins: [defaultCrud, defaultForm, header()], mixins: [defaultCrud, defaultForm, header()],
data() { data() {
return { return {
menuList: [], permissions: [],
colConfigs: [ colConfigs: [
{ prop: 'roleName', label: '角色名称', align: 'center' }, { prop: 'roleName', label: '角色名称', align: 'center' },
{ prop: 'roleCode', label: '角色代码', align: 'center' }, { prop: 'roleCode', label: '角色代码', align: 'center' },
@ -126,7 +141,9 @@ export default {
{ required: true, message: '请输入角色代码', trigger: 'blur' } { required: true, message: '请输入角色代码', trigger: 'blur' }
] ]
}, },
checkedIds: new Set() checkedIds: new Set(),
showMode: 0,
showModes: ['合并所有', '展开所有', '全部勾选', '取消勾选']
} }
}, },
mounted() { mounted() {
@ -135,7 +152,7 @@ export default {
methods: { methods: {
// //
[CRUD.HOOK.afterToCU]() { [CRUD.HOOK.afterToCU]() {
this.clearChecked(this.menuList) this.clearChecked(this.permissions)
this.checkedIds.clear() this.checkedIds.clear()
}, },
// //
@ -144,18 +161,55 @@ export default {
}, },
// //
[CRUD.HOOK.afterValidateCU]() { [CRUD.HOOK.afterValidateCU]() {
this.form.menuOptionIds = Array.from(this.checkedIds) this.form.resourcePermissionIds = Array.from(this.checkedIds)
},
/**
* 改变展示方式
*/
changeShowMode(val) {
switch (val) {
case 0:
this.permissions.forEach(row => {
setTimeout(() => {
this.$refs.permissions.toggleRowExpansion(row, false)
}, 1000)
})
break
case 1:
this.permissions.forEach(row => {
setTimeout(() => {
this.$refs.permissions.toggleRowExpansion(row, true)
}, 1000)
})
break
case 2:
this.permissions.forEach(row => {
row.checked = true
row.indeterminate = false
this.handleCheckAllChange(row, true)
})
break
case 3:
this.permissions.forEach(row => {
row.checked = false
row.indeterminate = false
this.handleCheckAllChange(row, false)
})
break
default:
break
}
}, },
// //
getAllMenu() { getAllMenu() {
getTree().then(data => { getTree().then(data => {
this.menuList = data this.permissions = data
}) })
}, },
getRoleMenuList(roleId) { getRoleMenuList(roleId) {
getPermissionsByRoleId(roleId).then(data => { getPermissionsByRoleId(roleId).then(data => {
data = data.map(row => row.resourcePermissionId) data = data.map(row => row.resourcePermissionId)
this.menuList.forEach(permission => { this.permissions.forEach(permission => {
if (permission.children.length > 0) { if (permission.children.length > 0) {
this.echoChildren(permission.children, data) this.echoChildren(permission.children, data)
} else { } else {
@ -167,11 +221,13 @@ export default {
handleCheckAllChange(val, checked) { handleCheckAllChange(val, checked) {
// //
if (val.children.length > 0) { if (val.children.length > 0) {
if (val.resourcePermissions.length) {
if (checked) { if (checked) {
this.checkedIds.add(val.resourcePermissions[0].id) this.checkedIds.add(val.resourcePermissions[0].id)
} else { } else {
this.checkedIds.delete(val.resourcePermissions[0].id) this.checkedIds.delete(val.resourcePermissions[0].id)
} }
}
this.findChildren(val.children, checked) this.findChildren(val.children, checked)
} else { } else {
// //
@ -186,7 +242,7 @@ export default {
} }
// //
if (val.permission.pid !== 0) { if (val.permission.pid !== 0) {
this.findParent(this.menuList, val.permission.pid) this.findParent(this.permissions, val.permission.pid)
} }
val.indeterminate = false val.indeterminate = false
}, },
@ -205,7 +261,7 @@ export default {
val.indeterminate = checkedLength > 0 && checkedLength < length val.indeterminate = checkedLength > 0 && checkedLength < length
// //
if (val.permission.pid !== 0) { if (val.permission.pid !== 0) {
this.findParent(this.menuList, val.permission.pid) this.findParent(this.permissions, val.permission.pid)
} }
}, },
findChildren(list, checked) { findChildren(list, checked) {
@ -250,7 +306,7 @@ export default {
} }
// //
if (result.permission.pid !== 0) { if (result.permission.pid !== 0) {
this.findParent(this.menuList, result.permission.pid) this.findParent(this.permissions, result.permission.pid)
} }
} else if (result.children.length > 0) { } else if (result.children.length > 0) {
this.findParent(result.children, pid) this.findParent(result.children, pid)
@ -281,8 +337,8 @@ export default {
} }
}, },
// //
clearChecked(menuList) { clearChecked(permissions) {
menuList.forEach(permission => { permissions.forEach(permission => {
permission.checked = false permission.checked = false
permission.indeterminate = false permission.indeterminate = false
permission.resourcePermissions.forEach(options => { permission.resourcePermissions.forEach(options => {

Loading…
Cancel
Save