|
1
2
3
4
5
6
7
8
9
10
|
<template>
<a-drawer
:title="title"
:maskClosable="true"
width=650
placement="right"
:closable="true"
@close="close"
:visible="visible"
style="overflow: auto;padding-bottom: 53px;">
|
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane key="1" tab="菜单权限">
<a-form>
<a-form-item label='所拥有的权限'>
<a-tree
checkable
@check="onCheck"
:checkedKeys="checkedKeys"
:treeData="treeData"
@expand="onExpand"
@select="onTreeNodeSelect"
:selectedKeys="selectedKeys"
:expandedKeys="expandedKeysss"
:checkStrictly="checkStrictly">
<span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
|
|
26
|
{{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
|
|
27
28
29
30
31
32
33
34
35
36
|
</span>
</a-tree>
</a-form-item>
</a-form>
</a-tab-pane>
<a-tab-pane key="2" tab="数据权限" force-render>
<a-form>
<a-form-item label='所拥有的权限'>
<a-tree
checkable
|
|
37
38
39
40
41
42
43
44
|
@check="onCheck2"
:checkedKeys="checkedKeys2"
:treeData="treeData2"
@expand="onExpand2"
@select="onTreeNodeSelect2"
:selectedKeys="selectedKeys2"
:expandedKeys="expandedKeysss2"
:checkStrictly="checkStrictly2">
|
|
45
46
47
48
49
50
51
52
|
<span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
{{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
</span>
</a-tree>
</a-form-item>
</a-form>
</a-tab-pane>
</a-tabs>
|
|
53
54
55
56
57
58
59
60
61
62
63
64
|
<div class="drawer-bootom-button">
<a-dropdown style="float: left" :trigger="['click']" placement="topCenter">
<a-menu slot="overlay">
<a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item>
<a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item>
<a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item>
<a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item>
<a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
<a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
</a-menu>
<a-button>
|
|
65
|
树操作
|
|
66
|
<a-icon type="up" />
|
|
67
68
69
70
71
|
</a-button>
</a-dropdown>
<a-popconfirm title="确定放弃编辑?" @confirm="close" okText="确定" cancelText="取消">
<a-button style="margin-right: .8rem">取消</a-button>
</a-popconfirm>
|
|
72
73
|
<a-button @click="handleSubmit(false)" type="primary" :loading="loading" ghost style="margin-right: 0.8rem">仅保存
</a-button>
|
|
74
75
76
77
78
79
80
81
82
|
<a-button @click="handleSubmit(true)" type="primary" :loading="loading">保存并关闭</a-button>
</div>
<role-datarule-modal ref="datarule"></role-datarule-modal>
</a-drawer>
</template>
<script>
|
|
83
|
import { queryDataTreeListForRole, queryRoleDataPermission, queryRolePermission, queryTreeListForRole, saveRolePermission } from '@/api/api'
|
|
84
|
import RoleDataruleModal from './RoleDataruleModal.vue'
|
|
85
|
|
|
86
|
export default {
|
|
87
|
name: 'RoleModal',
|
|
88
89
90
91
92
|
components: {
RoleDataruleModal
},
data() {
return {
|
|
93
|
roleId: '',
|
|
94
95
96
97
98
|
title: '角色权限配置',
visible: false,
loading: false,
activeKey: '1',
|
|
99
100
|
treeData: [],
defaultCheckedKeys: [],
|
|
101
|
selectedKeys: [],
|
|
102
103
104
105
106
|
checkedKeys: [],
expandedKeysss: [],
allTreeKeys: [],
autoExpandParent: true,
checkStrictly: true,
|
|
107
108
109
110
111
112
113
114
115
|
treeData2: [],
defaultCheckedKeys2: [],
selectedKeys2: [],
checkedKeys2: [],
expandedKeysss2: [],
allTreeKeys2: [],
autoExpandParent2: true,
checkStrictly2: true,
|
|
116
117
118
119
120
121
122
123
|
}
},
methods: {
onTreeNodeSelect(id) {
if (id && id.length > 0) {
this.selectedKeys = id
}
this.$refs.datarule.show(this.selectedKeys[0], this.roleId)
|
|
124
|
},
|
|
125
126
127
128
129
130
|
onTreeNodeSelect2(id) {
if (id && id.length > 0) {
this.selectedKeys2 = id
}
this.$refs.datarule.show(this.selectedKeys2[0], this.roleId)
},
|
|
131
132
|
onCheck(o) {
if (this.checkStrictly) {
|
|
133
|
this.checkedKeys = o.checked
|
|
134
135
|
} else {
this.checkedKeys = o
|
|
136
137
|
}
},
|
|
138
139
140
141
142
143
144
|
onCheck2(o) {
if (this.checkStrictly2) {
this.checkedKeys2 = o.checked
} else {
this.checkedKeys2 = o
}
},
|
|
145
146
|
show(roleId) {
this.roleId = roleId
|
|
147
|
this.visible = true
|
|
148
149
150
|
},
close() {
this.reset()
|
|
151
152
|
this.$emit('close')
this.visible = false
|
|
153
154
|
},
onExpand(expandedKeys) {
|
|
155
|
this.expandedKeysss = expandedKeys
|
|
156
157
|
this.autoExpandParent = false
},
|
|
158
159
160
161
|
onExpand2(expandedKeys) {
this.expandedKeysss2 = expandedKeys
this.autoExpandParent2 = false
},
|
|
162
163
|
reset() {
this.expandedKeysss = []
|
|
164
|
this.expandedKeysss2 = []
|
|
165
|
this.checkedKeys = []
|
|
166
|
this.checkedKeys2 = []
|
|
167
|
this.defaultCheckedKeys = []
|
|
168
|
this.defaultCheckedKeys2 = []
|
|
169
170
171
|
this.loading = false
},
expandAll() {
|
|
172
173
174
175
176
177
|
let activeKey = this.activeKey
if (activeKey === '1') {
this.expandedKeysss = this.allTreeKeys
} else if (activeKey === '2') {
this.expandedKeysss2 = this.allTreeKeys2
}
|
|
178
179
|
},
closeAll() {
|
|
180
181
182
183
184
185
|
let activeKey = this.activeKey
if (activeKey === '1') {
this.expandedKeysss = []
} else if (activeKey === '2') {
this.expandedKeysss2 = []
}
|
|
186
187
|
},
checkALL() {
|
|
188
189
190
191
192
193
|
let activeKey = this.activeKey
if (activeKey === '1') {
this.checkedKeys = this.allTreeKeys
} else if (activeKey === '2') {
this.checkedKeys2 = this.allTreeKeys2
}
|
|
194
195
|
},
cancelCheckALL() {
|
|
196
197
198
199
200
201
|
let activeKey = this.activeKey
if (activeKey === '1') {
this.checkedKeys = []
} else if (activeKey === '2') {
this.checkedKeys2 = []
}
|
|
202
203
|
},
switchCheckStrictly(v) {
|
|
204
|
let activeKey = this.activeKey
|
|
205
|
if (v === 1) {
|
|
206
207
208
209
210
|
if (activeKey === '1') {
this.checkStrictly = false
} else if (activeKey === '2') {
this.checkStrictly2 = false
}
|
|
211
|
} else if (v === 2) {
|
|
212
213
214
215
216
|
if (activeKey === '1') {
this.checkStrictly = true
} else if (activeKey === '2') {
this.checkStrictly2 = true
}
|
|
217
218
|
}
},
|
|
219
220
221
222
|
handleCancel() {
this.close()
},
handleSubmit(exit) {
|
|
223
|
let that = this
|
|
224
225
|
let params = {
roleId: that.roleId,
|
|
226
|
permissionIds: that.checkedKeys.join(','),
|
|
227
228
229
|
lastpermissionIds: that.defaultCheckedKeys.join(','),
permissionIds2: that.checkedKeys2.join(','),
lastpermissionIds2: that.defaultCheckedKeys2.join(',')
|
|
230
231
|
}
that.loading = true
|
|
232
233
|
saveRolePermission(params).then((res) => {
if (res.success) {
|
|
234
235
|
that.$message.success(res.message)
that.loading = false
|
|
236
237
238
239
|
if (exit) {
that.close()
}
} else {
|
|
240
241
|
that.$message.error(res.message)
that.loading = false
|
|
242
243
244
245
|
if (exit) {
that.close()
}
}
|
|
246
|
this.loadData()
|
|
247
248
249
250
251
|
})
},
loadData() {
queryTreeListForRole().then((res) => {
this.treeData = res.result.treeList
|
|
252
|
this.treeData2 = res.result.treeList2
|
|
253
|
this.allTreeKeys = res.result.ids
|
|
254
|
this.allTreeKeys2 = res.result.ids2
|
|
255
|
queryRolePermission({ roleId: this.roleId }).then((res) => {
|
|
256
257
258
259
|
this.checkedKeys = [...res.result.permissionIds]
this.defaultCheckedKeys = [...res.result.permissionIds]
this.checkedKeys2 = [...res.result.dataPermissionIds]
this.defaultCheckedKeys2 = [...res.result.dataPermissionIds]
|
|
260
|
//this.expandedKeysss = this.allTreeKeys 注释为了加载数据后,控件不展开
|
|
261
262
|
})
})
|
|
263
264
265
266
267
268
269
270
271
272
|
/*queryDataTreeListForRole().then((res) => {
this.treeData2 = res.result.treeList
this.allTreeKeys2 = res.result.ids
queryRoleDataPermission({ roleId: this.roleId }).then((res) => {
this.checkedKeys2 = [...res.result]
this.defaultCheckedKeys2 = [...res.result]
//this.expandedKeysss = this.allTreeKeys2 注释为了加载数据后,控件不展开
})
})*/
|
|
273
274
|
}
},
|
|
275
|
watch: {
|
|
276
|
visible() {
|
|
277
|
if (this.visible) {
|
|
278
|
this.loadData()
|
|
279
280
281
|
}
}
}
|
|
282
|
}
|
|
283
284
285
|
</script>
<style lang="less" scoped>
|
|
286
287
288
289
290
291
292
293
294
295
296
|
.drawer-bootom-button {
position: absolute;
bottom: 0;
width: 100%;
border-top: 1px solid #e8e8e8;
padding: 10px 16px;
text-align: right;
left: 0;
background: #fff;
border-radius: 0 0 2px 2px;
}
|
|
297
298
|
</style>
|