| | |
| | | <div style="margin-left: 8px;">角色名称</div> |
| | | </div> |
| | | |
| | | <div style="margin-right:10px"> |
| | | <i class="el-icon-plus" style="cursor: pointer;color: #999" @click="rolePlusClick" /> |
| | | </div> |
| | | <!-- <div style="margin-right:10px">--> |
| | | <!-- <i class="el-icon-plus" style="cursor: pointer;color: #999" @click="rolePlusClick" />--> |
| | | <!-- </div>--> |
| | | |
| | | </div> |
| | | |
| | |
| | | :props="defaultPropsLeft" |
| | | :default-expand-all="true" |
| | | :expand-on-click-node="false" |
| | | draggable |
| | | :allow-drop="treeLeftAllowDrop" |
| | | @node-click="treeLeftNodeClick" |
| | | > |
| | | <span slot-scope="{ node, data }" class="custom-tree-node"> |
| | | <span v-if="!data.isEdit">{{ node.label }}</span> |
| | | <input |
| | | v-if="data.isEdit" |
| | | :ref="data.code" |
| | | v-model="data.name" |
| | | type="text" |
| | | @click.stop |
| | | @blur="roleSave(data)" |
| | | @keyup.enter="roleSave(data)" |
| | | > |
| | | |
| | | <span v-if="!data.isEdit&&data.identifying!=='0'&&data.identifying!=='1'"> |
| | | <i |
| | | v-if="data.code!=='000'" |
| | | class="el-icon-edit" |
| | | style="margin-right:10px;color: #999" |
| | | @click.stop="val=>roleEditClick(val,node,data)" |
| | | /> |
| | | <i |
| | | v-if="data.code!=='000'" |
| | | class="el-icon-delete" |
| | | style="margin-right: 4px;color: #999" |
| | | @click.stop="val=>roleDeleteClick(val,node,data)" |
| | | /> |
| | | </span> |
| | | </span> |
| | | </el-tree> |
| | | /> |
| | | <!-- draggable--> |
| | | <!-- :allow-drop="treeLeftAllowDrop"--> |
| | | </div> |
| | | |
| | | <div |
| | | style="margin-left: 10px;width:100%;position: relative" |
| | | style="margin-left: 10px;width: calc(100% - 300px);position: relative" |
| | | > |
| | | |
| | | <el-button |
| | | style="position: absolute;right: 15px;z-index:1;top:3px" |
| | | type="primary" |
| | | :loading="$store.state.app.buttonIsDisabled" |
| | | :disabled="$store.state.app.buttonIsDisabled" |
| | | @click="saveClick" |
| | | >保 存 |
| | | </el-button> |
| | |
| | | <el-tabs v-model="activeName" type="border-card"> |
| | | <el-tab-pane label="PC端" name="PC"> |
| | | <div style="display: flex;"> |
| | | |
| | | <div |
| | | ref="scrollLeft" |
| | | style="border-right: 1px solid rgba(0,0,0,0.2);width: 200px; |
| | | style="border-right: 1px solid rgba(0,0,0,0.2);width:260px; |
| | | overflow-y: auto;overflow-x:hidden;" |
| | | :style="{height:(tableHeight-40)+'px'}" |
| | | @scroll="scrollLeftScroll()" |
| | |
| | | @node-click="getLeftTreeNode" |
| | | /> |
| | | </div> |
| | | |
| | | <div |
| | | ref="scrollCenter" |
| | | style="border-right: 1px solid rgba(0,0,0,0.2);width: 660px;padding-left: 10px;overflow-y: auto" |
| | | style="width: calc(100% - 260px );padding-left: 10px;overflow-y: auto" |
| | | :style="{height:(tableHeight-40)+'px'}" |
| | | @scroll="scrollCenterScroll()" |
| | | @mouseover="isScroll='center'" |
| | |
| | | <el-checkbox |
| | | v-model="buttonIsChecked" |
| | | style="height: 26px;display:flex;align-items: center;margin-top:10px;width:200px" |
| | | @change="val=>handleCheckAllChange(val,'button')" |
| | | @change=" handleCheckAllChange " |
| | | >全选 |
| | | </el-checkbox> |
| | | |
| | |
| | | :key="it.menucode" |
| | | v-model="it.buttonChecked" |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | @change="val=>handleCheckedButtonChange(val,index,it.menucode,it.buttonChecked)" |
| | | @change="val=>handleCheckedButtonChange(val,it.menucode,it.buttonChecked)" |
| | | > |
| | | |
| | | <el-checkbox |
| | |
| | | </div> |
| | | |
| | | </div> |
| | | |
| | | <div |
| | | ref="scrollRight" |
| | | style="width: 360px;padding-left: 10px;overflow-y: auto" |
| | | :style="{height:(tableHeight-40)+'px',}" |
| | | @scroll="scrollRightScroll()" |
| | | @mouseover="isScroll='right'" |
| | | > |
| | | <div style=" "> |
| | | <i class="el-icon-s-operation" :style="{color:$store.state.settings.theme}" /> 数据权限 |
| | | </div> |
| | | |
| | | <el-checkbox |
| | | v-model="dataIsChecked" |
| | | style="height: 26px;display:flex;align-items: center;margin-top:10px;width:200px" |
| | | @change="val=>handleCheckAllChange(val,'data')" |
| | | >全选 |
| | | </el-checkbox> |
| | | |
| | | <div v-if="treeCenter.length>0"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.menucode"> |
| | | <div |
| | | v-if="!item.datacodelist" |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | /> |
| | | |
| | | <el-radio-group |
| | | v-for="it in item.children" |
| | | v-if="item.expanded" |
| | | :key="it.menucode" |
| | | v-model="it.dataChecked" |
| | | style="margin-left: 40px;height:26px;display: flex" |
| | | @change="val=>handleCheckedDataChange(val,it.menucode)" |
| | | > |
| | | <el-radio |
| | | v-for="i in it.datacodelist" |
| | | :key="i" |
| | | style="display:flex;align-items: center" |
| | | :label="i" |
| | | /> |
| | | </el-radio-group> |
| | | </div> |
| | | |
| | | </div> |
| | | |
| | | </div> |
| | | |
| | | </div> |
| | | </el-tab-pane> |
| | | <el-tab-pane label="APP端" name="APP">大大</el-tab-pane> |
| | | <el-tab-pane label="APP端" name="APP">APP端</el-tab-pane> |
| | | <el-tab-pane label="工控端" name="工控端">工控端</el-tab-pane> |
| | | </el-tabs> |
| | | |
| | |
| | | <script> |
| | | import waves from '@/directive/waves' |
| | | import { |
| | | RoleAddUpdateSava, RoleDeleteSava, |
| | | RolePermissionSava, |
| | | RolePermissionSearchRole, |
| | | RolePermissionSearchRoleMenu, |
| | | RolePermissionSearchRoleMenuButton |
| | | } from '@/api/basicSettings' |
| | | import arrayToTree from 'array-to-tree' |
| | | import { throttle } from '@/utils/debounceAndThrottle' |
| | | import { DataPermissions } from '@/api/GeneralBasicData' |
| | | |
| | | export default { |
| | | name: 'RoleList', |
| | |
| | | activeName: 'PC', |
| | | |
| | | buttonIsChecked: false, |
| | | dataIsChecked: false, |
| | | |
| | | menuCheckedCodeArr: [], // 菜单权限数组选中的 |
| | | |
| | |
| | | |
| | | isScroll: 'left', |
| | | |
| | | dataKeyValue: []// 数据权限键值对 |
| | | ButtonData: JSON.parse(localStorage.getItem('ButtonData')) |
| | | |
| | | } |
| | | }, |
| | | watch: { |
| | | treeLeft: { |
| | | handler(newValue, oldValue) { |
| | | newValue[0].roles.forEach(i => { |
| | | if (i.isEdit) { |
| | | this.$nextTick(() => { |
| | | this.$refs[i.code].focus() |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | deep: true |
| | | } |
| | | }, |
| | | |
| | | created() { |
| | | |
| | | }, |
| | | mounted() { |
| | | window.addEventListener('resize', this.getHeight) |
| | |
| | | // 获取角色权限查询角色 |
| | | async getRolePermissionSearchRole() { |
| | | const { data: res } = await RolePermissionSearchRole() |
| | | res[0].roles.forEach(i => { |
| | | i.isEdit = false |
| | | }) |
| | | |
| | | this.treeLeft = res |
| | | |
| | | let rolecode = '' |
| | | if (window.location.hash.indexOf('?') !== -1) { |
| | | rolecode = window.location.hash.split('?')[1].split('=')[1] |
| | | } |
| | | |
| | | if (res && res.length > 0) { |
| | | this.$nextTick(() => { // 默认选中第一个 |
| | | this.$refs.treeLeftRef.setCurrentKey(res[0].roles[0].code) // 默认选中节点第一个 |
| | | this.$refs.treeLeftRef.setCurrentKey(rolecode || res[0].code) // 默认选中节点第一个 |
| | | }) |
| | | |
| | | await this.getDataPermissions()// 获取数据权限键值对 |
| | | await this.getRolePermissionSearchRoleMenuButton(res[0].roles[0].code)// 用于数据回显 |
| | | await this.getRolePermissionSearchRoleMenuButton(rolecode || res[0].code)// 用于数据回显 |
| | | |
| | | await this.getRolePermissionSearchRoleMenu(res[0].roles[0].code)// 用于渲染页面 |
| | | await this.getRolePermissionSearchRoleMenu(rolecode || res[0].code)// 用于渲染页面 |
| | | } else { |
| | | this.$notify.error('请先建相对应的角色!') |
| | | } |
| | | }, |
| | | async getDataPermissions() { |
| | | const { data: res } = await DataPermissions() |
| | | this.dataKeyValue = res |
| | | }, |
| | | |
| | | // 获取菜单权限对应的按钮 |
| | |
| | | item.children.forEach(it => { |
| | | it.buttoncodelist = it.buttoncodelist !== '' && it.buttoncodelist !== null ? it.buttoncodelist.split(',') : [] |
| | | if (it.buttoncodelist && it.buttoncodelist.length > 0) { |
| | | it.buttoncodelist = this.$ButtonData.filter(j => |
| | | it.buttoncodelist = this.ButtonData.filter(j => |
| | | it.buttoncodelist.includes(j.buttoncode) |
| | | ) |
| | | |
| | | it.buttoncodelist = it.buttoncodelist.map(j => j.buttonname) |
| | | } |
| | | |
| | | it.datacodelist = it.datacodelist ? it.datacodelist.split(',') : [] |
| | | if (it.datacodelist && it.datacodelist.length > 0) { |
| | | it.datacodelist = this.dataKeyValue.filter(j => |
| | | it.datacodelist.includes(j.datacode) |
| | | ).map(j => j.dataname) |
| | | } |
| | | }) |
| | | |
| | |
| | | let temp = this.allButtonData.filter(j => j.menucode === it.menucode).length > 0 ? this.allButtonData.filter(j => j.menucode === it.menucode)[0].buttoncode : [] |
| | | temp = temp.length > 0 ? temp.split(',') : [] |
| | | it.buttonChecked = [] // 数据回显 |
| | | this.$ButtonData.forEach(j => { |
| | | this.ButtonData.forEach(j => { |
| | | if (temp.includes(j.buttoncode)) { |
| | | it.buttonChecked.push(j.buttonname) |
| | | } |
| | | }) |
| | | |
| | | const datacode = this.allButtonData.filter(j => j.menucode === it.menucode).length > 0 ? this.allButtonData.filter(j => j.menucode === it.menucode)[0].datacode : '' |
| | | it.dataChecked = datacode ? this.dataKeyValue.find(j => j.datacode === datacode).dataname : '' // 数据回显 |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | this.handleCheckedButtonChange('', '', '', '', true) |
| | | this.handleCheckedDataChange('', '', true) |
| | | this.handleCheckedButtonChange('', '', '', true) |
| | | // this.$forceUpdate() |
| | | }, |
| | | |
| | |
| | | scrollLeftScroll() { |
| | | if (this.isScroll === 'left') { |
| | | this.$refs.scrollCenter.scrollTop = this.$refs.scrollLeft.scrollTop |
| | | this.$refs.scrollRight.scrollTop = this.$refs.scrollLeft.scrollTop |
| | | } |
| | | }, |
| | | // 中间边滚动条滑动时 |
| | | scrollCenterScroll() { |
| | | if (this.isScroll === 'center') { |
| | | this.$refs.scrollLeft.scrollTop = this.$refs.scrollCenter.scrollTop |
| | | this.$refs.scrollRight.scrollTop = this.$refs.scrollCenter.scrollTop |
| | | } |
| | | }, |
| | | // 右侧滚动条滑动时 |
| | | scrollRightScroll() { |
| | | if (this.isScroll === 'right') { |
| | | this.$refs.scrollLeft.scrollTop = this.$refs.scrollRight.scrollTop |
| | | this.$refs.scrollCenter.scrollTop = this.$refs.scrollRight.scrollTop |
| | | } |
| | | }, |
| | | |
| | | // 全选改变 |
| | | handleCheckAllChange(val, belong) { |
| | | handleCheckAllChange(val) { |
| | | const checkedKeys = this.$refs.treeCenterRef.getCheckedKeys() |
| | | |
| | | if (val) { |
| | |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (checkedKeys.includes(it.menucode)) { |
| | | if (belong === 'button') { |
| | | it.buttonChecked = it.buttoncodelist |
| | | } |
| | | if (belong === 'data') { |
| | | it.dataChecked = '全部' |
| | | } |
| | | it.buttonChecked = it.buttoncodelist |
| | | } |
| | | }) |
| | | } |
| | |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (checkedKeys.includes(it.menucode)) { |
| | | if (belong === 'button') { |
| | | it.buttonChecked = [] |
| | | } |
| | | if (belong === 'data') { |
| | | it.dataChecked = '' |
| | | } |
| | | it.buttonChecked = [] |
| | | } |
| | | }) |
| | | } |
| | |
| | | } |
| | | }, |
| | | // 单个按钮改变 |
| | | handleCheckedButtonChange(oldValue, index, code, newValue, flag) { |
| | | // console.log(oldValue, index, code, newValue, 2) |
| | | handleCheckedButtonChange(oldValue, code, newValue, flag) { |
| | | // console.log(oldValue, code, newValue, 2) |
| | | // 判断是否包含在内 |
| | | if (!flag) { |
| | | if (!this.menuCheckedCodeArr.includes(code) && oldValue.length === 0 && newValue.length === 1) { // 否 |
| | | this.menuCheckedCodeArr.push(code) |
| | | } else if (this.menuCheckedCodeArr.includes(code) && oldValue.length === 1 && newValue.length === 0) { // 是 |
| | | // 当数据权限未勾选时则过滤掉相对应的菜单 |
| | | if (this.treeCenter[0].children[index].children.find(i => i.menucode === code).dataChecked.toString().length < 1) { |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== code) |
| | | } |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== code) |
| | | } |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | } |
| | |
| | | |
| | | if (checkedKeys.length === 0) { // 树形菜单全不选的情况下 |
| | | this.buttonIsChecked = false |
| | | this.dataIsChecked = false |
| | | this.menuCheckedCodeArr = [] |
| | | } else { |
| | | if (checkedKeys.includes(obj.menucode)) { // 判断是否包含在内 //是 |
| | |
| | | if (!selfChildrenTreeCheck) { |
| | | if (!selfChecked) { // 从选中到不选中 |
| | | obj.buttonChecked = [] |
| | | obj.dataChecked = '' |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== obj.menucode) |
| | | } |
| | | if (selfChecked) { // 从不选中到选中 |
| | |
| | | this.$forceUpdate() |
| | | } |
| | | }, |
| | | // 单选框按钮改变 |
| | | handleCheckedDataChange(value, code, flag) { |
| | | // console.log(value, code) |
| | | if (!flag) { |
| | | this.menuCheckedCodeArr.push(code) |
| | | this.menuCheckedCodeArr = [...new Set(this.menuCheckedCodeArr)] |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | } |
| | | // 这里是判断全选radio 是否选中 |
| | | let count = 0 |
| | | let childrenLength = 0 |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.dataChecked.length > 0 && it.datacodelist.length > 0) { |
| | | count++ |
| | | } |
| | | // console.log(it.dataChecked, 234) |
| | | if (it.datacodelist.length > 0) { |
| | | childrenLength++ |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | // console.log(count, childrenLength, 123) |
| | | this.dataIsChecked = count === childrenLength |
| | | this.$forceUpdate() |
| | | }, |
| | | // 角色切换 |
| | | async treeLeftNodeClick(obj, Node, VueComponent) { |
| | | if (obj.code !== '000') { |
| | | await this.getRolePermissionSearchRoleMenuButton(obj.code) |
| | | // await this.getRolePermissionSearchRoleMenu(obj.code) |
| | | this.handleData() |
| | | } |
| | | }, |
| | | // 角色名称新增 |
| | | rolePlusClick() { |
| | | this.treeLeft[0].roles.push({ code: '', name: '', isEdit: true }) |
| | | }, |
| | | // 角色名称修改 |
| | | roleEditClick(self, node, data) { |
| | | // console.log(self, node, data) |
| | | this.treeLeft[0].roles.forEach(i => { |
| | | i.isEdit = false |
| | | }) |
| | | data.isEdit = !data.isEdit |
| | | }, |
| | | // 角色名称删除 |
| | | roleDeleteClick(self, node, data) { |
| | | // console.log(self, node, data) |
| | | this.$confirm('是否确认删除?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(() => { |
| | | const D = { |
| | | rolecode: data.code, |
| | | rolename: data.name, |
| | | type: this.activeName |
| | | } |
| | | RoleDeleteSava(D).then(res => { |
| | | if (res.code === '200') { |
| | | this.$notify.success('角色删除成功!') |
| | | } |
| | | this.getRolePermissionSearchRole() |
| | | }) |
| | | }).catch(() => { |
| | | this.$notify.info('已取消删除') |
| | | }) |
| | | }, |
| | | // 角色名称保存 采用防抖形式 |
| | | roleSave: throttle(function(val) { |
| | | val.isEdit = false |
| | | |
| | | if (val.name.trim().length === 0) { |
| | | this.getRolePermissionSearchRole() |
| | | return this.$notify.info('无效保存!') |
| | | } |
| | | |
| | | const data = { |
| | | rolecode: val.code, |
| | | rolename: val.name, |
| | | type: val.code === '' ? 'Add' : 'Update' |
| | | } |
| | | console.log(data, '执行了!') |
| | | RoleAddUpdateSava(data).then(res => { |
| | | if (res.code === '200') { |
| | | this.$notify.success(val.code === '' ? '角色新增成功!' : '角色修改成功!') |
| | | } |
| | | }) |
| | | this.getRolePermissionSearchRole() |
| | | }, 1000, true), |
| | | |
| | | // 页面勾选好保存事件 |
| | | async saveClick() { |
| | | const rolecode = this.$refs.treeLeftRef.getCurrentKey() |
| | | const datacode = this.treeLeft.find(i => i.code === rolecode).datarange !== 'CUSTOM' ? this.treeLeft.find(i => i.code === rolecode).datarange : this.treeLeft.find(i => i.code === rolecode).datapermissions |
| | | const menuKeyArr = this.$refs.treeCenterRef.getCheckedKeys() |
| | | const arr = [] |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (menuKeyArr.includes(it.menucode)) { |
| | | if (it.buttoncodelist.length > 0 && it.buttoncodelist && it.dataChecked && it.dataChecked.toString().length > 0) { // 数据权限已勾选 |
| | | it.dataCheckedCode = this.dataKeyValue.find(i => i.dataname === it.dataChecked).datacode |
| | | } |
| | | |
| | | if (it.buttonChecked && it.buttonChecked.length > 0) { // 已选菜单 |
| | | it.buttonCheckedCode = this.$ButtonData.filter(i => |
| | | it.buttonCheckedCode = this.ButtonData.filter(i => |
| | | it.buttonChecked.includes(i.buttonname) |
| | | ).map(i => i.buttoncode) |
| | | } |
| | | arr.push({ |
| | | menucode: it.menucode, |
| | | datacode: it.dataCheckedCode !== undefined ? it.dataCheckedCode : '', |
| | | datacode, |
| | | buttoncode: it.buttonCheckedCode ? it.buttonCheckedCode.join(',') : '' |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | this.$store.state.app.buttonIsDisabled = true |
| | | |
| | | const rolecode = this.$refs.treeLeftRef.getCurrentKey() |
| | | const res = await RolePermissionSava(JSON.stringify(arr), rolecode, this.activeName) |
| | | if (res.code === '200') { |
| | | const rolename = this.treeLeft[0].roles.find(i => i.code === rolecode).name |
| | | const rolename = this.treeLeft.find(i => i.code === rolecode).name |
| | | this.$notify.success(rolename + '的角色权限提交成功!') |
| | | await this.getRolePermissionSearchRoleMenuButton(rolecode) |
| | | this.$store.state.app.buttonIsDisabled = false |
| | | } |
| | | }, |
| | | // 获取页面高度 |
| | |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | .custom-tree-node { |
| | | flex: 1; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: space-between; |
| | | font-size: 14px; |
| | | padding-right: 8px; |
| | | } |
| | | |
| | | ::v-deep .el-checkbox__label { |
| | | width: 55px; |
| | | } |
| | | |
| | | .el-icon-plus:hover, .el-icon-edit:hover, .el-icon-delete:hover { |
| | | color: #000 !important; |
| | | .el-checkbox-group { |
| | | margin-left: 0 !important; |
| | | padding-left: 40px; |
| | | } |
| | | |
| | | .el-checkbox-group:hover { |
| | | background: #f0f7ff; |
| | | } |
| | | </style> |