rightsManagement.vue 6.73 KB
Newer Older
fengzhaoyu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <div class="rightManagement">
    <!-- 超级管理员    -->
    <div class="superAdministrator">
      <div class="superAdministratorTitle">
        1.超级管理员
        <span>(该角色拥有系统的所有权限)</span>
      </div>
      <div class="superAdministratorTable">
        <a-table :columns="columns" :dataSource="superAdministratorList" size="default" rowKey="key" :pagination="false">
          <span slot="userHasRoles" slot-scope="userHasRoles">
            <a-tag  v-for="(userHasRole, index) in userHasRoles" :key="index">{{userHasRole}}</a-tag>
          </span>
          <span slot="action" slot-scope="text, record, index">
fengzhaoyu committed
15
            <a href="javascript:;" @click="selectSuperAdministrator(record, text, index, superAdministratorListId)">编辑</a>
fengzhaoyu committed
16 17 18 19 20 21 22 23 24
          </span>
        </a-table>
      </div>
    </div>
    <!--  角色  -->
    <div class="role">
      <div class="roleTitle">2.创建角色</div>
      <div class="roleTable">
        <a-button type="primary" icon="plus" class="addRole" @click="addRole" key="key">添加</a-button>
fengzhaoyu committed
25
        <a-table :columns="roleColumns" :dataSource="roleList" size="default" rowKey="key" :pagination="false">
fengzhaoyu committed
26 27 28 29
          <span slot="userHasRoles" slot-scope="userHasRoles">
            <a-tag  v-for="(userHasRole, index) in userHasRoles" :key="index">{{userHasRole}}</a-tag>
          </span>
          <span slot="action" slot-scope="text, record, index">
fengzhaoyu committed
30
            <a href="javascript:;" @click="editRoles(record, text, index)">编辑</a>
fengzhaoyu committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
            <a href="javascript:;" class="delete" @click="delectRoles(record, text, index)">删除</a>
          </span>
        </a-table>
      </div>
    </div>
  </div>
</template>

<script>
import { config } from '../../../api/config.js'
import { $http } from '../../../api/axios.js'
export default {
  name: 'rightsManagement',
  component: {},
  data () {
    return {
      columns: [{
        title: '角色名称',
fengzhaoyu committed
49 50
        dataIndex: 'administratorName',
        width: '30%'
fengzhaoyu committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
      }, {
        title: '拥有该角色的员工',
        dataIndex: 'userHasRoles',
        width: '60%',
        scopedSlots: { customRender: 'userHasRoles' }
      }, {
        title: '操作',
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' }
      }],
      roleColumns: [{
        title: '角色名称',
        dataIndex: 'roleName'
      }, {
        title: '角色描述',
liang ce committed
66
        dataIndex: 'roleDesc'
fengzhaoyu committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80
      }, {
        title: '拥有该角色的员工',
        dataIndex: 'userHasRoles',
        scopedSlots: { customRender: 'userHasRoles' }
      }, {
        title: '创建时间',
        dataIndex: 'creatTime'
      }, {
        title: '操作',
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' }
      }],
      superAdministratorList: [], // 超级管理员列表
      roleList: [], // 超级管理员列表
fengzhaoyu committed
81
      superAdministratorListId: [] // 超级管理员的ddId
fengzhaoyu committed
82 83 84 85 86 87 88
    }
  },
  created () {
    this.getAllAdminisgtrator()
  },
  methods: {
    // 编辑超级管理员
fengzhaoyu committed
89
    selectSuperAdministrator (record, text, index, superAdministratorListId) {
fengzhaoyu committed
90
      config.ddready('ddchooseTen', superAdministratorListId).then((res) => {
fengzhaoyu committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        let roleId = record.key
        let roleName = record.administratorName
        let roleDesc = ''
        let ddUserIds = []
        let menuIds = []
        let roleCode = record.roleCode
        res.users.forEach((item, index) => {
          ddUserIds.push(item.emplId)
        })
        let data = {
          roleId: roleId,
          roleName: roleName,
          roleDesc: roleDesc,
          ddUserIds: ddUserIds,
          menuIds: menuIds,
          roleCode: roleCode
        }
        $http.post(`/admin/manager/modifyFullRole`, data).then(success => {
liang ce committed
109
          this.$message.success('编辑成功')
fengzhaoyu committed
110 111
          return this.getAllAdminisgtrator()
        })
fengzhaoyu committed
112 113 114 115
      })
    },
    // 删除角色
    delectRoles (record) {
fengzhaoyu committed
116
      const _that = this
fengzhaoyu committed
117 118
      this.$confirm({
        title: '确认要删除该角色吗?',
fengzhaoyu committed
119
        content: '删除后,拥有该角色员工自动解除',
fengzhaoyu committed
120 121 122
        okText: '确定',
        cancelText: '取消',
        onOk () {
fengzhaoyu committed
123
          let data = { roleId: record.key }
liang ce committed
124 125
          $http.post(`/admin/role/del1`, data).then(res => {
            _that.$message.success('删除成功')
fengzhaoyu committed
126 127
            _that.getAllAdminisgtrator()
          })
fengzhaoyu committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
        }
      })
    },
    // 增加角色
    addRole (obj) {
      // console.log(obj, 111)
      // this.chooseMenuList = obj.key
      this.$router.push({ name: 'addOrRights' })
    },
    // 获取所有管理员列表
    getAllAdminisgtrator () {
      let data = {
        item: 'e-card'
      }
      $http.post(`/admin/role/page1`, data).then(res => {
fengzhaoyu committed
143 144 145
        this.superAdministratorList = []
        this.roleList = []
        this.superAdministratorListId = []
fengzhaoyu committed
146 147 148 149
        res.data.data.forEach((item, index) => {
          if (item.roleCode === 'ROLE_SUPER_ADMIN') {
            let userHasRoles = []
            item.userList.forEach((userItem, userIndex) => {
liang ce committed
150
              userHasRoles.push(userItem.realName)
fengzhaoyu committed
151 152 153
              this.superAdministratorListId.push(userItem.ddUserId)
            })
            this.superAdministratorList.push({
fengzhaoyu committed
154
              roleCode: item.roleCode,
fengzhaoyu committed
155 156 157 158 159
              key: item.roleId,
              administratorName: item.roleName,
              userHasRoles: userHasRoles
            })
          } else {
fengzhaoyu committed
160 161 162
            let userHasRoles = []
            let ddUserId = []
            item.userList.forEach((userItem, userIndex) => {
liang ce committed
163
              userHasRoles.push(userItem.realName)
fengzhaoyu committed
164 165
              ddUserId.push(userItem.ddUserId)
            })
fengzhaoyu committed
166 167
            this.roleList.push({
              key: item.roleId,
liang ce committed
168
              roleName: item.roleName,
fengzhaoyu committed
169 170
              userHasRoles: userHasRoles,
              roleDesc: item.roleDesc,
liang ce committed
171
              creatTime: item.createTime ? item.createTime.replace('T', ' ') : '',
fengzhaoyu committed
172
              action: { ddUserId: ddUserId, name: userHasRoles }
fengzhaoyu committed
173 174 175 176
            })
          }
        })
      })
fengzhaoyu committed
177 178 179 180 181
    },
    // 编辑角色
    editRoles (record) {
      this.$router.push({ name: 'addOrRights', params: { roleId: record.key, record: record } })
      let data = { roleId: record.key }
fengzhaoyu committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    }
  },
  watch: {
    $route (to, from) {
      this.defaultSelectedKeys = to.name
      this.chooseMenuList = to.name
    }
  }
}
</script>

<style scoped>
  a {
    text-decoration: none;
  }
  .superAdministratorTitle,
  .roleTitle {
    height: 40px;
    width: 100%;
    line-height: 40px;
    color: rgba(0,0,0,0.85);
    font-weight: 500;
  }
  .superAdministratorTitle>span {
    color: #A0A0A0;
  }
  .superAdministratorTable {
    margin-top: 20px;
  }
  .role {
    margin-top: 20px;
  }
  .addRole {
    margin-top: 25px;
    margin-bottom: 20px;
  }
  .delete {
    margin-left: 5px;
  }
</style>