Vue 穿梭框的使用

实现效果图:
在这里插入图片描述

<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值