<template> <!--修改用户组权限对话框--> <el-dialog v-dialogDrag style="font-size: 10px;" :width='dialogWidth' :title="$t('Security.modifyUserGroup')" :visible.sync="dialogUpdate" @close="close" @opened="editChecked"> <el-main style="padding-bottom: 10px;"> <el-form ref="form" :model="form" :inline="true" :label-position="localPosition"> <el-form-item prop="groupName" style="margin-bottom: -10px; margin-right: 70px;" :label="'*'+$t('Security.userGroupName') + ':'" :label-width="formLabelWidth"> <el-input type="text" size='mini' v-model="form.usergroupName" v-on:blur="checkedUserGroupName" autocomplete="off" style="width:200px"></el-input> </el-form-item> <el-form-item prop="groupDescription" style="margin-bottom: -10px; margin-right: 70px;" :label="$t('Security.userGroupDescription') + ':'" :label-width="formLabelWidth"> <el-input type="text" size='mini' v-model="form.description" v-on:blur="checkedUserGroupDescription" autocomplete="off" style="width:200px"></el-input> </el-form-item> <el-form-item prop="functionAuthority" style="margin-bottom: -5px;" :label="$t('Security.functionAuthority') + ':'" :label-width="formLabelWidth"> <el-radio-group v-model="form.menuFlag" @change="menuValueChange" :style="formLabelStyle"> <el-radio style="font-size: 10px;" :label=0>{{$t("Security.select")}}</el-radio> <el-radio style="font-size: 10px;" :label=1>{{$t("Security.fullAuthority")}}</el-radio> </el-radio-group> <div style="border:1px solid #0f0f0f; background:#f0f9eb; font-size: 10px; width: 250px; height:250px"> <vue-scroll> <el-tree style="background:#f0f9eb; " :data="allAuthority" show-checkbox default-expand-all :default-checked-keys="authorityChecked" node-key="authorityKey" ref="authorityTree" highlight-current :props="defaultProps" :render-content="renderContent" @check="checkAuthorityTree"> </el-tree> </vue-scroll> </div> </el-form-item> <el-form-item prop="subnetAuthority" style="margin-top: 10px; margin-bottom: 0px;" :label="$t('Security.administrativeDomain') + ':'" :label-width="formLabelWidth"> <el-radio-group v-model="form.domainFlag" @change="subnetValueChange" :style="formLabelStyle"> <el-radio style="font-size: 10px;" :label=0>{{$t("Security.select")}}</el-radio> <el-radio style="font-size: 10px;" :label=1>{{$t("Security.fullAuthority")}}</el-radio> </el-radio-group> <div style="border:1px solid #0f0f0f; background:#f0f9eb; font-size: 10px; width: 250px; height:250px"> <vue-scroll> <el-tree style="background:#f0f9eb;" :data="subnetAuthority" show-checkbox default-expand-all node-key="subnetKey" ref="subnetTree" highlight-current :props="subnetProps"> </el-tree> </vue-scroll> </div> </el-form-item> </el-form> </el-main> <div slot="footer" class="dialog-footer"> <el-button size='mini' type="primary" icon='el-icon-circle-check' @click="updateAuthority">{{$t("common.ok")}} </el-button> <el-button size='mini' icon='el-icon-circle-close' @click="close">{{$t("common.cancel")}}</el-button> </div> </el-dialog> </template> <script> import UserGroupService from '@/domain/services/UserGroupService' import SubnetService from '@/domain/services/SubnetService' import legitimacyCheck from '../../../utils/legitimacyCheck' import HelperUtil from '../../../utils/HelperUtil' export default { props: ['command'], name: 'UpdateUserGroupDialog', created () { this.getAllAuthorities() // this.subnetAuthorityTree() this.getAllUserGroups() // this.updateClick() if (window.localStorage.getItem('user-language') === 'en') { this.formLabelWidth = '230px' this.dialogWidth = '600px' this.formLabelStyle = 'margin-top: 5px; margin-right: 70px;' } else { this.formLabelWidth = '120px' this.dialogWidth = '500px' this.formLabelStyle = 'margin-top: 5px; margin-right: 95px;' } }, mounted () { this.dialogUpdate = true }, data () { return { dialogUpdate: false, dialogWidth: '500px', multipleSelection: this.command.target, // 用户组列表 userGroupList: [], userGroupCollection: {}, // 表单参数 formLabelWidth: '120px', localPosition: 'right', formLabelStyle: 'margin-top: 5px; margin-right: 95px;', // 对话框全部权限 allAuthority: [], // 全部权限树 authorityCollection: {}, defaultProps: { children: 'children', label: 'authorityNameZH' }, allAuthorityKeys: [], // 全部权限Keys authorityChecked: [], // 回填对应的权限 authorityEditList: {}, // 权限是否有可编辑按钮选项 // 对话框全部子网 subnetList: [], // 显示时匹配子网名称 subnetCollection: {}, subnetAuthority: [], // 子网权限树 subnetAuthority_bk: [], // 子网权限树备份 subnetProps: { children: 'children', label: 'subnetName' }, allSubnetKeys: [], // 全部子网Key subnetChecked: [], // 回填用户组权限对应的subnetKey // 修改表单 form: { authority: [], delFlag: 0, description: '', domainFlag: 0, editFlag: 0, menuFlag: 0, modifyTime: '', subnetKey: [], usergroupKey: '', usergroupName: '' } } }, methods: { /* ---------------------------对话框初始化--------------------------- */ /*** * @Description : 获取全部用户组 * @author : zf * @date : 2019/03/21 20:03 */ getAllUserGroups: function () { let _this = this UserGroupService.getAllUserGroups().then(result => { // 成功 _this.userGroupList = Object.values(result) _this.userGroupCollection = result }).catch(err => { // 失败 _this.InfoTip.errorTip(_this, err) }) }, /*** * @Description : 获取全部菜单权限树 * @author : zf * @date : 2019/03/15 14:15 */ getAllAuthorities: function () { let _this = this this.allAuthority = [{ authorityKey: '0', authorityNameZH: this.$t('Security.selectAll'), disabled: false, children: [] }] UserGroupService.getAllAuthorities().then(result => { // 成功 _this.allAuthority[0].children = Object.values(result) _this.authorityCollection = result let func = 'addDisabled' _this.traverseAuthorityTree(_this.allAuthority, func, 3) _this.subnetAuthorityTree() }).catch(err => { // 失败 _this.InfoTip.errorTip(_this, err) }) }, /*** * @Description : 获取全部管辖范围权限树 * @author : zf * @date : 2019/03/14 15:54 */ subnetAuthorityTree: function () { let _this = this this.subnetAuthority = [] this.subnetAuthority_bk = [] SubnetService.getAllSubnetCollection().then(result => { // 成功 _this.subnetList = Object.values(result) _this.subnetCollection = result let mainTree = {} mainTree['subnetKey'] = '-1' mainTree['subnetName'] = this.$t('Security.selectAll') mainTree['disabled'] = false let subTree = [] for (let i = 0; i < _this.subnetList.length; i++) { let subNode = {} subNode['subnetKey'] = _this.subnetList[i].subnetKey subNode['subnetName'] = _this.subnetList[i].subnetName subNode['disabled'] = false subTree[i] = subNode } mainTree['children'] = subTree _this.subnetAuthority.push(mainTree) _this.subnetAuthority_bk.push(mainTree) _this.updateClick() }).catch(err => { // 失败 _this.InfoTip.errorTip(_this, err) }) }, /* ---------------------------对话框显示--------------------------- */ /*** * @Description : 遍历权限树 * @author : zf * @date : 2019/03/15 10:02 */ traverseAuthorityTree: function (authorityTree, func, level) { if (func === 'disabled') { for (let i = 0; i < authorityTree.length; i++) { let obj = Object.keys(authorityTree[i]) // 获取这一层的全部键值 for (let j = 0; j < obj.length; j++) { if (level === 0) { return } if (obj[j] === 'disabled') { authorityTree[i][obj[j]] = true } if (obj[j] === 'children' && authorityTree[i][obj[j]] !== null) { this.traverseAuthorityTree(authorityTree[i][obj[j]], func, level - 1) } } } } if (func === 'enabled') { for (let i = 0; i < authorityTree.length; i++) { let obj = Object.keys(authorityTree[i]) // 获取这一层的全部键值 for (let j = 0; j < obj.length; j++) { if (level === 0) { return } if (obj[j] === 'disabled') { authorityTree[i][obj[j]] = false } if (obj[j] === 'children' && authorityTree[i][obj[j]] !== null) { this.traverseAuthorityTree(authorityTree[i][obj[j]], func, level - 1) } } } } if (func === 'addDisabled') { for (let i = 0; i < authorityTree.length; i++) { let obj = Object.keys(authorityTree[i]) // 获取这一层这一个对象的全部键值 let disabledFlag = 0 for (let j = 0; j < obj.length; j++) { if (obj[j] === 'disabled') { disabledFlag = 1 } } if (disabledFlag === 0) { this.$set(authorityTree[i], 'disabled', false) } for (let j = 0; j < obj.length; j++) { if (level === 0) { return } if (obj[j] === 'children' && authorityTree[i][obj[j]] !== null) { this.traverseAuthorityTree(authorityTree[i][obj[j]], func, level - 1) } } } } if (func === 'getAllAuthorityKeys') { for (let i = 0; i < authorityTree.length; i++) { let obj = Object.keys(authorityTree[i]) // 获取这一层的全部键值 for (let j = 0; j < obj.length; j++) { if (level === 0) { return } if (obj[j] === 'children' && authorityTree[i][obj[j]] !== null) { this.allAuthorityKeys.push(authorityTree[i]['authorityKey']) this.traverseAuthorityTree(authorityTree[i][obj[j]], func, level - 1) } if (obj[j] === 'children' && authorityTree[i][obj[j]] === null) { this.allAuthorityKeys.push(authorityTree[i]['authorityKey']) } } } } if (func === 'getAllSubnetKeys') { for (let i = 0; i < authorityTree.length; i++) { let obj = Object.keys(authorityTree[i]) // 获取这一层的全部键值 for (let j = 0; j < obj.length; j++) { if (level === 0) { return } if (obj[j] === 'children' && authorityTree[i][obj[j]] !== null) { this.allSubnetKeys.push(authorityTree[i]['subnetKey']) this.traverseAuthorityTree(authorityTree[i][obj[j]], func, level - 1) } if (obj[j] === 'subnetKey' && authorityTree[i]['subnetKey'] !== '-1') { this.allSubnetKeys.push(authorityTree[i]['subnetKey']) } } } } }, /*** * @Description : 点击全部菜单权限按钮 * @author : zf * @date : 2019/03/15 10:40 */ menuValueChange: function () { let func if (this.form.menuFlag === 1) { func = 'disabled' this.traverseAuthorityTree(this.allAuthority, func, 3) // 创建对话框 this.allAuthorityKeys = [] this.traverseAuthorityTree(this.allAuthority, 'getAllAuthorityKeys', 3) this.$refs.authorityTree.setCheckedKeys(this.allAuthorityKeys) // 可编辑选项框状态:全部可编辑选项为disabled=true;checked=true let obj = Object.keys(this.authorityEditList) for (let i = 0; i < obj.length; i++) { let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === false) { item[0].disabled = true item[0].parentNode.classList.add('is-disabled') } if (item[0]['checked'] === false) { item[0].checked = true item[0].parentNode.classList.add('is-checked') } } } else { func = 'enabled' this.traverseAuthorityTree(this.allAuthority, func, 3) this.$refs.authorityTree.setCheckedKeys(this.authorityChecked) let authorityChecked = this.$refs.authorityTree.getCheckedKeys() let currentRow = 0 for (let n = 0; n < this.userGroupList.length; n++) { if (this.multipleSelection.usergroupKey === this.userGroupList[n].usergroupKey) { currentRow = n break } } // 回填可编辑选项 let obj = Object.keys(this.authorityEditList) // 回填可编辑选项可选状态 let objFlag = 0 for (let i = 0; i < obj.length; i++) { objFlag = 0 for (let j = 0; j < authorityChecked.length; j++) { if (obj[i] === authorityChecked[j]) { objFlag = 1 let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === true) { item[0]['disabled'] = false item[0].parentNode.classList.remove('is-disabled') } } } if (objFlag === 0) { let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === false) { item[0].disabled = true item[0].parentNode.classList.add('is-disabled') } } } // 回填可编辑选项勾选状态 for (let h = 0; h < obj.length; h++) { objFlag = 0 for (let k = 0; k < this.userGroupList[currentRow].authority.length; k++) { if (obj[h] === this.userGroupList[currentRow].authority[k].authorityKey) { objFlag = 1 if (this.userGroupList[currentRow].authority[k].editFlag === 0) { let item = document.getElementsByName(obj[h]) if (item[0]['checked'] === false) { item[0].checked = true item[0].parentNode.classList.add('is-checked') } } else { let item = document.getElementsByName(obj[h]) if (item[0]['checked'] === true) { item[0].checked = false item[0].parentNode.classList.remove('is-checked') } } } } if (objFlag === 0) { let item = document.getElementsByName(obj[h]) if (item[0]['checked'] === true) { item[0].checked = false item[0].parentNode.classList.remove('is-checked') } } } } }, /** * @Description : subnetValueChange * @author : ls * @date : 2020/12/30 11:12 * @param : * @return : */ subnetValueChange: function () { let func if (this.form.domainFlag === 1) { func = 'disabled' this.traverseAuthorityTree(this.subnetAuthority, func, 2) // 修改对话框 if (this.dialogUpdate === true) { this.allSubnetKeys = [] this.traverseAuthorityTree(this.subnetAuthority, 'getAllSubnetKeys', 2) this.$refs.subnetTree.setCheckedKeys(this.allSubnetKeys) } // this.subnetAuthority = []; // let mainTree = {}; // mainTree['subnetKey'] = '0'; // mainTree['subnetName'] = this.$t('Security.selectAll'); // mainTree['disabled'] = true; // this.subnetAuthority.push(mainTree); // this.$refs.subnetTree.setCheckedKeys(['0']) } else { if (this.subnetAuthority.length === 1) { this.subnetAuthority = this.subnetAuthority_bk } func = 'enabled' this.traverseAuthorityTree(this.subnetAuthority, func, 2) // 修改对话框 if (this.dialogUpdate === true) { this.$refs.subnetTree.setCheckedKeys([]) } } }, /*** * @Description : 添加对话框得中可编辑checkBox * @author : zf * @date : 2019/03/29 00:12 */ renderContent (h, { node, data, store }) { if (window.localStorage.getItem('user-language') === 'en') { if (data.editFlag === 0) { this.$set(this.authorityEditList, data.authorityKey, false) // disabled={true} onChange={() =>this.handleChange(data)} return ( <span class="custom-tree-node"> <span>{node.label}</span> <span> <el-checkbox checked={this.authorityEditList[data.authorityKey]} name={data.authorityKey}>Editable</el-checkbox> </span> </span>) } else { return ( <span class="custom-tree-node"> <span>{node.label}</span> </span>) } } else { if (data.editFlag === 0) { this.$set(this.authorityEditList, data.authorityKey, false) // disabled={true} onChange={() =>this.handleChange(data)} return ( <span class="custom-tree-node"> <span>{node.label}</span> <span> <el-checkbox checked={this.authorityEditList[data.authorityKey]} name={data.authorityKey}>可编辑</el-checkbox> </span> </span>) } else { return ( <span class="custom-tree-node"> <span>{node.label}</span> </span>) } } }, /*** * @Description : 手动选择权限点击节点时 * @author : zf * @date : 2019/03/21 19:35 */ checkAuthorityTree: function (data, node) { let allCheckedNodeKey = this.$refs.authorityTree.getCheckedKeys() let obj = Object.keys(this.authorityEditList) // 有可编辑选项框的节点 let checkedFlag = 0 for (let i = 0; i < obj.length; i++) { checkedFlag = 0 for (let j = 0; j < allCheckedNodeKey.length; j++) { if (obj[i] === allCheckedNodeKey[j]) { // 当前进行操作的节点 checkedFlag = 1 let item = document.getElementsByName(obj[i]) // 创建对话框 if (item[0]['disabled'] === true) { // 当前进行操作的节点编辑节点不可被选时 item[0].disabled = false item[0].parentNode.classList.remove('is-disabled') } break } } // 非选中按钮 if (checkedFlag === 0) { let item = document.getElementsByName(obj[i]) if (this.dialogCreate === true) { // 创建对话框 if (item[0]['disabled'] === false) { // 当前进行操作的节点编辑节点可被选时 item[0].disabled = true item[0].parentNode.classList.add('is-disabled') if (item[0]['checked'] === true) { item[0].checked = false item[0].parentNode.classList.remove('is-checked') } } } else { // 修改对话框 if (item[0]['disabled'] === false) { // 当前进行操作的节点编辑节点可被选时 item[0].disabled = true item[0].parentNode.classList.add('is-disabled') if (item[0]['checked'] === true) { item[0].checked = false item[0].parentNode.classList.remove('is-checked') } } } } } }, /* ---------------------------对话框验证--------------------------- */ /*** * @Description : 用户组名验证 * @author : zf * @date : 2019/04/01 17:27 */ checkedUserGroupName: function () { let check = legitimacyCheck() if (check.stringNullCheck(this.form.usergroupName)) { this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('Security.userGroupName')) return false } else { if (this.textLengthCheck(this.form.usergroupName)) { return true } else { this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.LENGTH_CODE), this.$t('Security.userGroupName')) return false } } }, /*** * @Description : 用户组描述验证 * @author : zf * @date : 2019/04/01 17:27 */ checkedUserGroupDescription: function () { if (this.textLengthCheck(this.form.description)) { return true } else { this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.LENGTH_CODE), this.$t('Security.userGroupDescription')) return false } }, /** * @Description :文本框所输入的字符长度校验: 控制在20之内 * @author : bjh * @param : * @return : * @exception : * @date : 2019/1/15 16:09 */ textLengthCheck: function (text) { let check = legitimacyCheck() if (!check.textLengthCheck(text)) { return false } else { return true } }, /*** * @Description : 验证是否真的修改了 * @author : zf * @date : 2019/04/10 12:26 */ checkedUpdate: function (authority, subnetKey) { let check = legitimacyCheck() if (this.form.usergroupName === this.multipleSelection.usergroupName && this.form.description === this.multipleSelection.description && this.form.domainFlag === this.multipleSelection.domainFlag && this.form.menuFlag === this.multipleSelection.menuFlag) { if (this.multipleSelection.authority === null) { this.multipleSelection.authority = [] } if (this.multipleSelection.subnetKey === null) { this.multipleSelection.subnetKey = [] } if (authority.length !== this.multipleSelection.authority.length || subnetKey.length !== this.multipleSelection.subnetKey.length) { return false } else { if (check.checkListEqual(subnetKey, this.multipleSelection.subnetKey)) { for (let i = 0; i < authority.length; i++) { let oldAuthority = {} let flag = 0 // 匹配原始权限中key值一样的 for (let j = 0; j < this.multipleSelection.authority.length; j++) { if (this.multipleSelection.authority[j].authorityKey === authority[i].authorityKey) { flag = 1 oldAuthority = this.multipleSelection.authority[j] } } if (flag === 0) { // 未匹配到 return false } else { // 匹配到 if (!check.compareObject(authority[i], oldAuthority)) { return false } } } return true } else { return false } } } else { return false } }, /** * @Description : updateAuthority * @author : ls * @date : 2020/12/29 17:30 * @param : * @return : */ updateAuthority: function () { let _this = this if (this.checkedUserGroupName() && this.checkedUserGroupDescription()) { this.form.subnetKey = [] this.form.authority = [] if (this.form.domainFlag === 1) { this.allSubnetKeys.shift() this.form.subnetKey = this.allSubnetKeys } else { let selectedSubnetKeys = this.$refs.subnetTree.getCheckedKeys() for (let i = 0; i < selectedSubnetKeys.length; i++) { if (selectedSubnetKeys[i] !== '-1') { this.form.subnetKey.push(selectedSubnetKeys[i]) } } } let selectedAuthority = this.$refs.authorityTree.getCheckedNodes() let halfSelectedAuthority = this.$refs.authorityTree.getHalfCheckedNodes() for (let p = 0; p < halfSelectedAuthority.length; p++) { if (halfSelectedAuthority[p].authorityKey !== '0') { var ob = {} ob.authorityKey = halfSelectedAuthority[p].authorityKey ob.authorityNameEn = halfSelectedAuthority[p].authorityNameEn ob.authorityNameZH = halfSelectedAuthority[p].authorityNameZH ob.editFlag = halfSelectedAuthority[p].editFlag ob.fatherauthorityKey = halfSelectedAuthority[p].fatherauthorityKey ob.children = null this.form.authority.push(ob) } } for (let j = 0; j < selectedAuthority.length; j++) { if (selectedAuthority[j].authorityKey !== '0') { var obj = {} obj.authorityKey = selectedAuthority[j].authorityKey obj.authorityNameEn = selectedAuthority[j].authorityNameEn obj.authorityNameZH = selectedAuthority[j].authorityNameZH obj.editFlag = selectedAuthority[j].editFlag obj.fatherauthorityKey = selectedAuthority[j].fatherauthorityKey obj.children = null this.form.authority.push(obj) } } let objKeys = Object.keys(this.authorityEditList) for (let q = 0; q < objKeys.length; q++) { var item = document.getElementsByName(objKeys[q]) let checkedFlag = false for (let i1 = 0; i1 < item[0].parentNode.classList.length; i1++) { if (item[0].parentNode.classList[i1] === 'is-checked') { checkedFlag = true } } if (checkedFlag) this.authorityEditList[objKeys[q]] = true } for (let k = 0; k < this.form.authority.length; k++) { if (this.form.menuFlag === 0) { for (let m = 0; m < objKeys.length; m++) { if (this.form.authority[k].authorityKey === objKeys[m]) { if (this.authorityEditList[objKeys[m]]) { this.form.authority[k].editFlag = 0 } else { this.form.authority[k].editFlag = 1 } } } } } let formUserGroup = {} formUserGroup.authority = this.form.authority formUserGroup.description = this.form.description formUserGroup.domainFlag = this.form.domainFlag formUserGroup.menuFlag = this.form.menuFlag formUserGroup.subnetKey = this.form.subnetKey formUserGroup.usergroupName = this.form.usergroupName formUserGroup.usergroupKey = this.form.usergroupKey let loadingInstance = _this.Loading.openLoading() UserGroupService.updateUserGroup(formUserGroup).then(result => { // 成功 _this.Loading.closeLoading(loadingInstance) _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.MODIFY_CODE)) _this.close() }).catch(err => { // 失败 _this.Loading.closeLoading(loadingInstance) _this.InfoTip.errorTip(_this, err) }) } }, /*** * @Description : 保存修改选项 * @author : zf * @date : 2019/03/13 17:47 */ updateAuthority1: function () { if (this.checkedUserGroupName() && this.checkedUserGroupDescription()) { this.form.subnetKey = [] this.form.authority = [] // 子网 let selectedSubnetKeys = this.$refs.subnetTree.getCheckedKeys() for (let i = 0; i < selectedSubnetKeys.length; i++) { if (selectedSubnetKeys[i] !== '-1') { this.form.subnetKey.push(selectedSubnetKeys[i]) } } // 权限 let selectedAuthority = this.$refs.authorityTree.getCheckedNodes() let halfSelectedAuthority = this.$refs.authorityTree.getHalfCheckedNodes() for (let j = 0; j < halfSelectedAuthority.length; j++) { let map = {} if (halfSelectedAuthority[j]['authorityKey'] !== '0') { this.$set(map, 'authorityKey', halfSelectedAuthority[j]['authorityKey']) this.$set(map, 'authorityNameZH', halfSelectedAuthority[j]['authorityNameZH']) this.$set(map, 'authorityNameEn', halfSelectedAuthority[j]['authorityNameEn']) this.$set(map, 'children', []) this.$set(map, 'editFlag', halfSelectedAuthority[j]['editFlag']) this.$set(map, 'fatherauthorityKey', halfSelectedAuthority[j]['fatherauthorityKey']) this.$set(map, 'method', halfSelectedAuthority[j]['method']) this.form.authority.push(map) } } for (let h = 0; h < selectedAuthority.length; h++) { let map = {} if (selectedAuthority[h]['authorityKey'] !== '0') { this.$set(map, 'authorityKey', selectedAuthority[h]['authorityKey']) this.$set(map, 'authorityNameZH', selectedAuthority[h]['authorityNameZH']) this.$set(map, 'authorityNameEn', selectedAuthority[h]['authorityNameEn']) this.$set(map, 'children', []) this.$set(map, 'editFlag', selectedAuthority[h]['editFlag']) this.$set(map, 'fatherauthorityKey', selectedAuthority[h]['fatherauthorityKey']) this.$set(map, 'method', selectedAuthority[h]['method']) this.form.authority.push(map) } } // 权限是否可编辑 let obj = Object.keys(this.authorityEditList) for (let k = 0; k < obj.length; k++) { let item = document.getElementsByName(obj[k]) let checkedFlag = false for (let i = 0; i < item[0].parentNode.classList.length; i++) { if (item[0].parentNode.classList[i] === 'is-checked') { checkedFlag = true } } this.$set(this.authorityEditList, obj[k], checkedFlag) // this.authorityEditList[obj[k]] = checkedFlag; } for (let m = 0; m < this.form.authority.length; m++) { for (let n = 0; n < obj.length; n++) { if (this.form.authority[m]['authorityKey'] === obj[n]) { if (this.authorityEditList[obj[n]] === true) { this.form.authority[m]['editFlag'] = 0 } else { this.form.authority[m]['editFlag'] = 1 } } } } if (!this.checkedUpdate(this.form.authority, this.form.subnetKey)) { let formUserGroup = {} this.$set(formUserGroup, 'delFlag', this.form.delFlag) this.$set(formUserGroup, 'description', this.form.description) this.$set(formUserGroup, 'editFlag', this.form.editFlag) this.$set(formUserGroup, 'menuFlag', this.form.menuFlag) this.$set(formUserGroup, 'domainFlag', this.form.domainFlag) this.$set(formUserGroup, 'modifyTime', this.form.modifyTime) this.$set(formUserGroup, 'usergroupKey', this.form.usergroupKey) this.$set(formUserGroup, 'usergroupName', this.form.usergroupName) this.$set(formUserGroup, 'subnetKey', this.form.subnetKey) this.$set(formUserGroup, 'authority', this.form.authority) let _this = this let loadingInstance = _this.Loading.openLoading() UserGroupService.updateUserGroup(formUserGroup).then(result => { // 成功 _this.Loading.closeLoading(loadingInstance) _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.MODIFY_CODE)) this.close() }).catch(err => { // 失败 _this.Loading.closeLoading(loadingInstance) _this.InfoTip.errorTip(_this, err) }) } else { this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UNUPDATE_CODE)) } } }, /** * @Description : updateClick * @author : ls * @date : 2020/12/29 17:26 * @param : * @return : */ updateClick () { let func // 回填权限 this.authorityChecked = [] if (this.multipleSelection.menuFlag === 1) { this.allAuthorityKeys = [] this.traverseAuthorityTree(this.allAuthority, 'getAllAuthorityKeys', 3) for (let count = 0; count < this.allAuthorityKeys.length; count++) { this.authorityChecked.push(this.allAuthorityKeys[count]) } } else { if (this.multipleSelection.authority !== null) { for (let i = 0; i < this.multipleSelection.authority.length; i++) { if (this.multipleSelection.authority[i]['children'] === null && this.multipleSelection.authority[i]['fatherauthorityKey'] !== null) { this.authorityChecked.push(this.multipleSelection.authority[i].authorityKey) } if (this.multipleSelection.authority[i].authorityKey === '070000') { this.authorityChecked.push(this.multipleSelection.authority[i].authorityKey) } } } else { this.authorityChecked = [] } } // 回填子网 this.subnetChecked = [] if (this.multipleSelection.domainFlag === 1) { this.allSubnetKeys = [] this.traverseAuthorityTree(this.subnetAuthority, 'getAllSubnetKeys', 2) for (let count = 0; count < this.allSubnetKeys.length; count++) { this.subnetChecked.push(this.allSubnetKeys[count]) } } else { if (this.multipleSelection.subnetKey !== null) { this.subnetChecked = this.multipleSelection.subnetKey } else { this.subnetChecked = [] } } this.form.authority = this.multipleSelection.authority this.form.delFlag = this.multipleSelection.delFlag this.form.description = this.multipleSelection.description this.form.domainFlag = this.multipleSelection.domainFlag this.form.editFlag = this.multipleSelection.editFlag this.form.menuFlag = this.multipleSelection.menuFlag this.form.modifyTime = this.multipleSelection.modifyTime this.form.subnetKey = this.multipleSelection.subnetKey this.form.usergroupKey = this.multipleSelection.usergroupKey this.form.usergroupName = this.multipleSelection.usergroupName }, /*** * @Description : 回填可编辑checked;disabled * @author : zf * @date : 2019/03/29 18:53 */ editChecked: function () { this.menuValueChange() this.subnetValueChange() this.$refs.subnetTree.setCheckedKeys(this.subnetChecked) if (this.form.menuFlag !== 1) { this.$refs.authorityTree.setCheckedKeys(this.authorityChecked) let authorityChecked = this.$refs.authorityTree.getCheckedKeys() // 回填可编辑选项 let obj = Object.keys(this.authorityEditList) // 回填可编辑选项可选状态 let objFlag = 0 for (let i = 0; i < obj.length; i++) { objFlag = 0 for (let j = 0; j < authorityChecked.length; j++) { if (obj[i] === authorityChecked[j]) { objFlag = 1 let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === true) { item[0]['disabled'] = false item[0].parentNode.classList.remove('is-disabled') } } } if (objFlag === 0) { let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === false) { item[0].disabled = true item[0].parentNode.classList.add('is-disabled') } } } // 回填可编辑选项勾选状态 for (let k = 0; k < this.multipleSelection.authority.length; k++) { for (let h = 0; h < obj.length; h++) { if (obj[h] === this.multipleSelection.authority[k].authorityKey) { if (this.multipleSelection.authority[k].editFlag === 0) { let item = document.getElementsByName(obj[h]) if (item[0]['checked'] === false) { item[0].checked = true item[0].parentNode.classList.add('is-checked') } } } } } } else { // 回填全部可编辑选项为disabled=true;checked=true let obj = Object.keys(this.authorityEditList) for (let i = 0; i < obj.length; i++) { let item = document.getElementsByName(obj[i]) if (item[0]['disabled'] === false) { item[0].disabled = true item[0].parentNode.classList.add('is-disabled') } if (item[0]['checked'] = false) { item[0].checked = true item[0].parentNode.classList.add('is-checked') } } } }, /* ---------------------------对话框结束--------------------------- */ /*** * @Description : 对话框结束 * @author : zf * @date : 2019/05/09 14:08 */ close: function () { this.command.done() } } } </script> <style scoped> /deep/ .custom-tree-node { flex: 1; display: flex; align-items: center; justify-content: space-between; font-size: 10px; padding-right: 8px; } /deep/ .el-tree-node__label{ font-size: 12px; } /deep/ .el-radio__label { font-size: 12px; padding-left: 5px; } /deep/ .el-checkbox__label{ font-size: 12px; padding-top: 5px; padding-left: 5px; } /deep/ .el-dialog__body{ padding-top: 10px !important; padding-bottom: 0px !important; } /deep/ .col-new{ padding-left: 0px !important; padding-right: 0px !important; } </style>