| | |
| | | <div> |
| | | <div class="content-main"> |
| | | <div class="top-bar"> |
| | | <el-form ref="form" :inline="true" :model="searchData"> |
| | | <el-form style="display: flex;align-items: center;margin-top: 10px;" ref="form" :inline="true" :model="searchData"> |
| | | <el-form-item label="角色名称:" class="sermargin"> |
| | | <el-input v-model="searchData.roleName" class="input-form" placeholder="请输入角色名称" style="width:250px"> |
| | | <el-input size="small" v-model="searchData.roleName" class="input-form" placeholder="请输入角色名称" style="width:250px"> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item class="rightBtn"> |
| | | <el-button type="primary">查询</el-button> |
| | | <el-button type="primary" plain>重置</el-button> |
| | | <el-col> |
| | | <el-button size="small" type="primary" @click="searchRole">查询</el-button> |
| | | <el-button size="small" type="primary" @click="clear()" plain>重置</el-button> |
| | | </el-col> |
| | | </el-form-item> |
| | | </el-form> |
| | | <el-form> |
| | | <el-form style="margin-top: 10px;"> |
| | | <el-form-item class="rightBtn"> |
| | | <el-button type="primary" @click="addClickRole" icon="el-icon-plus">新增角色</el-button> |
| | | <el-button size="small" type="primary" @click="addClickRole" icon="el-icon-plus">新增角色</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-form> |
| | | </div> |
| | | <div class="library-table"> |
| | | <div class="table-box"> |
| | | <el-table :max-height="800" :cell-style="{ textAlign: 'center' }" |
| | | :header-cell-style="{ border: '0px', background: '#f5f7fa', color: '#606266', boxShadow: 'inset 0 1px 0 #ebeef5', textAlign: 'center' }" |
| | | <el-table :max-height="800" :cell-style="{ textAlign: 'left' }" |
| | | :header-cell-style="{ border: '0px', background: '#f5f7fa', color: '#606266', boxShadow: 'inset 0 1px 0 #ebeef5', textAlign: 'left' }" |
| | | :data="roleTable" style="width: 100%"> |
| | | <el-table-column type="index" min-width="8%" /> |
| | | <el-table-column prop="roleName" label="角色名称" min-width="20%" /> |
| | |
| | | <el-table-column prop="updateTime" label="更新时间" min-width="20%" /> |
| | | <el-table-column label="操作" min-width="12%"> |
| | | <template slot-scope="scope"> |
| | | <el-button type="text" size="small">编辑</el-button> |
| | | <el-button type="text" size="small">删除</el-button> |
| | | <el-button type="text" @click="selectRoleInfo(scope)" size="small">查看</el-button> |
| | | <el-button type="text" @click="upRole(scope)" size="small">编辑</el-button> |
| | | <el-button type="text" @click="removeRole(scope)" size="small">删除</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | |
| | | :default-expand-all="false" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"> |
| | | <el-table-column highlight-current-row prop="parentId" label="菜单类型" sortable width="180"> |
| | | <template slot-scope="scope"> |
| | | <span v-if="scope.row.parentId == 0 && scope.row.children != undefined" style="color: #409eff;">主菜单</span> |
| | | <span v-if="scope.row.parentId == 0 && scope.row.children === undefined" style="color: #409eff;"> |
| | | <span v-if="scope.row.parentId == 0" style="color: #409eff;">主菜单</span> |
| | | <!-- <span v-if="scope.row.parentId == 0 && scope.row.children === undefined" style="color: #409eff;"> |
| | | 主菜单 |
| | | </span> |
| | | </span> --> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="name" label="菜单名" sortable width="180"> |
| | |
| | | <el-button type="primary" @click="addRole">确 定</el-button> |
| | | </span> |
| | | </el-dialog> |
| | | |
| | | <el-dialog top="5vh" title="编辑角色" :visible.sync="dialogTableVisibleUpdate" width="50%"> |
| | | <el-form :model="updateRole" ref="updateRole" label-position="right" label-width="100px"> |
| | | <el-col :span="24" style="display: flex;justify-content: space-between;"> |
| | | <el-form-item :rules="nameaRules" label="角色名:"> |
| | | <el-input @blur="assertUpName" style="width: 300px" v-model="updateRole.roleName" placeholder="请输入角色名"> |
| | | </el-input> |
| | | </el-form-item> |
| | | <!-- <el-form-item label="菜单选择:"> |
| | | <el-cascader style="width: 300px" collapse-tags size="medium " filterable :props="props" |
| | | v-model="roleAdd.menuData" :options="menuInfo"> |
| | | <template slot-scope="{ data }"> |
| | | <span>{{ data.label }}</span> |
| | | </template> |
| | | </el-cascader> |
| | | </el-form-item> --> |
| | | </el-col> |
| | | </el-form> |
| | | <el-col :span="24"> |
| | | <el-table height="500" :data="menuUpdateInfo" style="width: 100%;margin-bottom: 20px;" row-key="id" |
| | | :default-expand-all="true" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"> |
| | | <el-table-column highlight-current-row prop="parentId" label="菜单类型" sortable width="180"> |
| | | <template slot-scope="scope"> |
| | | <span v-if="scope.row.parentId == 0" style="color: #409eff;">主菜单</span> |
| | | <!-- <span v-if="scope.row.parentId == 0 && scope.row.children === undefined" style="color: #409eff;"> |
| | | 主菜单 |
| | | </span> --> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="name" label="菜单名" sortable width="180"> |
| | | <template slot-scope="scope"> |
| | | <el-col v-if="scope.row.parentId == 0"> |
| | | <span style="color: #409eff;">{{ scope.row.name }}</span> |
| | | </el-col> |
| | | <el-col v-else> |
| | | <span style="color: #40b815;">{{ scope.row.name }}</span> |
| | | </el-col> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="id" label="操作权限"> |
| | | <template slot-scope="scope"> |
| | | <el-col v-if="scope.row.parentId == 0 && scope.row.children != undefined"> |
| | | <!-- <el-checkbox v-model="scope.row.select">查询</el-checkbox> --> |
| | | </el-col> |
| | | <el-col v-else> |
| | | <el-checkbox size="medium" v-model="scope.row.selected" @change="chekSelect(scope)">查询</el-checkbox> |
| | | <el-checkbox size="medium" v-model="scope.row.added" @change="chekAdd(scope)">添加</el-checkbox> |
| | | <el-checkbox size="medium" v-model="scope.row.updated" @change="chekUpdate(scope)">修改</el-checkbox> |
| | | <el-checkbox size="medium" v-model="scope.row.deleted" @change="chekDelet(scope)">删除</el-checkbox> |
| | | </el-col> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </el-col> |
| | | <span slot="footer" class="dialog-footer"> |
| | | <el-button @click="clearUPAll">取 消</el-button> |
| | | <el-button type="primary" @click="cilckUP">确 定</el-button> |
| | | </span> |
| | | </el-dialog> |
| | | |
| | | <el-dialog top="5vh" title="角色察看" :visible.sync="dialogTableSelectVisible" width="50%"> |
| | | <el-form :model="selectMenuInfo" ref="selectMenuInfo" label-position="right" label-width="100px"> |
| | | <el-col :span="24" style="display: flex;justify-content: space-between;"> |
| | | <el-form-item label="角色名:"> |
| | | <el-input style="width: 300px" v-model="selectMenuInfo.roleName" readonly> |
| | | </el-input> |
| | | </el-form-item> |
| | | <!-- <el-form-item label="菜单选择:"> |
| | | <el-cascader style="width: 300px" collapse-tags size="medium " filterable :props="props" |
| | | v-model="roleAdd.menuData" :options="menuInfo"> |
| | | <template slot-scope="{ data }"> |
| | | <span>{{ data.label }}</span> |
| | | </template> |
| | | </el-cascader> |
| | | </el-form-item> --> |
| | | </el-col> |
| | | </el-form> |
| | | <el-col :span="24"> |
| | | <el-table height="500" :data="selectMenuInfo.menuData" style="width: 100%;margin-bottom: 20px;" row-key="menuId" |
| | | :default-expand-all="true" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"> |
| | | <el-table-column highlight-current-row prop="parentId" label="菜单类型" sortable width="180"> |
| | | <template slot-scope="scope"> |
| | | <span v-if="scope.row.parentId == 0" style="color: #409eff;">主菜单</span> |
| | | <!-- <span v-if="scope.row.parentId == 0 && scope.row.children === undefined" style="color: #409eff;"> |
| | | 主菜单 |
| | | </span> --> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="menuName" label="菜单名" sortable width="180"> |
| | | <template slot-scope="scope"> |
| | | <el-col v-if="scope.row.parentId == 0"> |
| | | <span style="color: #409eff;">{{ scope.row.menuName }}</span> |
| | | </el-col> |
| | | <el-col v-else> |
| | | <span style="color: #40b815;">{{ scope.row.menuName }}</span> |
| | | </el-col> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="menuId" label="操作权限"> |
| | | <template slot-scope="scope"> |
| | | <el-col v-if="scope.row.parentId == 0 && scope.row.children.length > 0"> |
| | | <!-- <el-checkbox v-model="scope.row.select">查询</el-checkbox> --> |
| | | </el-col> |
| | | <el-col id="selectRoleCheck" class="selectRoleCheck" v-else> |
| | | <el-checkbox size="medium" disabled v-model="scope.row.selected">查询</el-checkbox> |
| | | <el-checkbox size="medium" disabled v-model="scope.row.added">添加</el-checkbox> |
| | | <el-checkbox size="medium" disabled v-model="scope.row.updated">修改</el-checkbox> |
| | | <el-checkbox size="medium" disabled v-model="scope.row.deleted">删除</el-checkbox> |
| | | </el-col> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </el-col> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { getMenusTree, addRoleInfo, assertRepeat, getAllRoleAndMenuInfo } from '@/api/laboratory/role' |
| | | import { getMenusTree, addRoleInfo, assertRepeat, getAllRoleAndMenuInfo, deleteRole, updateRoleMenu } from '@/api/laboratory/role' |
| | | import { default as menuPower } from './menuPower.vue' |
| | | export default { |
| | | components: { |
| | |
| | | data() { |
| | | return { |
| | | props: { multiple: true }, |
| | | dialogTableVisibleUpdate: false, |
| | | updateRole: { |
| | | roleId: null, |
| | | roleName: null, |
| | | lastName: null, |
| | | menuData: null, |
| | | lastMenuSelect: null |
| | | }, |
| | | selectRole: [], |
| | | roleAdd: { |
| | | roleName: null, |
| | | menuData: null |
| | |
| | | menuTableTree: null, |
| | | searchData: { |
| | | roleName: '', |
| | | permission: '' |
| | | }, |
| | | assertRepeatName: true, |
| | | menuInfo: [], |
| | | menuUpdateInfo: [], |
| | | selectMenuInfo: { |
| | | roleName: null, |
| | | menuData: null |
| | | }, |
| | | roleTable: [], |
| | | updateData: { |
| | | oldPassWord: '', |
| | |
| | | confirmPassWord: '' |
| | | }, |
| | | dialogTableVisible: false, |
| | | dialogTableSelectVisible: false, |
| | | addOrUp: false, |
| | | currentPage: 1, |
| | | pageSize: 5, |
| | | total: 20 |
| | |
| | | this.start() |
| | | }, |
| | | methods: { |
| | | chekSelect(scope) { |
| | | selectRoleInfo(scope) { |
| | | this.selectMenuInfo.roleName = scope.row.roleName |
| | | this.selectMenuInfo.menuData = scope.row.roleMenuList |
| | | console.log(this.selectMenuInfo.menuData); |
| | | this.dialogTableSelectVisible = true |
| | | }, |
| | | searchRole() { |
| | | this.start() |
| | | }, |
| | | clear(){ |
| | | this.searchData.roleName='' |
| | | this.start() |
| | | }, |
| | | clearUPAll() { |
| | | this.updateRole = { |
| | | roleId: null, |
| | | roleName: null, |
| | | lastName: null, |
| | | menuData: null, |
| | | lastMenuSelect: null |
| | | } |
| | | this.menuUpdateInfo = [] |
| | | this.dialogTableVisibleUpdate = false |
| | | }, |
| | | async cilckUP() { |
| | | if (this.updateRole.roleName == null || this.updateRole.roleName == '') { |
| | | this.$message({ |
| | | message: '请输入角色名', |
| | | type: 'warning' |
| | | }); |
| | | return |
| | | } |
| | | if (!this.assertRepeatName) { |
| | | this.$message({ |
| | | message: '角色名重复,请重新输入', |
| | | type: 'warning' |
| | | }); |
| | | return |
| | | } |
| | | this.menuUpdateInfo.forEach(item => { |
| | | if (item.children != undefined) { |
| | | item.children.forEach(c => { |
| | | if (c.added) { |
| | | item.selected = true |
| | | } |
| | | if (c.selected) { |
| | | item.selected = true |
| | | } |
| | | if (c.updated) { |
| | | item.selected = true |
| | | } |
| | | if (c.deleted) { |
| | | item.selected = true |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | console.log(this.menuUpdateInfo); |
| | | this.updateRole.menuData = JSON.parse(JSON.stringify(this.menuUpdateInfo)); |
| | | this.updateRole.menuData.forEach(item => { |
| | | if (item.children != undefined) { |
| | | let child = item.children.filter(c => { |
| | | return c.added == true || c.selected == true || c.deleted == true || c.updated === true |
| | | }) |
| | | item.children = child |
| | | } |
| | | }) |
| | | this.updateRole.menuData = this.updateRole.menuData.filter(item => { |
| | | return item.selected == true |
| | | }) |
| | | this.assertDeleteOrUp() |
| | | console.log(this.updateRole); |
| | | let up = await updateRoleMenu(this.updateRole) |
| | | if (up.data) { |
| | | this.$message({ |
| | | type: 'success', |
| | | message: '编辑成功!' |
| | | }); |
| | | this.start() |
| | | this.clearUPAll() |
| | | } else { |
| | | this.$message.error('编辑失败!请重新操作'); |
| | | } |
| | | |
| | | }, |
| | | async upRole(scope) { |
| | | this.updateRole.roleId = scope.row.roleId |
| | | this.updateRole.roleName = scope.row.roleName |
| | | this.updateRole.lastName = scope.row.roleName |
| | | let menuSelect = scope.row.roleMenuList |
| | | this.updateRole.lastMenuSelect = scope.row.roleMenuList |
| | | let res = await getMenusTree(); |
| | | this.menuUpdateInfo = res.data |
| | | this.menuUpdateInfo.forEach(item => { |
| | | this.$set(item, 'added', false); |
| | | this.$set(item, 'updated', false); |
| | | this.$set(item, 'deleted', false); |
| | | this.$set(item, 'selected', false); |
| | | if (item.children.length == 0) { |
| | | delete item['children'] |
| | | } else { |
| | | item.children.forEach(c => { |
| | | this.$set(c, 'selected', false); |
| | | this.$set(c, 'added', false); |
| | | this.$set(c, 'updated', false); |
| | | this.$set(c, 'deleted', false); |
| | | if (c.children.length == 0) { |
| | | delete c['children'] |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | menuSelect.forEach(ms => { |
| | | this.menuUpdateInfo.forEach(item => { |
| | | if (ms.menuName === item.name) { |
| | | item.selected = ms.selected |
| | | item.added = ms.added |
| | | item.deleted = ms.deleted |
| | | item.updated = ms.updated |
| | | ms.children.forEach(msc => { |
| | | if (item.children != undefined) { |
| | | item.children.forEach(itemc => { |
| | | if (itemc.name === msc.menuName) { |
| | | itemc.selected = msc.selected |
| | | itemc.added = msc.added |
| | | itemc.deleted = msc.deleted |
| | | itemc.updated = msc.updated |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | }) |
| | | this.dialogTableVisibleUpdate = true |
| | | }, |
| | | removeRole(scope) { |
| | | this.$confirm('此操作将删除该角色, 是否继续?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(async () => { |
| | | this.roleTable = this.roleTable.filter(item => { |
| | | return item.roleId != scope.row.roleId |
| | | }); |
| | | this.$message({ |
| | | type: 'success', |
| | | message: '删除成功!' |
| | | }); |
| | | await deleteRole({ id: scope.row.roleId }) |
| | | }).catch(() => { |
| | | this.$message({ |
| | | type: 'info', |
| | | message: '已取消删除' |
| | | }); |
| | | }); |
| | | }, |
| | | async start() { |
| | | let res = await getAllRoleAndMenuInfo() |
| | | this.roleTable = res.data |
| | | console.log(res); |
| | | let res = await getAllRoleAndMenuInfo({ currentPage: this.currentPage, pageSize: this.pageSize, name: this.searchData.roleName }) |
| | | res.data.list.forEach(item => { |
| | | item.roleId = String(item.roleId) |
| | | }) |
| | | this.roleTable = res.data.list |
| | | this.total = res.data.total |
| | | }, |
| | | async assertName() { |
| | | if (this.roleAdd.roleName == null || this.roleAdd.roleName == '') { |
| | |
| | | } |
| | | }, |
| | | chekAdd(scope) { |
| | | scope.row.selected = true |
| | | if (scope.row.added) { |
| | | scope.row.selected = true |
| | | } |
| | | this.updateFatherState(scope) |
| | | }, |
| | | chekUpdate(scope) { |
| | | scope.row.selected = true |
| | | if (scope.row.updated) { |
| | | scope.row.selected = true |
| | | } |
| | | this.updateFatherState(scope) |
| | | }, |
| | | chekDelet(scope) { |
| | | scope.row.selected = true |
| | | if (scope.row.deleted) { |
| | | scope.row.selected = true |
| | | } |
| | | this.updateFatherState(scope) |
| | | }, |
| | | chekSelect(scope) { |
| | | this.updateFatherState(scope) |
| | | }, |
| | | updateFatherState(scope) { |
| | | if (this.menuUpdateInfo != []) { |
| | | this.menuUpdateInfo.forEach(item => { |
| | | if (item.id == scope.row.parentId) { |
| | | if (item.children != undefined) { |
| | | let childrenFalse = item.children.length * 4; |
| | | let countFalse = 0; |
| | | item.children.forEach(c => { |
| | | if (c.added == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.deleted == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.updated == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.selected == false) { |
| | | countFalse++; |
| | | } |
| | | }) |
| | | if (childrenFalse === countFalse) { |
| | | item.selected = false |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | if (this.menuInfo != []) { |
| | | this.menuInfo.forEach(item => { |
| | | if (item.id == scope.row.parentId) { |
| | | if (item.children != undefined) { |
| | | let childrenFalse = item.children.length * 4; |
| | | let countFalse = 0; |
| | | item.children.forEach(c => { |
| | | if (c.added == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.deleted == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.updated == false) { |
| | | countFalse++; |
| | | } |
| | | if (c.selected == false) { |
| | | countFalse++; |
| | | } |
| | | }) |
| | | if (childrenFalse === countFalse) { |
| | | item.selected = false |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | async addClickRole() { |
| | | let res = await getMenusTree(); |
| | |
| | | return item.selected == true |
| | | }) |
| | | let res = await addRoleInfo(this.roleAdd); |
| | | this.start() |
| | | if (res.data) { |
| | | this.$message({ |
| | | message: '添加角色成功', |
| | |
| | | this.menuInfo = [] |
| | | this.assertRepeatName = true |
| | | this.dialogTableVisible = false |
| | | }, |
| | | assertDeleteOrUp() { |
| | | console.log("---------"); |
| | | console.log(this.updateRole.menuData); |
| | | this.updateRole.lastMenuSelect |
| | | this.updateRole.menuData |
| | | let newTree = [] |
| | | let oldTree = [] |
| | | this.updateRole.menuData.forEach(item => { |
| | | const obj = { |
| | | menuId: item.id, |
| | | menuName: item.name, |
| | | added: item.added, |
| | | parentId: item.parentId, |
| | | deleted: item.deleted, |
| | | updated: item.updated, |
| | | selected: item.selected |
| | | } |
| | | newTree.push(obj) |
| | | if (item.children != undefined && obj.selected != false) { |
| | | item.children.forEach(c => { |
| | | const objc = { |
| | | menuId: c.id, |
| | | menuName: c.name, |
| | | parentId: c.parentId, |
| | | added: c.added, |
| | | deleted: c.deleted, |
| | | updated: c.updated, |
| | | selected: c.selected |
| | | } |
| | | newTree.push(objc) |
| | | }) |
| | | } |
| | | }) |
| | | console.log(newTree); |
| | | // this.updateRole.lastMenuSelect.forEach(item => { |
| | | // const obj = { |
| | | // menuId: item.menuId, |
| | | // menuName: item.menuName, |
| | | // added: item.added, |
| | | // deleted: item.deleted, |
| | | // updated: item.updated, |
| | | // selected: item.selected |
| | | // } |
| | | // if (obj.selected) { |
| | | // oldTree.push(obj) |
| | | // } |
| | | // if (item.children != [] && obj.selected != false) { |
| | | // item.children.forEach(c => { |
| | | // const objc = { |
| | | // menuId: c.menuId, |
| | | // menuName: c.menuName, |
| | | // added: c.added, |
| | | // deleted: c.deleted, |
| | | // updated: c.updated, |
| | | // selected: c.selected |
| | | // } |
| | | // oldTree.push(objc) |
| | | // }) |
| | | // } |
| | | // }) |
| | | console.log(oldTree); |
| | | // this.updateRole.lastMenuSelect = oldTree |
| | | this.updateRole.menuData = newTree |
| | | }, |
| | | async assertUpName() { |
| | | if (this.updateRole.roleName == null || this.updateRole.roleName == '') { |
| | | this.$message({ |
| | | message: '请输入角色名称!', |
| | | type: 'warning' |
| | | }); |
| | | return |
| | | } |
| | | if (this.updateRole.roleName === this.updateRole.lastName) { |
| | | return |
| | | } |
| | | let res = await assertRepeat({ roleName: this.updateRole.roleName }) |
| | | if (!res.data) { |
| | | this.assertRepeatName = false |
| | | this.$message({ |
| | | message: '角色名重复,请重新输入!', |
| | | type: 'warning' |
| | | }); |
| | | } else { |
| | | this.assertRepeatName = true |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | justify-content: end; |
| | | margin-top: 20px |
| | | } |
| | | |
| | | } |
| | | </style> |
| | | |
| | | <style> |
| | | #selectRolecheck .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after { |
| | | border-color: #fff !important; |
| | | } |
| | | |
| | | #selectRoleCheck .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner { |
| | | background-color: #409EFF; |
| | | border-color: #409EFF; |
| | | } |
| | | </style> |