Files
Yi.Admin/Yi.Vue/src/views/AdmRoleMenu.vue

113 lines
2.6 KiB
Vue
Raw Normal View History

2021-10-14 13:15:00 +08:00
<template>
<v-row>
<v-col cols="12">
2021-10-19 19:07:42 +08:00
<material-card color="primary" icon="mdi-account-outline">
<template #title>
角色菜单分配管理
<small class="text-body-1"
>你可以在这里多角色分配多菜单/选中一个可查看</small
> </template
2021-10-22 16:22:14 +08:00
>
<v-divider></v-divider>
<app-btn class="ma-4" @click="setMenu">确定分配</app-btn
>
<app-btn class="my-4" color="secondary" @click="clear">清空选择</app-btn></material-card
2021-10-19 19:07:42 +08:00
>
2021-10-22 16:22:14 +08:00
</v-col>
2021-10-22 16:22:14 +08:00
<v-col cols="12" md="4" lg="4">
<v-card class="mx-auto" width="100%">
2021-10-14 20:29:07 +08:00
<v-treeview
selectable
:items="RoleItems"
v-model="selectionRole"
return-object
open-all
hoverable
item-text="role_name"
>
</v-treeview>
</v-card>
</v-col>
2021-10-14 13:15:00 +08:00
<v-col cols="12" md="8" lg="8">
<v-card class="mx-auto" width="100%">
2021-10-14 20:29:07 +08:00
<v-treeview
2021-10-19 19:07:42 +08:00
open-on-click
2021-10-14 20:29:07 +08:00
selectable
:items="Menuitems"
2021-10-23 20:23:44 +08:00
selection-type="independent"
2021-10-14 20:29:07 +08:00
v-model="selectionMenu"
return-object
open-all
hoverable
item-text="menu_name"
>
<template v-slot:append="{ item }">
<v-btn>id:{{ item.id }}</v-btn>
2021-10-14 13:15:00 +08:00
</template>
2021-10-14 20:29:07 +08:00
</v-treeview>
</v-card></v-col
>
</v-row>
2021-10-14 13:15:00 +08:00
</template>
<script>
import roleApi from "../api/roleApi";
2021-10-16 14:48:55 +08:00
import menuApi from "../api/menuApi";
2021-10-14 20:29:07 +08:00
export default {
created() {
2021-10-19 19:07:42 +08:00
this.init();
},
2021-10-19 19:07:42 +08:00
watch: {
selectionRole: {
handler(val, oldVal) {
if (val.length == 1) {
roleApi.getMenuByRloe(val[0].id).then((resp) => {
this.selectionMenu = resp.data;
});
}
},
deep: true,
},
2021-10-19 17:44:37 +08:00
},
methods: {
2021-10-19 19:07:42 +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);
});
roleApi.setMenuByRole(roleIds, menuIds).then((resp) => {
this.$dialog.notify.info(resp.msg, {
2021-10-16 14:48:55 +08:00
position: "top-right",
timeout: 5000,
});
2021-10-19 19:07:42 +08:00
});
2021-10-16 14:48:55 +08:00
},
init() {
roleApi.getRole().then((resp) => {
this.RoleItems = resp.data;
});
menuApi.getMenu().then((resp) => {
this.Menuitems = resp.data;
});
},
},
2021-10-14 20:29:07 +08:00
data: () => ({
selectionMenu: [],
selectionRole: [],
RoleItems: [],
Menuitems: [],
2021-10-14 20:29:07 +08:00
}),
};
2021-10-14 13:15:00 +08:00
</script>