实现效果图:
<template>
<el-dialog
title="角色分配"
top="8vh"
:visible="setUserShowDialog"
@close="handleCloseDialog"
@open="getOption"
>
<el-form
ref="serSetFrom"
:model="userSetFrom"
label-width="120px"
label-position="auto"
style="width: 90%; margin: 0px 0px 10px 20px"
>
<el-form-item label="用户账号">
<el-input v-model="userSetFrom.userName" disabled />
</el-form-item>
</el-form>
<el-transfer
v-model="value"
:data="data"
:titles="['待分配', '已分配']"
:button-texts="['移除', '添加']"
style="margin-left: 10%"
:v-loading="loading"
/>
<template v-slot:footer>
<el-button style="margin-top: 12px" type="primary" @click="onSubmit"
>确定</el-button
>
<el-button @click="handleCloseDialog">取消</el-button>
</template>
</el-dialog>
</template>
<script>
import {
reqGetUserInfo,
reqGetUserInfoAuth,
reqSetUserInfoAuth,
} from "@/api/userlist";
import { reqGetRoleOption } from "@/api/role";
export default {
name: "JRYUserSet",
props: {
setUserShowDialog: {
type: Boolean,
required: true,
},
userSetId: {
type: String,
required: true,
},
},
data() {
return {
loading: true,
data: [],
value: [],
userSetFrom: {
userName: "",
},
};
},
mounted() {},
methods: {
// 关闭
handleCloseDialog() {
this.$emit("update:setUserShowDialog", false);
this.userSetFrom = {
userName: "",
};
this.value = [];
},
async onSubmit() {
await reqSetUserInfoAuth(this.userSetId, this.value);
this.$message.success("操作成功");
this.handleCloseDialog();
this.$parent.getUserInfo();
},
async Detail() {
// 获取用户详情
const { result: res } = await reqGetUserInfo(this.userSetId);
this.userSetFrom = res;
// 获取用户对应的权限
const { result: res1 } = await reqGetUserInfoAuth(this.userSetId);
this.value = res1;
},
// 获取所有权限
async getOption() {
this.loading = true;
const { result: resOption } = await reqGetRoleOption();
const generateData = (_) => {
const data = [];
resOption.items.forEach((item) => {
data.push({
key: item.id,
label: item.name,
});
});
return data;
};
this.data = generateData();
this.loading = false;
},
},
};
</script>
<style lang="scss" scoped></style>