index.vue
10.7 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
<template>
<div class="system-container">
<div class="container">
<search-form
class="searchTop border-shadow"
:formModel="searchForm"
:formList="roleFormList"
>
<slot name="form-slot">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-search"
:id="tableParams.btnId"
>搜索</el-button>
<el-button
type="primary"
:size="btn_size"
icon="el-icon-refresh"
@click="refresh"
>重置</el-button>
</slot>
</search-form>
<div class="table-btn">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-plus"
@click="btnClick('create')"
>新增</el-button>
</div>
<basic-table
ref="roleTable"
:tableParams="tableParams"
:getListApi="getListApi"
:searchForm="searchForm"
:hasNum="false"
>
<span
slot="status"
slot-scope="scope"
>
<span
class="dot"
:class="scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''"
></span>
<span class="statusText">{{ scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span>
</span>
<span
slot="table-button"
slot-scope="scope"
>
<el-button
v-for="(j, idx) in tableParams.tableOption.btnList"
:key="idx"
:type="j.type"
size="mini"
plain
@click="btnClick(j.pType, scope.scope)"
>{{j.name}}</el-button>
</span>
</basic-table>
<basic-dialog
class="role"
:title="roleDialogTitle"
:isVisible="roleVisible"
@confirmDialog="handleConfirm"
@closeDialog="handleClose"
>
<slot>
<rule-form
:ruleForm="roleForm"
:rules="roleRules"
:ruleData="roleData"
:labelWidth="'120px'"
ref='roleForm'
>
<div slot="visible-type">
<el-radio-group
@change="radioChange(roleForm.roleVisibility)"
v-model="roleForm.roleVisibility"
>
<el-radio
v-for="(child,childIndex) in visibilityList"
:key="childIndex"
:label="child.code"
>{{child.value}}</el-radio>
</el-radio-group>
<el-select
v-if="roleForm.roleVisibility == 2"
v-model="roleForm.roleTenants"
placeholder="请选择"
multiple
filterable
>
<el-option
v-for="i in tenantList"
:key="i.tenantId"
:label="i.departmentName"
:value="i.tenantId"
>
</el-option>
</el-select>
</div>
<el-tree
slot="menu-list"
:data="treedata"
show-checkbox
default-expand-all
node-key="id"
ref="tree"
highlight-current
>
</el-tree>
</rule-form>
</slot>
</basic-dialog>
</div>
</div>
</template>
<script>
import { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole, getMenuTree, getVisibility } from 'services/role';
export default {
data() {
var checkMenu = (rule, value, callBack) => {
if (value && value.length == 0) {
return callBack(new Error('请选择菜单列表'))
} else {
return callBack()
}
}
return {
USERSTATUS: this.$Constants.USER_STATUS,
searchForm: {},
roleFormList: [
{
type: 'input',
inputType: 'text',
prop: 'roleName',
placeholder: '请输入角色名称'
}
],
tableParams: {
// mutiSelectName: 'role',
// mutiSelectUniqueKey: 'id',
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableColumns: [
{
label: '角色名称',
prop: 'roleName'
}, {
label: '备注',
prop: 'remark'
}, {
label: '状态',
prop: 'enableStatus',
addHtml: 'status'
}, {
label: '创建时间',
prop: 'createdDate'
}
],
tableOption: {
width: 300,
btnList: [
{
type: 'primary',
name: '编辑',
pType: 'edit'
},
{
type: 'danger',
name: '删除',
pType: 'delete'
}
]
}
},
getListApi: getRoleList,
// 弹窗数据
roleDialogTitle: '新增角色',
roleVisible: false,
roleForm: {
enableStatus: true,
menuIdList: []
},
roleData: [
{ label: '角色名称:', prop: 'roleName', type: 'input', maxlength: 50 },
{ label: '备注:', prop: 'remark', type: 'input', inputText: 'textarea', maxlength: 200, showWordLimit: true },
{ label: '状态:', prop: 'enableStatus', type: 'switch' },
{ label: '租户可见度:', prop: 'roleVisibility', type: 'customize', slotName: 'visible-type' },
{ label: '数据权限:', prop: 'rolePermissionType', type: 'radio', children: this.$Constants.ROLE_AUTH },
{ label: '菜单权限:', prop: 'menuIdList', type: 'customize', slotName: 'menu-list' }
],
roleRules: {
roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' },
{ validator: this.$Common.checkName, trigger: 'blur' },
{ min: 5, max: 50, message: '长度在 5 到 50 个字符', trigger: 'blur' }],
enableStatus: [{ required: true }],
roleVisibility: [{ required: true, message: '请选择租户可见度' }],
rolePermissionType: [{ required: true, message: '请选择数据权限' }],
menuIdList: [{ required: true, validator: checkMenu, trigger: 'blur' }]
},
treedata: [],
tenantList: [],
visibilityList: []
}
},
mounted() {
this.getTenantList()
this.getVisibility()
},
methods: {
// 重置搜索条件
refresh() {
this.searchForm = {}
},
// 确定
handleConfirm() {
this.getCheckedKeys()
console.log(this.roleForm)
this.$refs.roleForm.$children[0].validate((valid) => {
if (valid) {
let api = addRole
let params = {
remark: this.roleForm.remark,
roleName: this.roleForm.roleName,
menuIdList: this.roleForm.menuIdList
}
params.enableStatus = this.roleForm.enableStatus ? 1 : 2
params.roleVisibility = Number(this.roleForm.roleVisibility)
params.rolePermissionType = Number(this.roleForm.rolePermissionType)
if (params.roleVisibility == 2) params.roleTenants = this.roleForm.roleTenants.toString()
if (this.roleForm.id) {
api = editRole
params.roleId = this.roleForm.id
}
api(params).then(res => {
if (res.code == '200') {
this.$message({
type: 'success',
message: '操作成功!'
})
this.handleClose()
this.$refs.roleTable.refreshTable()
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
}
})
},
// 取消
handleClose() {
if (!this.roleVisible && this.$refs.roleForm) {
this.$refs.roleForm.$children[0].resetFields()
}
this.roleVisible = !this.roleVisible
if (!this.roleVisible) this.$refs.tree.setCheckedKeys([])
},
// 按钮事件
btnClick(pType, scope) {
console.log(pType, scope)
switch (pType) {
case 'create':
this.roleDialogTitle = '新增角色'
this.roleForm = {
enableStatus: true,
menuIdList: []
}
this.getMenuTree()
this.handleClose()
break
case 'edit':
this.roleDialogTitle = '编辑角色'
this.editEvent(scope)
break
case 'delete':
this.deleteEvent(scope.id)
break
}
},
// 编辑触发事件
editEvent(row) {
const that = this
roleInfo({ id: row.id }).then(res => {
this.roleForm = JSON.parse(JSON.stringify(res.data))
this.roleForm.enableStatus = res.data.enableStatus == 1 ? true : false
this.roleForm.roleVisibility = res.data.roleVisibility + ''
this.roleForm.rolePermissionType = res.data.rolePermissionType + ''
if (res.data.roleTenants) this.roleForm.roleTenants = res.data.roleTenants.split(',').map(Number)
this.getMenuTree({ roleId: row.id })
this.handleClose(res.data)
})
},
// 删除触发事件
deleteEvent(id) {
const that = this
const tipData = {
that: that,
tipText: '是否删除当前记录',
tipTitle: '提示',
type: 'error',
callBack: () => {
deleteRole({ id: id }).then(res => {
if (res.code == '200') {
this.$message({
type: 'success',
message: '删除成功!'
})
this.$refs.roleTable.refreshTable()
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
}
}
this.$Common.confirmDialog(tipData)
},
// 获取菜单权限列表
getMenuTree(params) {
getMenuTree(params).then(res => {
this.treedata = res.data.menuTree
setTimeout(() => {
this.$refs.tree.setCheckedKeys(res.data.checkedIds)
}, 1000 / 60)
})
},
// 获取选中菜单数组
getCheckedKeys() {
this.roleForm.menuIdList = this.$refs.tree.getCheckedKeys()
},
// 获取角色可见度可选项
getVisibility() {
getVisibility().then(res => {
console.log(res.data)
this.visibilityList = res.data
})
},
// 获取租户列表
getTenantList() {
getTenantList().then(res => {
this.tenantList = res.data
})
},
radioChange(e) {
this.$set(this.roleForm, 'roleVisibility', e)
}
}
}
</script>
<style lang="scss">
.role .el-tree {
margin-top: 7px;
}
</style>