123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <template>
- <el-dialog class="settingDialog" title="角色权限配置" width="750px" :visible.sync="visible">
- <div class="roleSettings">
- <div class="roleName">
- <div class="roleNameLeft">
- <p>角色名称</p>
- <el-input placeholder="请输入内容" v-model="role.name" :disabled="true"></el-input>
- </div>
- <p style="color:#338AFB" v-if="role.is_system == 0" @click="disableRoleAction(role.id)">删除该角色</p>
- </div>
- <div class="roleMain" >
- <div class="roleMainLeft" >
- <p class="roletitle">选择权限</p>
- <div class="roleMainLeftBox">
- <!--<el-tree-->
- <!--:props="defaultProps"-->
- <!--:data="data"-->
- <!--:default-checked-keys="data"-->
- <!--node-key="id"-->
- <!--ref="tree"-->
- <!--default-expand-all-->
- <!--show-checkbox-->
- <!-->-->
- <!--<!– <span class="custom-tree-node" slot-scope="{ node, data }">-->
- <!--<span>{{ data.name }}</span>-->
- <!--</span>–>-->
- <!--</el-tree>-->
- <el-tree v-loading="loading" :props="treeProps" :data="purviews" :default-checked-keys="default_checkeds" node-key="id"
- ref="tree" default-expand-all show-checkbox>
- <span class="custom-tree-node" slot-scope="{ node, data }">
- <span>{{ data.name }}</span>
- </span>
- </el-tree>
- </div>
- </div>
- <!--<div class="roleMainRight">-->
- <!--<div class="hasChoose">已选择权限</div>-->
- <!--<el-tree-->
- <!--:props="treeProps" :data="check_purviews" node-key="id" ref="tree" default-expand-all-->
-
- <!--></el-tree>-->
- <!--</div>-->
- </div>
- </div>
- <div slot="footer" class="dialog-footer">
- <el-button @click="hide">取 消</el-button>
- <el-button type="primary" @click="submitAction" :loading="submitLoading">保 存</el-button>
- </div>
- </el-dialog>
- </template>
-
- <script>
- import { editPurview, getEditPurviewInitData, setRoleStatus } from '@/api/role/role'
-
- export default {
- data() {
- return {
- visible: false,
- loading: true,
- submitLoading:false,
- role_id: 0,
- name: '',
- role: {
- name:"",
- },
- purviews: [],
- treeProps: {
- label: 'name',
- children: 'childs'
- },
- default_checkeds: [],
- check_purviews: [],
- defaultProps: {
- children: 'children',
- label: 'label'
- }
- }
- },
- methods: {
- disableRoleAction: function(id) {
- this.$msgbox({
- title: '提示',
- message: '是否确定要移除该角色',
- showCancelButton: true,
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- beforeClose: (action, instance, done) => {
- if (action === "confirm") {
-
- instance.confirmButtonLoading = true;
- instance.confirmButtonText = "移除中...";
- setRoleStatus(id, false)
- .then(rs => {
- done();
- instance.confirmButtonLoading = false;
- const resp = rs.data
- if (resp.state === 1) {
- this.$emit('delete')
- } else {
- this.$message.error(resp.msg)
- }
- })
- .catch(err => {
- done();
- this.$message.error(err);
- instance.confirmButtonLoading = false;
- })
- }else{
-
- done();
- }
- }
- })
- },
-
- submitAction: function() {
-
- if (this.role_id <= 0) {
- return
- }
-
- var checkeds = this.$refs.tree.getCheckedKeys(true)
-
- var ids = []
- var func_ids = []
-
- if (checkeds.length > 0) {
- this.purviews.forEach(purview => {
- if (purview.childs != null && purview.childs.length > 0) {
- purview.childs.forEach(childs => {
- if (childs.childs == null) {
- if (checkeds.indexOf(childs.id) != -1) {
- if (ids.indexOf(purview.id) == -1) {
- ids.push(purview.id)
- }
- ids.push(childs.id)
-
- }
- } else {
- console.log(childs.name)
- if (childs.name == '透析记录') {
-
- childs.childs.forEach(child => {
- if (checkeds.indexOf(child.id) != -1) {
- if (func_ids.indexOf(childs.id) == -1) {
- func_ids.push(childs.id)
- }
- func_ids.push(child.id)
- }
- })
- } else {
- childs.childs.forEach(child => {
- if (checkeds.indexOf(child.id) != -1) {
- if (ids.indexOf(childs.id) == -1) {
- ids.push(childs.id)
- }
- ids.push(child.id)
- }
- })
-
- }
-
- }
- })
-
- } else {
- if (checkeds.indexOf(purview.id) != -1) {
- ids.push(purview.id)
- }
- }
- })
- }
- var idsStr = ''
- if (ids.length > 0) {
- idsStr = ids.join(',')
- }
-
- var funcIdsStr = ''
- if (func_ids.length > 0) {
- funcIdsStr = func_ids.join(',')
- }
- this.submitLoading = true
- editPurview(this.role_id, idsStr, funcIdsStr).then(rs => {
- var resp = rs.data
- this.submitLoading = false
-
- if (resp.state === 1) {
- this.hide()
- } else {
- this.$message.error(resp.msg)
- }
- }).catch(err => {
- this.submitLoading = false
- this.$message.error(err)
- })
- },
-
- show(role_id) {
- this.loading = true
- this.visible = true
- this.default_checkeds = []
- this.purviews = []
-
-
-
- var id = parseInt(role_id)
- if (id <= 0) {
- this.$message.error('参数错误')
- return
- }
- this.role_id = role_id
- getEditPurviewInitData(this.role_id).then(rs => {
- var resp = rs.data
- if (resp.state === 1) {
- this.role = resp.data.role
- this.purviews.push(...resp.data.purviews)
- // 初始化默认选中项
- var role_purview_ids = resp.data.role_purview_ids
- var checkeds = []
- if (role_purview_ids.length > 0) {
- var ids = role_purview_ids.split(',')
- this.purviews.forEach(purview => {
- if (purview.childs != null && purview.childs.length > 0) {
- purview.childs.forEach(childs => {
-
- if (childs.childs != null && childs.childs.length > 0) {
- childs.childs.forEach(child => {
- if (ids.indexOf(child.id + '') != -1) {
- checkeds.push(child.id)
- }
- })
-
- }else{
- if (ids.indexOf(childs.id + '') != -1) {
- checkeds.push(childs.id)
- }
- }
- })
-
- } else {
- if (ids.indexOf(purview.id + '') != -1) {
- checkeds.push(purview.id)
- }
- }
- })
- }
-
-
-
- this.$nextTick(() => {
- this.default_checkeds = checkeds
- })
-
- this.loading = false
-
- } else {
- this.loading = false
-
- this.$message.error(resp.msg)
- }
- }).catch(err => {
- this.loading = false
-
- this.$message.error(err)
- })
- },
- hide() {
- this.visible =false
-
- }
-
- }, created() {
-
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .roleSettings {
-
- .roleName {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .roleNameLeft {
- display: flex;
- align-items: center;
-
- p {
- width: 100px;
- }
-
- }
- .roleMain {
- display: flex;
- justify-content: space-between;
- margin-top: 18px;
-
- .roleMainLeft {
- display: flex;
-
- .roletitle {
- width: 74px;
- }
-
- .roleMainLeftBox {
- width: 500px;
- height: 706px;
- overflow-y: auto;
- border: 1px solid rgba(234, 238, 240, 1);
- border-radius: 4px;
- padding: 20px 0 0 10px;
- }
-
- }
- .roleMainRight {
- width: 280px;
- height: 706px;
- overflow-y: auto;
- border: 1px solid rgba(235, 238, 240, 1);
- color: #303133;
-
- .hasChoose {
- height: 42px;
- line-height: 42px;
- padding-left: 20px;
- background: #f6f8f9;
- }
-
- }
- }
- }
- </style>
-
- <style lang="scss">
- .settingDialog {
-
- .el-dialog__body {
- max-height: 600px !important;
- }
-
- }
- </style>
|