1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
<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">
<a href="javascript:;" @click="selectSuperAdministrator(record, text, index, superAdministratorListId)">编辑</a>
</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>
<a-table :columns="roleColumns" :dataSource="roleList" 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">
<a href="javascript:;" @click="editRoles(record, text, index)">编辑</a>
<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: '角色名称',
dataIndex: 'administratorName',
width: '30%'
}, {
title: '拥有该角色的员工',
dataIndex: 'userHasRoles',
width: '60%',
scopedSlots: { customRender: 'userHasRoles' }
}, {
title: '操作',
dataIndex: 'action',
scopedSlots: { customRender: 'action' }
}],
roleColumns: [{
title: '角色名称',
dataIndex: 'roleName'
}, {
title: '角色描述',
dataIndex: 'roleDesc'
}, {
title: '拥有该角色的员工',
dataIndex: 'userHasRoles',
scopedSlots: { customRender: 'userHasRoles' }
}, {
title: '创建时间',
dataIndex: 'creatTime'
}, {
title: '操作',
dataIndex: 'action',
scopedSlots: { customRender: 'action' }
}],
superAdministratorList: [], // 超级管理员列表
roleList: [], // 超级管理员列表
superAdministratorListId: [] // 超级管理员的ddId
}
},
created () {
this.getAllAdminisgtrator()
},
methods: {
// 编辑超级管理员
selectSuperAdministrator (record, text, index, superAdministratorListId) {
config.ddready('ddchooseTen', superAdministratorListId).then((res) => {
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 => {
this.$message.success('编辑成功')
return this.getAllAdminisgtrator()
})
})
},
// 删除角色
delectRoles (record) {
const _that = this
this.$confirm({
title: '确认要删除该角色吗?',
content: '删除后,拥有该角色员工自动解除',
okText: '确定',
cancelText: '取消',
onOk () {
let data = { roleId: record.key }
$http.post(`/admin/role/del1`, data).then(res => {
_that.$message.success('删除成功')
_that.getAllAdminisgtrator()
})
}
})
},
// 增加角色
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 => {
this.superAdministratorList = []
this.roleList = []
this.superAdministratorListId = []
res.data.data.forEach((item, index) => {
if (item.roleCode === 'ROLE_SUPER_ADMIN') {
let userHasRoles = []
item.userList.forEach((userItem, userIndex) => {
userHasRoles.push(userItem.realName)
this.superAdministratorListId.push(userItem.ddUserId)
})
this.superAdministratorList.push({
roleCode: item.roleCode,
key: item.roleId,
administratorName: item.roleName,
userHasRoles: userHasRoles
})
} else {
let userHasRoles = []
let ddUserId = []
item.userList.forEach((userItem, userIndex) => {
userHasRoles.push(userItem.realName)
ddUserId.push(userItem.ddUserId)
})
this.roleList.push({
key: item.roleId,
roleName: item.roleName,
userHasRoles: userHasRoles,
roleDesc: item.roleDesc,
creatTime: item.createTime ? item.createTime.replace('T', ' ') : '',
action: { ddUserId: ddUserId, name: userHasRoles }
})
}
})
})
},
// 编辑角色
editRoles (record) {
this.$router.push({ name: 'addOrRights', params: { roleId: record.key, record: record } })
let data = { roleId: record.key }
}
},
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>