|
1
2
3
4
5
6
7
8
9
|
<template>
<a-drawer
:title="title"
:maskClosable="true"
width=650
placement="right"
:closable="true"
@close="close"
:visible="visible"
|
|
10
|
style="overflow: auto;padding-bottom: 53px;">
|
|
11
|
|
|
12
13
14
15
16
17
18
19
20
|
<a-form>
<a-form-item label='所拥有的权限'>
<a-tree
checkable
@check="onCheck"
:checkedKeys="checkedKeys"
:treeData="treeData"
@expand="onExpand"
@select="onTreeNodeSelect"
|
|
21
|
:selectedKeys="selectedKeys"
|
|
22
23
|
:expandedKeys="expandedKeysss"
:checkStrictly="checkStrictly">
|
|
24
25
|
<span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
{{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
|
|
26
27
28
29
|
</span>
</a-tree>
</a-form-item>
</a-form>
|
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<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>
树操作 <a-icon type="up" />
</a-button>
</a-dropdown>
<a-popconfirm title="确定放弃编辑?" @confirm="close" okText="确定" cancelText="取消">
<a-button style="margin-right: .8rem">取消</a-button>
</a-popconfirm>
|
|
48
49
|
<a-button @click="handleSubmit(false)" type="primary" :loading="loading" ghost style="margin-right: 0.8rem">仅保存</a-button>
<a-button @click="handleSubmit(true)" type="primary" :loading="loading">保存并关闭</a-button>
|
|
50
|
</div>
|
|
51
52
53
|
<role-datarule-modal ref="datarule"></role-datarule-modal>
|
|
54
55
56
57
|
</a-drawer>
</template>
<script>
|
|
58
59
60
|
import {queryTreeListForRole,queryRolePermission,saveRolePermission} from '@/api/api'
import RoleDataruleModal from './RoleDataruleModal.vue'
|
|
61
62
|
export default {
name: "RoleModal",
|
|
63
64
65
|
components:{
RoleDataruleModal
},
|
|
66
67
68
69
70
71
72
73
74
|
data(){
return {
roleId:"",
treeData: [],
defaultCheckedKeys:[],
checkedKeys:[],
expandedKeysss:[],
allTreeKeys:[],
autoExpandParent: true,
|
|
75
|
checkStrictly: true,
|
|
76
77
78
|
title:"角色权限配置",
visible: false,
loading: false,
|
|
79
|
selectedKeys:[]
|
|
80
81
82
|
}
},
methods: {
|
|
83
|
onTreeNodeSelect(id){
|
|
84
85
|
if(id && id.length>0){
this.selectedKeys = id
|
|
86
|
}
|
|
87
88
|
this.$refs.datarule.show(this.selectedKeys[0],this.roleId)
},
|
|
89
90
91
92
93
94
|
onCheck (o) {
if(this.checkStrictly){
this.checkedKeys = o.checked;
}else{
this.checkedKeys = o
}
|
|
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
|
},
show(roleId){
this.roleId=roleId
this.visible = true;
},
close () {
this.reset()
this.$emit('close');
this.visible = false;
},
onExpand(expandedKeys){
this.expandedKeysss = expandedKeys;
this.autoExpandParent = false
},
reset () {
this.expandedKeysss = []
this.checkedKeys = []
this.defaultCheckedKeys = []
this.loading = false
},
expandAll () {
this.expandedKeysss = this.allTreeKeys
},
closeAll () {
this.expandedKeysss = []
},
checkALL () {
this.checkedKeys = this.allTreeKeys
},
cancelCheckALL () {
|
|
125
|
//this.checkedKeys = this.defaultCheckedKeys
|
|
126
127
|
this.checkedKeys = []
},
|
|
128
129
130
131
132
133
134
|
switchCheckStrictly (v) {
if(v==1){
this.checkStrictly = false
}else if(v==2){
this.checkStrictly = true
}
},
|
|
135
136
137
|
handleCancel () {
this.close()
},
|
|
138
|
handleSubmit(exit) {
|
|
139
140
|
let that = this;
let params = {
|
|
141
|
roleId:that.roleId,
|
|
142
|
permissionIds:that.checkedKeys.join(","),
|
|
143
|
lastpermissionIds:that.defaultCheckedKeys.join(","),
|
|
144
145
146
147
148
149
150
|
};
that.loading = true;
console.log("请求参数:",params);
saveRolePermission(params).then((res)=>{
if(res.success){
that.$message.success(res.message);
that.loading = false;
|
|
151
152
153
|
if (exit) {
that.close()
}
|
|
154
155
156
|
}else {
that.$message.error(res.message);
that.loading = false;
|
|
157
158
159
|
if (exit) {
that.close()
}
|
|
160
|
}
|
|
161
|
this.loadData();
|
|
162
163
|
})
},
|
|
164
|
loadData(){
|
|
165
|
queryTreeListForRole().then((res) => {
|
|
166
167
168
|
this.treeData = res.result.treeList
this.allTreeKeys = res.result.ids
queryRolePermission({roleId:this.roleId}).then((res)=>{
|
|
169
170
171
|
this.checkedKeys = [...res.result];
this.defaultCheckedKeys = [...res.result];
this.expandedKeysss = this.allTreeKeys;
|
|
172
|
console.log(this.defaultCheckedKeys)
|
|
173
174
175
|
})
})
}
|
|
176
177
178
179
180
181
|
},
watch: {
visible () {
if (this.visible) {
this.loadData();
}
|
|
182
183
184
185
186
|
}
}
}
</script>
|
|
187
|
<style lang="less" scoped>
|
|
188
189
190
191
192
193
194
195
196
197
198
|
.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;
}
|
|
199
|
|
|
200
|
</style>
|