index.vue
10.9 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<template>
<div ref="getHeight" class="app-container">
<div class="main">
<h2 class="crumbsTitle">角色管理</h2>
<div class="container scrollTable tabConLeft">
<!-- 搜索框 -->
<div class="conSearch">
<el-form ref="ruleForm" :inline="true" :model="searchData">
<el-row>
<el-col :span="24">
<el-form-item prop="name" label="角色名称:">
<el-input
v-model="searchData.name"
placeholder="请输入"
suffix-icon="el-icon-search"
style="width: 160px;"
clearable
@click.native="handleSearch"
@keypress.native.enter="handleSearch"
/>
</el-form-item>
<el-button v-if="$hasPermission('role:add')" type="primary" class="textRight" @click="handleAdd"> 添加角色 </el-button>
</el-col>
</el-row>
</el-form>
</div>
<module-tip :data-table="dataTable" :list-loading="listLoading" />
<div v-if="dataTable.length> 0" id="resultScroll" class="roleMain">
<el-table
ref="table"
:data="dataTable"
fit
:row-class-name="row => row.row.classs ===true ? 'current-row' : ''"
style="width: 100%"
@row-click="handleClickRow"
>
<el-table-column align="left">
<template slot="header">
<span> 角色名称 </span>
</template>
<template slot-scope="{ row }">
<span>{{ ellipsis(row.name, 6) }}</span>
</template>
</el-table-column>
<el-table-column
label=""
width="120"
align="center"
>
<template slot-scope="{ row,$index }">
<div @click.stop>
<el-switch v-model="row.status" :disabled="!$hasPermission('role:update')" @change="handleState(row,$index)" />
</div>
</template>
</el-table-column>
<el-table-column align="left" width="130">
<template slot="header">
<span> 操作 </span>
</template>
<template slot-scope="{ row }">
<div class="operation">
<!-- <span @click="handleEdit(row.id)">修改</span> -->
<el-button v-if="$hasPermission('role:update')" class="inputText" :disabled="!row.status" @click.stop="handleEdit(row.id)">修改</el-button>
<el-button v-if="$hasPermission('role:delete')" class="inputText delect" :disabled="!row.status" @click.stop="handleDelete(row)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
<!-- 用户添加、编辑对话框 -->
<user-add-dialog
v-if="isShow"
ref="userDialog"
:role-data="roleData"
:roleid="roleid"
:data="formData"
:dialog="dialog"
@close="handleClose"
@getList="getList"
/>
<!-- end -->
<!-- 启用禁用 -->
<base-dialog
ref="status"
:dialog="dialog"
@handle-close="handleCloseStatus"
@state-submit="handleStateSubmit"
/>
<!-- end -->
<!-- 删除 -->
<delete
ref="delete"
:dialog="dialog"
@handle-close="handleCloseDelete"
@delete="deleteButton"
/>
<!-- end -->
</div>
<div class="container tabConRight">
<jurisdictionDialog ref="menu" :allroleid="allRoleId" :formdata="formData" @getEdit="getEdit" @getlist="getList" />
</div>
</div>
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator'
import { ellipsis, restData } from '@/utils'
// 组件
// 删除
import Delete from './components/delete.vue'
// 添加
import UserAddDialog from './components/add.vue'
import ModuleTip from '@/components/ModuleTip/index.vue'
// 启用禁用
import BaseDialog from '@/components/BaseStatus/index.vue'
import JurisdictionDialog from './components/jurisdiction.vue'
// interface接口
import { RoleTableData } from '@/pages/role/interface/types'
// api
// import { getRole, getAllTree } from '@/api/api'
import { getDataList, deleteRole, editRole, getRoleIdList, detailRole, userRole } from '@/pages/role/api'
import { hasPermission } from '../../utils/index'
@Component({
name: 'RoleList',
components: {
Delete,
UserAddDialog,
BaseDialog,
JurisdictionDialog,
ModuleTip
}
})
export default class extends Vue {
private ref = this.$refs as any
private dataTable: RoleTableData[]=[]
private listLoading = true
private isShow =false
private delectData = []
private roleData = [] as any
private roleIds = ''
private allRoleId=[]
private userData = {} as any
private formData: RoleTableData ={
status: true,
name: '',
repel: '',
applicationIds: [],
dsType: {
val: 1,
code: 'ALL'
}
} as any
private searchData = {
id: '',
name: ''
}
private dialog = {
id: '',
msg: '',
isVisible: false,
isDeleVisible: false,
isStatusVisible: false,
type: 'add',
status: false,
title: ''
}
private total = ''
private roleid='' as string
private newIndex=0
private newData ={} as any
@Watch('dataTable')
tableData(val:any) {
this.$nextTick(() => {
if ((this.$refs as any).table !== undefined) {
(this.$refs as any).table.setCurrentRow(val[0])
}
})
}
/// 生命周期
created() {
this.getList()
}
mounted() {
this.isShow = true
}
/// // 功能函数 /////
// 获取数据
private async getList() {
this.listLoading = true
const { data } = await getDataList(this.searchData)
if (data.isSuccess === true) {
this.dataTable = data.data
this.roleData = data.data
const roleId = this.$store.state.baseTreeId
if (roleId) {
this.roleid = roleId
} else {
if (data.data.length > 0) {
this.roleid = data.data[0].id
}
}
if ((this as any).$hasPermission('rule:config-get')) {
if (this.roleid !== '') {
this.getEdit(this.roleid)
this.getAllRoleId(this.roleid)
}
this.dataTable.forEach((item:any) => {
item.classs = false
if (this.roleid === item.id) {
item.classs = true
} else {
item.classs = false
}
})
}
this.roleData.forEach((item:any) => {
if (item.status === false) {
item.disabled = true
} else {
item.disabled = false
}
})
}
setTimeout(() => {
this.listLoading = false
}, 0.1)
}
// 查询角色拥有的资源id集合
private async getAllRoleId(id:string) {
const { data } = await getRoleIdList(id)
this.allRoleId = data.data
this.$store.commit('updatedMenuData', data.data.resourceIdList)
}
// 搜索
private handleSearch() {
this.getList()
}
// 启用、禁用确认
private async handleStateSubmit() {
this.userData.applicationIds = this.formData.applicationIds
delete (this.userData as any).createTime
delete (this.userData as any).updateTime
const { data } = await editRole(this.userData)
if (data.isSuccess) {
this.dialog.isStatusVisible = false
this.$message.success('操作成功!')
this.$store.commit('updatedDataTreeId', (this.userData as any).id)
this.getList()
} else {
this.$message.error(data.msg)
}
}
// 删除
private async deleteButton() {
const ids = [this.roleIds]
const { data } = await deleteRole({ ids: ids })
if (data.isSuccess === true) {
if (data.data.length > 0) {
this.$message.error(`角色"${this.dialog.title}"正在被使用,无法删除!`)
} else {
this.$message.success('删除成功!')
this.$store.commit('updatedDataTreeId', '')
}
} else {
this.$message.error(data.msg)
}
this.getList()
this.dialog.isDeleVisible = false
}
// 获取详情
private async getEdit(id: string) {
const { data } = await detailRole(id)
this.formData = data.data
this.roleData.forEach((item:any) => {
item.disabled = false
if (item.status === false || id === item.id) {
item.disabled = true
}
})
}
// 单个删除
private handleDelete(row: any) {
this.dialog.title = row.name
this.roleIds = row.id
this.dialog.isDeleVisible = true
}
// 修改
private handleEdit(id: string) {
this.dialog.type = 'edit'
this.dialog.title = '修改'
this.dialog.isVisible = true
this.getEdit(id)
}
/// // ui /////
private async handleState(value: any, index:any) {
this.newData = value
this.newIndex = index
this.getEdit(value.id)
const { data } = await userRole(value.id)
if (data.isSuccess) {
this.dialog.isStatusVisible = true
if (data.data.userList.length > 0) {
this.dialog.msg = `"${value.name}" 有用户在使用,确定要禁用么?`
} else {
this.dialog.msg = `"${value.name}" 角色权限将被禁用!`
}
}
this.userData = value
if (!value.status) {
this.dialog.title = '确认禁用'
} else {
this.dialog.msg = `"${value.name}" 启用!`
this.dialog.title = '确认启用'
}
}
// 添加关闭弹层
handleClose() {
this.dialog.isVisible = false
}
// 启用禁用弹层关闭
handleCloseStatus() {
this.dialog.isStatusVisible = false
restData(this.dataTable, this.newData, this.newIndex)
}
// 删除弹层关闭
handleCloseDelete() {
this.dialog.isDeleVisible = false
}
// 用户添加
handleAdd() {
this.dialog.isVisible = true
this.dialog.type = 'add'
this.dialog.title = '添加'
this.formData = {
status: true,
dsType: {
val: 1,
code: 'ALL'
}
}
this.searchData.name = ''
this.getList()
}
// 内容控制字数,多出的用省略号
ellipsis(value: any, num: any) {
return ellipsis(value, num)
}
// 触发当行
handleClickRow(row:any) {
if (!(this as any).$hasPermission('rule:config-get')) {
return
}
// this.roleData = row
this.dataTable.forEach((element:any) => {
if (row.id === element.id) {
element.classs = true
} else {
element.classs = false
}
})
this.getAllRoleId(row.id)
this.getEdit(row.id)
this.roleid = row.id
this.roleData.forEach((item:any) => {
if (item.status === false || row.id === item.id) {
item.disabled = true
}
})
this.ref.menu.getMenuList(row.id)
}
}
</script>
<style lang="scss" scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>