EditPrivilegePage.vue
6.27 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
<template>
<a-card title="权限管理" :bordered="false">
<template #extra>
<a-button class="mr-10" type="primary" :disabled="submitted" @click="submitForm">保存</a-button>
<a-button @click="$goBack()">返回</a-button>
</template>
<div class="scroll-block">
<a-collapse v-model:activeKey="activeKey" collapsible="icon">
<a-collapse-panel v-for="(menu, index) in privilegeTree" :key="index">
<template #header>
<a-checkbox v-model:checked="menu.checked" @change="onCheckAllChange(menu)">
<MenuOutlined v-if="menu.type === 'MENU'" class="mr-5"/>
<ToolOutlined v-else class="mr-5"/>
{{ menu.title }}
</a-checkbox>
</template>
<!-- <template #extra>-->
<!-- <a-checkbox v-model:checked="menu.unselectable" @change="onCheckAllChange(menu)">-->
<!-- 全选-->
<!-- </a-checkbox>-->
<!-- </template>-->
<a-collapse v-model:activeKey="activeSubKey" ghost collapsible="icon">
<a-collapse-panel v-for="(subMenu ) in menu.children" :key="subMenu.key">
<template #header>
<a-checkbox v-model:checked="subMenu.checked" @change="onCheckAllChange(subMenu)">
<MenuOutlined v-if="subMenu.type === 'MENU'" class="mr-5"/>
<ToolOutlined v-else class="mr-5"/>
{{ subMenu.title }}
</a-checkbox>
</template>
<a-row :gutter="[4, 4]">
<a-col :offset="2" :span="4" class="child-col-item" v-for="colItem in subMenu?.children" :key="colItem.key">
<a-checkbox v-model:checked="colItem.checked">
<MenuOutlined v-if="colItem.type === 'MENU'" class="mr-5"/>
<ToolOutlined v-else class="mr-5"/>
{{ colItem?.title }}
</a-checkbox>
</a-col>
</a-row>
</a-collapse-panel>
</a-collapse>
</a-collapse-panel>
</a-collapse>
</div>
<a-row class="mt-16">
<a-col :offset="5">
<a-button class="mr-10" type="primary" :disabled="submitted" @click="submitForm">保存</a-button>
<a-button @click="$goBack()">返回</a-button>
</a-col>
</a-row>
</a-card>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import {Role} from "lib/src/entity/security/entity/Role";
import {TreeItem} from "lib/src/core/bean/TreeItem";
import {message} from "ant-design-vue";
import {SecurityController} from "@/api/SecurityController";
import {MenuOutlined, ToolOutlined} from "@ant-design/icons-vue";
@Component({
components: {MenuOutlined, ToolOutlined}
})
export default class EditPrivilegePage extends Vue {
activeKey = "";
activeSubKey = "";
roleId: number;
submitted = false;
/**
* 权限树
*/
privilegeTree: TreeItem[] = [];
created(): void {
this.roleId = Number(this.$route.query.roleId);
// 初始化加载权限树
SecurityController.getPrivilegeTreeByRoleId(this.axios, this.roleId).then(res => {
this.privilegeTree = res.data;
});
}
submitForm(): void {
const role = new Role();
role.roleId = this.roleId;
const codes: Array<string> = [];
this.privilegeTree.forEach(item => {
this.buildPrivilegeCodes(item, codes);
});
role.privilegeCodes = codes;
SecurityController.updateRolePrivileges(this.axios, role).then(res => {
message.success('操作成功');
this.$goBack();
});
}
buildPrivilegeCodes(treeItem: TreeItem, codes: Array<string>): void {
if (treeItem.checked) {
codes.push(treeItem.key);
}
if (treeItem.children) {
treeItem.children.forEach(item => {
this.buildPrivilegeCodes(item, codes);
});
}
}
onCheckAllChange(treeItem: TreeItem) {
const checked = treeItem.checked;
this.toggleFor(treeItem, checked);
}
// 数据递归处理
toggleFor(treeItem: TreeItem, checked: boolean) {
treeItem.checked = checked;
treeItem.unselectable = checked;
if (treeItem.children) {
treeItem.children.forEach(item => {
this.toggleFor(item, checked);
});
}
}
}
</script>
<style lang="less" scoped>
.scroll-block {
max-height: calc(100vh - 280px);
overflow: hidden auto;
}
.privilege-codes-tree {
margin-top: 32px;
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, 0.15);
.tree-title {
padding: 13px 20px;
font-size: 14px;
font-weight: 600;
color: #000;
background: #F5F7FA;
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
}
.tree-children > div {
width: 100%;
&:not(:last-child) {
& > div {
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
}
}
}
.parent {
padding: 12px 20px;
min-width: 232px;
border-right: 1px solid rgba(0, 0, 0, 0.15);
}
.child-col {
padding: 12px 20px;
}
.child {
flex: 1;
}
.child-col-item {
padding-left: 16px !important;
::v-deep(.ant-checkbox+span) {
color: rgba(0, 0, 0, 0.65);
}
}
}
::v-deep(.ant-collapse > .ant-collapse-item > .ant-collapse-content) {
transition: none !important;
animation: none !important;
}
//::v-deep(.ant-collapse-content-active) {
// transition: none !important;
// animation: none !important;
//}
</style>