| | |
| | | |
| | | <el-tree |
| | | ref="treeLeftRef" |
| | | style="padding: 10px;overflow: scroll" |
| | | style="padding: 10px;overflow: auto" |
| | | :style="{height:(tableHeight-20)+'px'}" |
| | | :data="treeLeft" |
| | | node-key="code" |
| | |
| | | :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"> |
| | |
| | | @keyup.enter="roleSave(data)" |
| | | > |
| | | |
| | | <span v-if="!data.isEdit"> |
| | | <span v-if="!data.isEdit&&data.identifying!=='0'&&data.identifying!=='1'"> |
| | | <i |
| | | v-if="data.code!=='000'" |
| | | class="el-icon-edit" |
| | |
| | | style="position: absolute;right: 15px;z-index:1;top:3px" |
| | | type="primary" |
| | | @click="saveClick" |
| | | >保 存</el-button> |
| | | >保 存 |
| | | </el-button> |
| | | |
| | | <el-tabs v-model="activeName" type="border-card"> |
| | | <el-tab-pane label="PC端" name="PC端"> |
| | | <el-tab-pane label="PC端" name="PC"> |
| | | <div style="display: flex;"> |
| | | |
| | | <div |
| | |
| | | highlight-current |
| | | :props="defaultPropsCenter" |
| | | show-checkbox |
| | | node-key="code" |
| | | node-key="menucode" |
| | | :default-expand-all="true" |
| | | @check-change="handleTreeCenterCheckChange" |
| | | @check="handleTreeCenterCheck" |
| | |
| | | </el-checkbox> |
| | | |
| | | <div v-if="treeCenter.length>0"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.code"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.menucode"> |
| | | |
| | | <div |
| | | v-if="item.display" |
| | | v-if="item.buttoncodelist ===null " |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | /> |
| | | |
| | | <el-checkbox-group |
| | | v-for="it in item.children" |
| | | v-if="item.expanded" |
| | | :key="it.code" |
| | | v-model="it.checkedButton" |
| | | :key="it.menucode" |
| | | v-model="it.buttonChecked" |
| | | style="margin-left: 40px;height:26px;display: flex" |
| | | @change="val=>handleCheckedButtonChange(val,it.code)" |
| | | @change="val=>handleCheckedButtonChange(val,it.menucode)" |
| | | > |
| | | |
| | | <el-checkbox |
| | | v-for="i in it.itemButton" |
| | | :key="i.code" |
| | | :label="i.name" |
| | | v-for="i in it.buttoncodelist" |
| | | :key="i" |
| | | :label="i" |
| | | style="display:flex;align-items: center" |
| | | /> |
| | | </el-checkbox-group> |
| | | |
| | | </div> |
| | | |
| | | </div> |
| | |
| | | </el-checkbox> |
| | | |
| | | <div v-if="treeCenter.length>0"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.code"> |
| | | <div v-for="item in treeCenter[0].children" :key="item.menucode"> |
| | | <div |
| | | v-if="item.display" |
| | | v-if="item.datacodelist ===null " |
| | | style="margin-left: 40px;height:26px;display: flex;" |
| | | /> |
| | | |
| | | <el-radio-group |
| | | v-for="it in item.children" |
| | | v-if="item.expanded" |
| | | :key="it.code" |
| | | v-model="it.checkedData" |
| | | :key="it.menucode" |
| | | v-model="it.dataChecked" |
| | | style="margin-left: 40px;height:26px;display: flex" |
| | | @change="val=>handleCheckedDataChange(val,it.code)" |
| | | @change="val=>handleCheckedDataChange(val,it.menucode)" |
| | | > |
| | | <el-radio |
| | | v-for="i in it.itemData" |
| | | :key="i.code" |
| | | v-for="i in it.datacodelist" |
| | | :key="i" |
| | | style="display:flex;align-items: center" |
| | | :label="i.name" |
| | | :label="i" |
| | | /> |
| | | </el-radio-group> |
| | | </div> |
| | |
| | | |
| | | </div> |
| | | </el-tab-pane> |
| | | <el-tab-pane label="APP端" name="APP端">大大</el-tab-pane> |
| | | <el-tab-pane label="APP端" name="APP">大大</el-tab-pane> |
| | | <el-tab-pane label="工控端" name="工控端">工控端</el-tab-pane> |
| | | </el-tabs> |
| | | |
| | |
| | | <script> |
| | | import waves from '@/directive/waves' |
| | | import { |
| | | DataPermissions, |
| | | RolePermissionSava, |
| | | RolePermissionSearchRole, |
| | | RolePermissionSearchRoleMenu, |
| | |
| | | }, |
| | | defaultPropsCenter: { |
| | | children: 'children', |
| | | label: 'name' |
| | | label: 'menuname' |
| | | }, |
| | | activeName: 'PC端', |
| | | activeName: 'PC', |
| | | |
| | | buttonIsChecked: false, |
| | | dataIsChecked: false, |
| | | |
| | | menuCheckedCodeArr: [], // 菜单权限数组选中的 |
| | | |
| | | allButtonData: [], // 所有的按钮加权限 |
| | | allButtonData: [], // 所有菜单对应的按钮权限加数据权限 |
| | | |
| | | isScroll: 'left' |
| | | isScroll: 'left', |
| | | |
| | | dataKeyValue: []// 数据权限键值对 |
| | | |
| | | } |
| | | }, |
| | |
| | | this.$nextTick(() => { // 默认选中第一个 |
| | | this.$refs.treeLeftRef.setCurrentKey(res[0].roles[0].code) // 默认选中节点第一个 |
| | | }) |
| | | await this.getRolePermissionSearchRoleMenuButton(res[0].roles[0].code) |
| | | await this.getRolePermissionSearchRoleMenu(res[0].roles[0].code) |
| | | |
| | | await this.getDataPermissions()// 获取数据权限键值对 |
| | | await this.getRolePermissionSearchRoleMenuButton(res[0].roles[0].code)// 用于数据回显 |
| | | |
| | | await this.getRolePermissionSearchRoleMenu(res[0].roles[0].code)// 用于渲染页面 |
| | | } else { |
| | | this.$notify.error('请先建相对应的角色!') |
| | | } |
| | | }, |
| | | async getDataPermissions() { |
| | | const { data: res } = await DataPermissions() |
| | | this.dataKeyValue = res |
| | | }, |
| | | |
| | | // 获取菜单权限对应的按钮 |
| | | async getRolePermissionSearchRoleMenuButton(rolecode) { |
| | | const { data: res } = await RolePermissionSearchRoleMenuButton({ rolecode }) |
| | | this.allButtonData = res |
| | | const { data: res } = await RolePermissionSearchRoleMenuButton({ rolecode, type: this.activeName }) |
| | | this.allButtonData = JSON.parse(res[0].jsondate) |
| | | }, |
| | | // 获取菜单权限 |
| | | async getRolePermissionSearchRoleMenu(rolecode) { |
| | | const { data: res } = await RolePermissionSearchRoleMenu({ rolecode, type: 'PC' }) |
| | | const { data: res } = await RolePermissionSearchRoleMenu({ rolecode, type: this.activeName }) |
| | | |
| | | // 拿到数组list转换成树形tree |
| | | const result = arrayToTree(res, { |
| | | parentProperty: 'parentid', |
| | | customID: 'code', |
| | | parentProperty: 'parent_id', |
| | | customID: 'menucode', |
| | | childrenProperty: 'children' |
| | | }) |
| | | |
| | | this.menuCheckedCodeArr = [] |
| | | |
| | | result.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | // 按钮权限回显 |
| | | const buttonAll = this.allButtonData.tButton.filter(j => j.menucode === it.code) |
| | | const buttonChecked = this.allButtonData.tButton.filter(j => |
| | | j.menucode === it.code && j.flag === 'Y' |
| | | ).map(j => j.name) |
| | | it.itemButton = buttonAll |
| | | it.checkedButton = buttonChecked |
| | | |
| | | // 数据权限回显 |
| | | const dataAll = this.allButtonData.tData.filter(j => j.menucode === it.code) |
| | | const dataChecked = this.allButtonData.tData.filter(j => j.menucode === it.code && j.flag === 'Y') |
| | | |
| | | it.itemData = dataAll |
| | | it.checkedData = dataChecked.length > 0 ? dataChecked[0].name : [] |
| | | |
| | | // 用作菜单勾选回显 |
| | | if (it.flag === 'Y') { |
| | | this.menuCheckedCodeArr.push(it.code) |
| | | } |
| | | }) |
| | | item.display = true |
| | | item.expanded = true |
| | | } |
| | | }) |
| | | |
| | | // console.log(JSON.parse(JSON.stringify(result)), 8) |
| | | |
| | | this.treeCenter = [ |
| | | { code: '-1', name: '全部', flag: result.every(i => i.flag === 'Y') ? 'Y' : 'N', children: result } |
| | | ] |
| | | |
| | | this.handleCheckedButtonChange('', '', true) |
| | | this.handleCheckedDataChange('', '', true) |
| | | |
| | | this.menuCheckedCodeArr = this.allButtonData.map(i => i.menucode) |
| | | this.$nextTick(() => { |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | }) |
| | | |
| | | this.$forceUpdate() |
| | | result.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | it.buttoncodelist = it.buttoncodelist ? 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 = 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) |
| | | } |
| | | 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.handleCheckedButtonChange('', '', true) |
| | | this.handleCheckedDataChange('', '', true) |
| | | // this.$forceUpdate() |
| | | console.log(JSON.parse(JSON.stringify(result)), 6) |
| | | }, |
| | | |
| | | // 左边滚动条滑动时 |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (checkedKeys.includes(it.code)) { |
| | | if (checkedKeys.includes(it.menucode)) { |
| | | if (belong === 'button') { |
| | | it.checkedButton = it.itemButton.map(i => i.name) |
| | | it.buttonChecked = it.buttoncodelist |
| | | } |
| | | if (belong === 'data') { |
| | | it.checkedData = '全部' |
| | | it.dataChecked = '全部' |
| | | } |
| | | } |
| | | }) |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (checkedKeys.includes(it.code)) { |
| | | if (checkedKeys.includes(it.menucode)) { |
| | | if (belong === 'button') { |
| | | it.checkedButton = [] |
| | | it.buttonChecked = [] |
| | | } |
| | | if (belong === 'data') { |
| | | it.checkedData = undefined |
| | | it.dataChecked = '' |
| | | } |
| | | } |
| | | }) |
| | |
| | | }, |
| | | // 单个按钮改变 |
| | | handleCheckedButtonChange(value, code, flag) { |
| | | // console.log(value, code, flag, 1) |
| | | |
| | | // console.log(JSON.parse(JSON.stringify(this.treeCenter[0])), 2) |
| | | |
| | | // 判断是否包含在内 |
| | | if (!flag) { |
| | | if (!this.menuCheckedCodeArr.includes(code) && value.length === 1) { // 否 |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.checkedButton.length === it.itemButton.length) { |
| | | if (it.buttonChecked && it.buttonChecked.length === it.buttoncodelist.length && it.buttoncodelist.length > 0) { |
| | | count++ |
| | | } |
| | | |
| | | if (it.buttoncodelist.length) { |
| | | childrenLength++ |
| | | } |
| | | console.log(count, childrenLength) |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | this.buttonIsChecked = count === childrenLength |
| | | this.$forceUpdate() |
| | | }, |
| | |
| | | // console.log(data, Node, VueComponent, 2221) |
| | | // console.log(Node.expanded) |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.name === data.name) { |
| | | if (item.menucode === data.menucode) { |
| | | item.expanded = Node.expanded |
| | | } |
| | | }) |
| | | if (data.code === '-1') { |
| | | if (data.menucode === '-1') { |
| | | Node.expanded = true // 暂时先写成这个 |
| | | // this.treeCenter[0].children.forEach(item => { |
| | | // item.expanded = Node.expanded |
| | | // }) |
| | | } |
| | | this.$forceUpdate() |
| | | }, |
| | |
| | | this.dataIsChecked = false |
| | | this.menuCheckedCodeArr = [] |
| | | } else { |
| | | if (checkedKeys.includes(obj.code)) { // 判断是否包含在内 //是 |
| | | this.menuCheckedCodeArr.push(obj.code) |
| | | if (checkedKeys.includes(obj.menucode)) { // 判断是否包含在内 //是 |
| | | this.menuCheckedCodeArr.push(obj.menucode) |
| | | } else { // 否 |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== obj.code) |
| | | this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== obj.menucode) |
| | | } |
| | | } |
| | | }, |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.code === obj.code) { |
| | | it.checkedButton = [] |
| | | it.checkedData = undefined |
| | | if (it.menucode === obj.menucode) { |
| | | it.buttonChecked = [] |
| | | it.DataChecked = '' |
| | | } |
| | | }) |
| | | } |
| | |
| | | if (!flag) { |
| | | this.menuCheckedCodeArr.push(code) |
| | | this.menuCheckedCodeArr = [...new Set(this.menuCheckedCodeArr)] |
| | | |
| | | this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr) |
| | | } |
| | | // 这里是判断全选radio 是否选中 |
| | |
| | | this.treeCenter[0].children.forEach(item => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach(it => { |
| | | if (it.checkedData.length > 0) { |
| | | if (it.dataChecked.length > 0) { |
| | | count++ |
| | | } |
| | | if (it.itemData.length > 0) { |
| | | if (it.datacodelist.length > 0) { |
| | | childrenLength++ |
| | | } |
| | | }) |
| | |
| | | }, 1000, true), |
| | | |
| | | // 页面勾选好保存事件 |
| | | saveClick() { |
| | | // console.log(this.treeCenter) |
| | | async saveClick() { |
| | | // [{"menucode":"1010","buttoncode":"Add,Update","datacode":"ALL"},] |
| | | 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 (it.buttonChecked && it.buttonChecked.length > 0) { // 已选菜单 |
| | | it.buttonChecked = this.$ButtonData.filter(i => |
| | | it.buttonChecked.includes(i.buttonname) |
| | | ).map(i => i.buttoncode) |
| | | } |
| | | arr.push({ |
| | | menucode: it.menucode, |
| | | datacode: it.dataChecked, |
| | | buttoncode: it.buttonChecked ? it.buttonChecked.join(',') : '' |
| | | }) |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | const rolecode = this.$refs.treeLeftRef.getCurrentKey() |
| | | |
| | | const roleMenu = [] |
| | | const roleButton = [] |
| | | const roleData = [] |
| | | |
| | | this.treeCenter[0].children.forEach((item, index) => { |
| | | if (item.children && item.children.length) { |
| | | item.children.forEach((it, ind) => { |
| | | if (it.flag === 'Y') { |
| | | roleMenu.push({ rolecode, menucode: it.code }) |
| | | |
| | | if (it.itemButton && it.itemButton.length && it.checkedButton.length > 0) { |
| | | it.itemButton.forEach(i => { |
| | | if (it.checkedButton.includes(i.name)) { |
| | | roleButton.push({ rolecode, buttoncode: i.code }) |
| | | } |
| | | }) |
| | | } |
| | | if (it.checkedData && it.checkedData.length) { |
| | | roleData.push({ rolecode, datacode: it.itemData.find(i => i.name === it.checkedData).code }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | // console.log(roleMenu) |
| | | // console.log(roleButton) |
| | | // console.log(roleData) |
| | | const data = { |
| | | roleMenu, roleButton, roleData |
| | | } |
| | | |
| | | RolePermissionSava(data).then(res => { |
| | | // 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 + '的角色权限提交成功!') |
| | | this.getRolePermissionSearchRoleMenuButton(rolecode) |
| | | this.getRolePermissionSearchRoleMenu(rolecode) |
| | | await this.getRolePermissionSearchRoleMenuButton(rolecode) |
| | | await this.getRolePermissionSearchRoleMenu(rolecode) |
| | | } |
| | | this.$forceUpdate() |
| | | }) |
| | | }, |
| | | // 获取页面高度 |
| | | getHeight() { |
| | |
| | | this.mainHeight = window.innerHeight - 85 |
| | | this.tableHeight = this.mainHeight - 50 |
| | | }) |
| | | }, |
| | | // 左侧树形拖动处理 |
| | | treeLeftAllowDrop(draggingNode, dropNode, type) { |
| | | // console.log(draggingNode, dropNode, type) |
| | | // 注掉的是同级拖拽 |
| | | if (draggingNode.level === dropNode.level) { |
| | | return type === 'prev' || type === 'next' |
| | | } else { |
| | | // 不同级进行处理 |
| | | return false |
| | | } |
| | | } |
| | | } |
| | | } |