田源
2025-01-16 404966637eda6881a0f17683c5aacc7c1c34aed8
Source/plt-web/plt-web-ui/src/views/system/role/index.vue
@@ -14,15 +14,62 @@
      @row-click="rowClickHandler"
      @row-save="rowSaveHandler"
      @row-update="rowUpdateHandler"
      @row-del="rowDeleteHandler"
    >
      <template slot="menuLeft" slot-scope="scope">
        <el-button icon="el-icon-delete" plain size="small" type="danger" @click="allDelHandler">删除</el-button>
        <el-button icon="el-icon-school" plain size="small" type="primary" @click="assignMembersHandler">分配成员
        <el-button v-if="permissionList.addBtn" class="button-custom-icon" size="small" type="primary"
                   @click="$refs.roleCrud.rowAdd()">
          <icon-show :name="permissionList.addBtn.source"></icon-show>
          新 增
        </el-button>
        <el-button icon="el-icon-user" plain size="small" type="primary" @click="statisticsHandler">统计</el-button>
        <el-button icon="el-icon-upload2" plain size="small" type="primary" @click="upLoadRole">导入角色</el-button>
        <el-button icon="el-icon-download" plain size="small" type="primary">导出</el-button>
        <el-button v-if="permissionList.delBtn" class="button-custom-icon" plain size="small" type="danger"
                   @click="allDelHandler">
          <icon-show :name="permissionList.delBtn.source"></icon-show>
          删除
        </el-button>
        <el-button v-if="permissionList.statisticsBtn" class="button-custom-icon" plain size="small" type="primary"
                   @click="statisticsHandler">
          <icon-show :name="permissionList.statisticsBtn.source"></icon-show>
          统计
        </el-button>
        <el-button v-if="permissionList.importRoleBtn" class="button-custom-icon" plain size="small" type="primary"
                   @click="upLoadRole">
          <icon-show :name="permissionList.importRoleBtn.source"></icon-show>
          导入角色
        </el-button>
        <el-button v-if="permissionList.exportBtn" class="button-custom-icon" plain size="small" type="primary">
          <icon-show :name="permissionList.exportBtn.source"></icon-show>
          导出
        </el-button>
      </template>
      <template slot="menu" slot-scope="{ row, index }">
        <el-button
          v-if="permissionList.assignMembersBtn"
          size="small"
          type="text"
          @click="assignMembersHandler(row, index)"
        >
          <icon-show :name="permissionList.assignMembersBtn.source"></icon-show>
          分配成员
        </el-button>
        <el-button
          v-if="permissionList.editBtn"
          size="small"
          type="text"
          @click="handleEdit(row, index)"
        >
          <icon-show :name="permissionList.editBtn.source"></icon-show>
          编辑
        </el-button>
        <el-button
          v-if="permissionList.delBtn"
          size="small"
          type="text"
          @click="handleDel(row, index)"
        >
          <icon-show :name="permissionList.delBtn.source"></icon-show>
          删除
        </el-button>
      </template>
      <template slot="roleClassifyText" slot-scope="{row}">
@@ -30,7 +77,7 @@
      </template>
    </avue-crud>
    <!-- 分配角色穿梭框   -->
    <!-- 分配成员穿梭框   -->
    <transfer ref="transfer" :left-role-data="leftRoleData" :right-role-data="rightRoleData"
              :transferTitle="transferTitle" title="角色添加成员"
              @transferSend="roleSendHandler">
@@ -79,19 +126,13 @@
import basicOption from "@/util/basic-option";
import {column} from "@/views/system/role/option";
import func from "@/util/func";
import {mapGetters} from "vuex";
export default {
  name: "index",
  data() {
    return {
      tableData: [],
      option: {
        ...basicOption,
        dialogTop: 0,
        dialogWidth: '30%',
        calcHeight: -60,
        column: column
      },
      page: {
        currentPage: 1,
        pageSize: 10,
@@ -113,6 +154,7 @@
        refreshBtn: false,
        addBtn: false,
        menu: false,
        header: false,
        column: [
          {
            label: '部门',
@@ -142,6 +184,32 @@
      tipList: ["角色导入只有 名称 和 描述 两列,且名称为必输项不能为空"]
    }
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission[this.$route.query.id].ADD, false),
        delBtn: this.vaildData(this.permission[this.$route.query.id].DELETE, false),
        editBtn: this.vaildData(this.permission[this.$route.query.id].EDIT, false),
        exportBtn: this.vaildData(this.permission[this.$route.query.id].EXPORT, false),
        assignMembersBtn: this.vaildData(this.permission[this.$route.query.id].ASSIGN, false),
        importRoleBtn: this.vaildData(this.permission[this.$route.query.id].IMPORT, false),
        statisticsBtn: this.vaildData(this.permission[this.$route.query.id].DISCARD, false),
      };
    },
    option() {
      return {
        ...basicOption,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        dialogTop: 0,
        dialogWidth: '30%',
        column: column,
        calcHeight: -60,
      }
    }
  },
  methods: {
    // 表格初始化请求
    getTableList() {
@@ -152,6 +220,11 @@
        this.page.total = res.data.total;
        this.tableLoading = false;
      })
    },
    // 编辑按钮
    handleEdit(row, index) {
      this.$refs.roleCrud.rowEdit(row, index);
    },
    // 列头刷新
@@ -180,8 +253,12 @@
        row,
        this.$refs.roleCrud,
        this.lastIndex,
        (newIndex) => { this.lastIndex = newIndex; },
        () => { this.selectList = []; }
        (newIndex) => {
          this.lastIndex = newIndex;
        },
        () => {
          this.selectList = [row];
        }
      );
    },
@@ -189,7 +266,6 @@
    rowSaveHandler(row, done, loading) {
      delete row.roleClassifyText;
      addRole(row).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          this.$message.success(res.data.obj);
          this.getTableList();
@@ -212,12 +288,11 @@
        }
      }).catch(err => {
        loading();
        console.log(err);
      });
    },
    // 删除
    rowDeleteHandler(row) {
    handleDel(row, index) {
      let params = {
        ids: row.oid
      }
@@ -270,20 +345,22 @@
    },
    // 分配成员
    assignMembersHandler() {
      if (this.selectList.length <= 0) {
        this.$message.warning('请选择角色进行成员分配!');
        return;
      }
      if (this.selectList.length > 1) {
        this.$message.warning('一次只能对一个角色进行分配成员操作!');
        return;
      }
    assignMembersHandler(row,index) {
      // if (this.selectList.length <= 0) {
      //   this.$message.warning('请选择角色进行成员分配!');
      //   return;
      // }
      //
      // if (this.selectList.length > 1) {
      //   this.$message.warning('一次只能对一个角色进行分配成员操作!');
      //   return;
      // }
      Promise.all([
        listUserUnInRoleOid({pkRole: this.selectList[0].oid}),
        listUserByRoleOid({pkRole: this.selectList[0].oid})
        listUserUnInRoleOid({pkRole: row.oid}),
        listUserByRoleOid({pkRole: row.oid})
      ]).then(([unInRoleRes, byRoleRes]) => {
        this.leftRoleData = [];
        this.rightRoleData = [];
        if (unInRoleRes.data.code === 200 && byRoleRes.data.code === 200) {
          const leftData = [...unInRoleRes.data.data, ...byRoleRes.data.data];
          // 组装好穿梭框可用数据
@@ -296,8 +373,6 @@
          this.rightRoleData = byRoleRes.data.data.map(item => item.oid);
          this.$refs.transfer.visible = true;
        }
      }).catch(err => {
        console.error(err);
      });
    },
@@ -311,8 +386,6 @@
      saveRight(params).then(res => {
        this.$message.success(res.data.obj);
        this.getTableList();
      }).catch(err => {
        this.$message.error(err)
      })
    },
@@ -328,7 +401,6 @@
        return;
      }
      listUserByRoleOid({pkRole: this.selectList[0].oid}).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          const data = res.data.data;
          this.countData = data.map(item => {
@@ -341,8 +413,6 @@
          });
          this.statisticsVisible = true;
        }
      }).catch(err => {
        console.log(err)
      })
    },