Files
Yi.Admin/Yi.Vue2.x/src/views/AdmRoleMenu.vue

122 lines
2.9 KiB
Vue
Raw Normal View History

2022-04-26 01:34:47 +08:00
<template>
<v-row>
<v-col cols="12">
<material-card color="primary" icon="mdi-account-outline">
<template #title>
角色菜单分配管理
<small class="text-body-1"
>你可以在这里多角色分配多菜单/选中一个可查看</small
2022-04-29 12:38:19 +08:00
>
</template>
<v-divider></v-divider>
<app-btn dark class="ma-4" @click="showAll"> 展开全部</app-btn>
<app-btn class="my-4 mr-4" @click="setMenu">确定分配</app-btn>
<app-btn class="my-4" color="secondary" @click="clear"
>清空选择</app-btn
></material-card
2022-04-26 01:34:47 +08:00
>
</v-col>
2022-04-29 12:38:19 +08:00
2022-04-26 01:34:47 +08:00
<v-col cols="12" md="4" lg="4">
<v-card class="mx-auto" width="100%">
<v-treeview
selectable
:items="RoleItems"
v-model="selectionRole"
return-object
open-all
hoverable
2022-04-29 12:38:19 +08:00
item-text="roleName"
2022-04-26 01:34:47 +08:00
>
</v-treeview>
</v-card>
</v-col>
<v-col cols="12" md="8" lg="8">
<v-card class="mx-auto" width="100%">
<v-treeview
2022-04-29 12:38:19 +08:00
ref="tree"
2022-04-26 01:34:47 +08:00
open-on-click
selectable
:items="Menuitems"
selection-type="independent"
v-model="selectionMenu"
return-object
open-all
hoverable
2022-04-29 12:38:19 +08:00
item-text="menuName"
2022-04-26 01:34:47 +08:00
>
<template v-slot:append="{ item }">
2022-04-30 21:48:18 +08:00
<v-btn>权限:{{ item.permissionCode }}</v-btn>
2022-04-26 01:34:47 +08:00
</template>
</v-treeview>
</v-card></v-col
>
</v-row>
</template>
<script>
import roleApi from "../api/roleApi";
import menuApi from "../api/menuApi";
export default {
created() {
this.init();
},
watch: {
selectionRole: {
handler(val, oldVal) {
if (val.length == 1) {
2022-04-29 12:38:19 +08:00
roleApi.getInMenuByRoleId(val[0].id).then((resp) => {
if (resp.data.menus == null) {
this.selectionMenu = [];
} else {
this.selectionMenu = resp.data.menus;
}
2022-04-26 01:34:47 +08:00
});
}
},
deep: true,
},
},
methods: {
2022-04-29 12:38:19 +08:00
showAll() {
this.$refs.tree.updateAll(true);
},
2022-04-26 01:34:47 +08:00
clear() {
this.selectionMenu = [];
this.selectionRole = [];
},
setMenu() {
var roleIds = [];
var menuIds = [];
this.selectionRole.forEach((ele) => {
roleIds.push(ele.id);
});
this.selectionMenu.forEach((ele) => {
menuIds.push(ele.id);
});
2022-04-29 12:38:19 +08:00
roleApi.giveRoleSetMenu(roleIds, menuIds).then((resp) => {
this.$dialog.notify.info(resp.message, {
2022-04-26 01:34:47 +08:00
position: "top-right",
timeout: 5000,
});
});
},
init() {
2022-04-29 12:38:19 +08:00
roleApi.getList().then((resp) => {
2022-04-26 01:34:47 +08:00
this.RoleItems = resp.data;
});
2022-04-29 12:38:19 +08:00
menuApi.getMenuTree().then((resp) => {
this.Menuitems = resp.data;
2022-04-26 01:34:47 +08:00
});
},
},
data: () => ({
selectionMenu: [],
selectionRole: [],
RoleItems: [],
Menuitems: [],
}),
};
</script>