| | |
| | | <input |
| | | v-if="data.isEdit" |
| | | :ref="data.code" |
| | | v-model="node.label" |
| | | v-model="data.name" |
| | | type="text" |
| | | @click.stop |
| | | @blur="roleSave(data)" |
| | |
| | | </div> |
| | | |
| | | <div |
| | | style="margin-left: 15px;width:100%;position: relative" |
| | | style="margin-left: 10px;width:100%;position: relative" |
| | | > |
| | | |
| | | <el-button |
| | |
| | | |
| | | <div |
| | | ref="scrollCenter" |
| | | style="border-right: 1px solid rgba(0,0,0,0.2);width: 600px;padding-left: 10px;overflow-y: auto" |
| | | style="border-right: 1px solid rgba(0,0,0,0.2);width: 660px;padding-left: 10px;overflow-y: auto" |
| | | :style="{height:(tableHeight-40)+'px'}" |
| | | @scroll="scrollCenterScroll()" |
| | | @mouseover="isScroll='center'" |
| | |
| | | </el-checkbox> |
| | | |
| | | <div v-if="treeCenter.length>0"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.menucode"> |
| | | <div v-for="(item,index) in treeCenter[0].children" :key="item.menucode"> |
| | | |
| | | <div |
| | | v-if="item.buttoncodelist ===null " |
| | | v-if="!item.buttoncodelist" |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | /> |
| | | |
| | |
| | | v-if="item.expanded" |
| | | :key="it.menucode" |
| | | v-model="it.buttonChecked" |
| | | style="margin-left: 40px;height:26px;display: flex" |
| | | @change="val=>handleCheckedButtonChange(val,it.menucode)" |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | @change="val=>handleCheckedButtonChange(val,index,it.menucode,it.buttonChecked)" |
| | | > |
| | | |
| | | <el-checkbox |
| | | v-for="i in it.buttoncodelist" |
| | | :key="i" |
| | | :label="i" |
| | | style="display:flex;align-items: center" |
| | | style="display:flex;align-items: center;" |
| | | /> |
| | | </el-checkbox-group> |
| | | |
| | |
| | | <div v-if="treeCenter.length>0"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.menucode"> |
| | | <div |
| | | v-if="item.datacodelist ===null " |
| | | v-if="!item.datacodelist" |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | /> |
| | | |
| | |
| | | <script> |
| | | import waves from '@/directive/waves' |
| | | import { |
| | | DataPermissions, |
| | | RoleAddUpdateSava, RoleDeleteSava, |
| | | RolePermissionSava, |
| | | RolePermissionSearchRole, |
| | | RolePermissionSearchRoleMenu, |
| | |
| | | } from '@/api/basicSettings' |
| | | import arrayToTree from 'array-to-tree' |
| | | import { throttle } from '@/utils/debounceAndThrottle' |
| | | import { DataPermissions } from '@/api/GeneralBasicData' |
| | | |
| | | export default { |
| | | name: 'RoleList', |
| | |
| | | }, |
| | | |
| | | created() { |
| | | this.getRolePermissionSearchRole() |
| | | }, |
| | | mounted() { |
| | | window.addEventListener('resize', this.getHeight) |
| | | this.getHeight() |
| | | |
| | | this.getRolePermissionSearchRole() |
| | | }, |
| | | methods: { |
| | | |
| | |
| | | |
| | | this.treeLeft = res |
| | | |
| | | if (res.length > 0) { |
| | | if (res && res.length > 0) { |
| | | this.$nextTick(() => { // 默认选中第一个 |
| | | this.$refs.treeLeftRef.setCurrentKey(res[0].roles[0].code) // 默认选中节点第一个 |
| | | }) |
| | |
| | | // 获取菜单权限对应的按钮 |
| | | async getRolePermissionSearchRoleMenuButton(rolecode) { |
| | | const { data: res } = await RolePermissionSearchRoleMenuButton({ rolecode, type: this.activeName }) |
| | | this.allButtonData = JSON.parse(res[0].jsondate) |
| | | this.allButtonData = res.length > 0 ? JSON.parse(res[0].jsondate) : [] |
| | | }, |
| | | // 获取菜单权限 |
| | | async getRolePermissionSearchRoleMenu(rolecode) { |
| | |
| | | childrenProperty: 'children' |
| | | }) |
| | | |
| | | this.menuCheckedCodeArr = this.allButtonData.map(i => i.menucode) |
| | | this.$nextTick(() => { |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | }) |
| | | this.treeCenter = [ |
| | | { menucode: '-1', menuname: '全部', children: result } |
| | | ] |
| | | |
| | | result.forEach(item => { |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | it.buttoncodelist = it.buttoncodelist ? it.buttoncodelist.split(',') : [] |
| | | 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.includes(j.buttoncode) |
| | | ) |
| | | |
| | | 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(',') : [] |
| | | console.log(temp, 7) |
| | | |
| | | it.buttonChecked = [] // 数据回显 |
| | | it.buttoncodelist.forEach(j => { |
| | | if (temp.includes(j.buttoncode)) { |
| | | it.buttonChecked.push(j.buttonname) |
| | | } |
| | | }) |
| | | |
| | | it.buttoncodelist = it.buttoncodelist.map(j => j.buttonname) |
| | | } |
| | |
| | | it.datacodelist.includes(j.datacode) |
| | | ).map(j => j.dataname) |
| | | } |
| | | 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 : '' // 数据回显 |
| | | }) |
| | | |
| | | item.expanded = true |
| | | } |
| | | }) |
| | | |
| | | this.treeCenter = [ |
| | | { menucode: '-1', menuname: '全部', children: result } |
| | | ] |
| | | this.handleData()// 处理数据回显 |
| | | }, |
| | | // 处理组合数据 |
| | | handleData() { |
| | | this.menuCheckedCodeArr = this.allButtonData.map(i => i.menucode) |
| | | this.$nextTick(() => { |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | }) |
| | | |
| | | this.handleCheckedButtonChange('', '', true) |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | 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 => { |
| | | 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.$forceUpdate() |
| | | console.log(JSON.parse(JSON.stringify(result)), 6) |
| | | }, |
| | | |
| | | // 左边滚动条滑动时 |
| | |
| | | } |
| | | }, |
| | | // 单个按钮改变 |
| | | handleCheckedButtonChange(value, code, flag) { |
| | | // console.log(value, code, flag, 1) |
| | | |
| | | // console.log(JSON.parse(JSON.stringify(this.treeCenter[0])), 2) |
| | | |
| | | handleCheckedButtonChange(oldValue, index, code, newValue, flag) { |
| | | // console.log(oldValue, index, code, newValue, 2) |
| | | // 判断是否包含在内 |
| | | if (!flag) { |
| | | if (!this.menuCheckedCodeArr.includes(code) && value.length === 1) { // 否 |
| | | if (!this.menuCheckedCodeArr.includes(code) && oldValue.length === 0 && newValue.length === 1) { // 否 |
| | | this.menuCheckedCodeArr.push(code) |
| | | } else if (this.menuCheckedCodeArr.includes(code) && value.length === 0) { // 是 |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== 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.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | } |
| | |
| | | if (it.buttoncodelist.length) { |
| | | childrenLength++ |
| | | } |
| | | console.log(count, childrenLength) |
| | | }) |
| | | } |
| | | }) |
| | |
| | | }, |
| | | // 获取树形节点node |
| | | getLeftTreeNode(data, Node, VueComponent) { |
| | | // console.log(data, Node, VueComponent, 2221) |
| | | // console.log(Node.expanded) |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.menucode === data.menucode) { |
| | | item.expanded = Node.expanded |
| | |
| | | // 处理中间树形选中值改变 |
| | | handleTreeCenterCheckChange(obj, selfChecked, selfChildrenTreeCheck) { |
| | | // console.log(obj, selfChecked, selfChildrenTreeCheck, '王老吉') |
| | | obj.flag = selfChecked ? 'Y' : 'N' |
| | | if (!selfChildrenTreeCheck) { |
| | | if (!selfChecked) { |
| | | if (!selfChecked) { // 从选中到不选中 |
| | | obj.buttonChecked = [] |
| | | obj.dataChecked = '' |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== obj.menucode) |
| | | } |
| | | if (selfChecked) { // 从不选中到选中 |
| | | obj.buttonCheckedCode = [] |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.menucode === obj.menucode) { |
| | | it.buttonChecked = [] |
| | | it.DataChecked = '' |
| | | this.menuCheckedCodeArr.push(obj.menucode) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | this.$forceUpdate() |
| | | } |
| | | |
| | | this.$forceUpdate() |
| | | } |
| | | }, |
| | | // 单选框按钮改变 |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.dataChecked.length > 0) { |
| | | 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, 9) |
| | | // 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) |
| | | // await this.getRolePermissionSearchRoleMenu(obj.code) |
| | | this.handleData() |
| | | } |
| | | }, |
| | | // 角色名称新增 |
| | | rolePlusClick() { |
| | | this.treeLeft[0].roles.push({ code: 1234, name: '', isEdit: true }) |
| | | this.treeLeft[0].roles.push({ code: '', name: '', isEdit: true }) |
| | | }, |
| | | // 角色名称修改 |
| | | roleEditClick(self, node, data) { |
| | |
| | | // 角色名称删除 |
| | | roleDeleteClick(self, node, data) { |
| | | // console.log(self, node, data) |
| | | // this.treeLeft[0].roles.forEach((item, index) => { |
| | | // if (item.code === data.code) { |
| | | // this.treeLeft[0].roles.splice(index, 1) // 暂时先写成前端删除,后期调用接口删除 |
| | | // } |
| | | // }) |
| | | 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(data) { |
| | | data.isEdit = false |
| | | console.log('执行了!') |
| | | 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() { |
| | | // [{"menucode":"1010","buttoncode":"Add,Update","datacode":"ALL"},] |
| | | 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 (it.dataChecked && it.dataChecked.toString().length > 0) { // 数据权限已勾选 |
| | | it.dataChecked = this.dataKeyValue.find(i => i.dataname === it.dataChecked).datacode |
| | | } |
| | | 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.buttonChecked = this.$ButtonData.filter(i => |
| | | it.buttonChecked.includes(i.buttonname) |
| | | ).map(i => i.buttoncode) |
| | | if (it.buttonChecked && it.buttonChecked.length > 0) { // 已选菜单 |
| | | 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 : '', |
| | | buttoncode: it.buttonCheckedCode ? it.buttonCheckedCode.join(',') : '' |
| | | }) |
| | | } |
| | | arr.push({ |
| | | menucode: it.menucode, |
| | | datacode: it.dataChecked, |
| | | buttoncode: it.buttonChecked ? it.buttonChecked.join(',') : '' |
| | | }) |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | const rolecode = this.$refs.treeLeftRef.getCurrentKey() |
| | | // console.log(JSON.stringify(arr).toString()) |
| | | 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 |
| | | this.$notify.success(rolename + '的角色权限提交成功!') |
| | | await this.getRolePermissionSearchRoleMenuButton(rolecode) |
| | | await this.getRolePermissionSearchRoleMenu(rolecode) |
| | | } |
| | | this.$forceUpdate() |
| | | }, |
| | | // 获取页面高度 |
| | | getHeight() { |
| | |
| | | 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; |
| | | } |
| | | </style> |