Surpriseplus
2022-10-14 20baed5059a2f040996cae291d66bdbfc46eb9c2
菜单权限授权,角色资源授权页面添加,接口对接
已添加2个文件
已修改5个文件
1097 ■■■■■ 文件已修改
public/config/config.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/api.js 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/lang/en.js 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/lang/zh.js 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/AuthorizationManagement/menuRoleAuthorization.vue 447 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/AuthorizationManagement/roleResAuthorization.vue 540 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/config/config.js
@@ -1,5 +1,5 @@
// const BASE_URL = 'http://192.168.20.55:12316';
const BASE_URL = 'http://192.168.20.39:12316';
const BASE_URL = 'http://192.168.20.55:12316';
//const BASE_URL = 'http://192.168.20.39:12316';
var gisUrl = 'http://183.162.245.49:3301';
var ifreamUrl = 'http://192.168.20.39:12306/';
src/api/api.js
@@ -132,6 +132,12 @@
  //请求地址
  return request.get('/auth/selectByPageAndCount', { params: params });
}
//权限管理列表根据菜单
export function select_AuthMenu_ByPageAndCount(params) {
  //请求地址
  return request.get('/auth/selectByPageForMenu', { params: params });
}
//权限管理添加
export function insertAuth(params) {
  return request.post('/auth/insertAuth', params);
@@ -202,8 +208,6 @@
  return request.post('/Menu/updateMenus', params);
}
//请求目录树数据
export function queryDirTree() {
  return request.get('/dir/selectDirAll');
@@ -268,8 +272,6 @@
  return request.post('/user/updateUserPwd', params);
}
//根据角色查询用户
export function roleUserselectByPageForRole(params) {
  //请求地址
@@ -299,3 +301,32 @@
export function update_args(params) {
  return request.post('/args/update', params);
}
//菜单权限请求列表
export function select_menuAuth_ByPageAndCount(params) {
  return request.get('/menuAuth/selectByPageAndCount', { params: params });
}
//菜单权限添加多条数据
export function menuAuthinserts(params) {
  return request.post('/menuAuth/inserts', params);
}
//菜单权限删除多条
export function menuAuthDeletes(params) {
  return request.get('/menuAuth/deletes', { params: params });
}
//角色资源列表
export function roleReselectByPageAndCount(params) {
  return request.get('/roleRes/selectByPageAndCount', { params: params });
}
//角色资源新增
export function roleResInserts(params) {
  return request.post('/roleRes/inserts', params);
}
//角色资源删除
export function roleResDeletes(params) {
  return request.get('/roleRes/deletes', { params: params });
}
//资源管理-根据角色分页查询并返回记录数
export function resSelectCountForRole(params) {
  return request.get('/res/selectCountForRole', { params: params });
}
src/assets/lang/en.js
@@ -105,6 +105,7 @@
    operatManage: 'Operat Manage',
    ResourceLog: 'Resource Log',
    UserRoleAuthorization: 'User Role Authorization',
    MenuRoleAuthorization: 'Menu Permission Authorization',
    UserRoleAuthorizationObj: {
      RoleTable: 'Role Table',
      userTable: 'user Table',
@@ -112,6 +113,8 @@
      delete: 'delete',
      serialNumber: 'serial Number',
      name: 'name',
      PermissionTable: 'Permission table',
      server: 'Service Address',
    },
    ELM: {
      username: 'username',
src/assets/lang/zh.js
@@ -106,6 +106,7 @@
    operatManage: '运维管理',
    ResourceLog: '资源日志',
    UserRoleAuthorization: '用户角色授权',
    MenuRoleAuthorization: '菜单权限授权',
    UserRoleAuthorizationObj: {
      RoleTable: '角色表',
      userTable: '用户表',
@@ -113,6 +114,8 @@
      delete: '删除',
      serialNumber: '编号',
      name: '名称',
      PermissionTable: '权限表',
      server: '服务地址',
    },
    ELM: {
      username: '用户名称',
@@ -399,21 +402,21 @@
      rejection: '拒批',
      userexport: 'Excel用户导出',
      userinput: 'Excel用户导入',
      userStatus: "用户状态",
      uname: "用户名",
      pwd: "密码",
      sex: "性别",
      natives: "籍贯",
      userStatus: '用户状态',
      uname: '用户名',
      pwd: '密码',
      sex: '性别',
      natives: '籍贯',
      depName: '单位名称',
      idcard: "证件号",
      job: "工作",
      edu: "教育",
      addr: "地址",
      email: "电子邮件",
      contact: "联系方式",
      status: "状态",
      bak: "备注",
      depid: "所属部门",
      idcard: '证件号',
      job: '工作',
      edu: '教育',
      addr: '地址',
      email: '电子邮件',
      contact: '联系方式',
      status: '状态',
      bak: '备注',
      depid: '所属部门',
      chineseName: '中文名[用户名]',
      affiliatedUnit: '所属单位[在职]',
      mobileNumber: '手机号[接收短信]',
src/router/index.js
@@ -37,14 +37,16 @@
import groupManage from '../views/userManage/groupManage.vue'; // ç”¨æˆ·ç®¡ç†æ¨¡å—
import authorityManage from '@/views/userManage/authorityManage.vue'; //用户管理-权限管理
import resourceManage from '@/views/userManage/resourceManage.vue'; //用户管理-资源管理
import userRoleAuthorization from '@/views/AuthorizationManagement/userRoleAuthorization.vue'; //系统管理-
const originalPush = VueRouter.prototype.push
import userRoleAuthorization from '@/views/AuthorizationManagement/userRoleAuthorization.vue'; //系统管理-用户角色授权
import menuRoleAuthorization from '@/views/AuthorizationManagement/menuRoleAuthorization.vue'; //系统管理-菜单权限授权
import roleResAuthorization from '@/views/AuthorizationManagement/roleResAuthorization.vue'; //系统管理-角色资源授权
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
  return originalPush.call(this, location).catch((err) => err);
};
// ç¾¤ç»„管理
Vue.use(VueRouter);
@@ -355,7 +357,24 @@
          requireAuth: true, // æ ‡è¯†è¯¥è·¯ç”±æ˜¯å¦éœ€è¦ç™»å½•
        },
      },
      {
        path: '/menuRoleAuthorization',
        component: menuRoleAuthorization,
        name: 'menuRoleAuthorization',
        meta: {
          title: '菜单权限授权',
          requireAuth: true, // æ ‡è¯†è¯¥è·¯ç”±æ˜¯å¦éœ€è¦ç™»å½•
        },
      },
      {
        path: '/roleResAuthorization',
        component: roleResAuthorization,
        name: 'roleResAuthorization',
        meta: {
          title: '菜单权限授权',
          requireAuth: true, // æ ‡è¯†è¯¥è·¯ç”±æ˜¯å¦éœ€è¦ç™»å½•
        },
      },
    ],
  },
];
src/views/AuthorizationManagement/menuRoleAuthorization.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,447 @@
<template>
  <div class="menuSettings_box">
    <div class="menuSettings_tree">
      <My-bread
        :list="[
          `${$t('operatManage.operatManage')}`,
          `${$t('operatManage.MenuRoleAuthorization')}`,
        ]"
      ></My-bread>
      <el-divider />
      <div class="menuTreeBox">
        <el-tree
          :data="depList"
          :props="defaultProps"
          :show-checkbox="true"
          :check-on-click-node="true"
          :check-strictly="true"
          node-key="id"
          @check="treeCheck"
          ref="treeForm"
        >
        </el-tree>
      </div>
    </div>
    <div class="menuSettings">
      <!-- <div class="title_box">
        <h4>详细信息</h4>
      </div> -->
      <div
        style="
          font-size: 14px;
          color: #606266;
          line-height: 1;
          cursor: text;
          position: relative;
          top: 5px;
          margin-left: 10px;
          display: flex;
          align-items: center;
        "
      >
        <span>
          {{
            $t('operatManage.UserRoleAuthorizationObj.PermissionTable')
          }}</span
        >
        <div class="btn" style="margin-left: auto">
          <el-button
            type="primary"
            icon="el-icon-circle-plus-outline"
            size="small"
            :disabled="roleid == null ? true : false"
            @click="adduser"
            >{{ $t('operatManage.UserRoleAuthorizationObj.Added') }}</el-button
          >
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="small"
            @click="deletesUser"
            :disabled="roleid == null ? true : false"
            >{{ $t('operatManage.UserRoleAuthorizationObj.delete') }}</el-button
          >
        </div>
      </div>
      <el-divider class="divider" />
      <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        height="85%"
        @selection-change="handleSelectionChange"
        :header-cell-style="{
          background: 'transparent',
        }"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="authid"
          :label="$t('operatManage.UserRoleAuthorizationObj.serialNumber')"
        >
        </el-table-column>
        <el-table-column
          prop="authName"
          :label="$t('operatManage.UserRoleAuthorizationObj.name')"
        >
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px; text-align: center" class="pagination_box">
        <el-pagination
          @size-change="userhandleSizeChange"
          @current-change="userhandleCurrentChange"
          :current-page="userlistData.pageIndex"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="userlistData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="usercount"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      :title="$t('operatManage.UserRoleAuthorizationObj.Added')"
      :visible.sync="dialogTableVisible"
    >
      <el-table
        :data="gridData"
        height="40vh"
        @selection-change="addhandleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="id"
          :label="$t('operatManage.UserRoleAuthorizationObj.serialNumber')"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          :label="$t('operatManage.UserRoleAuthorizationObj.name')"
        >
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px; text-align: center" class="pagination_box">
        <el-pagination
          @size-change="addhandleSizeChange"
          @current-change="addhandleCurrentChange"
          :current-page="addlistData.pageIndex"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="addlistData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="addcount"
        >
        </el-pagination>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">{{
          $t('dataManage.dictionaryManageObj.cancel')
        }}</el-button>
        <el-button type="primary" @click="addConfirm">{{
          $t('dataManage.dictionaryManageObj.confirm')
        }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import MyBread from '../../components/MyBread.vue';
import {
  queryMenuTree,
  select_menuAuth_ByPageAndCount,
  roleUserselectByPageForRole,
  menuAuthDeletes,
  select_AuthMenu_ByPageAndCount,
  menuAuthinserts,
} from '../../api/api';
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    MyBread,
  },
  data() {
    return {
      addcount: 0,
      gridData: [],
      addlistData: {
        pageIndex: 1,
        pageSize: 10,
      },
      dialogTableVisible: false,
      usertableData: [],
      userlistData: {
        pageIndex: 1,
        pageSize: 10,
      },
      usercount: 0,
      tableData: [],
      //   å½“前选择的行的id
      templateSelection: '',
      //   å½“前选择的行的数据
      checkList: [],
      defaultProps: {
        children: 'children',
        label: 'cnName',
      },
      oriData: [], //原始树数据
      depList: [], //el树数据
      backUpData: {},
      formLabelWidth: '170px',
      listData: {
        pageIndex: 1,
        pageSize: 10,
      },
      count: 0,
      usermultipleSelection: [],
      debid: null,
      roleid: null,
      addmultipleSelection: [],
    };
  },
  methods: {
    /**
     * sws
     */
    // éƒ¨é—¨è¯·æ±‚
    async getMenuTree() {
      //获取目录树最大ID,新建节点使用
      const data = await queryMenuTree();
      if (data.code !== 200) {
        return this.$message.error('请求单位报错');
      }
      this.depList = this.treeData(data.result);
    },
    treeData(source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // å¯¹æºæ•°æ®æ·±åº¦å…‹éš†
      return cloneData.filter((father) => {
        // å¾ªçŽ¯æ‰€æœ‰é¡¹
        let branchArr = cloneData.filter((child) => father.id == child.pid); // å¯¹æ¯”ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ''; // ç»™çˆ¶çº§æ·»åŠ ä¸€ä¸ªchildren属性,并赋值
        return father.pid == 0; // è¿”回一级菜单
      });
    },
    // éƒ¨é—¨æ ‘单选
    treeCheck(node, list) {
      //node è¯¥èŠ‚ç‚¹æ‰€å¯¹åº”çš„å¯¹è±¡ã€list æ ‘目前的选中状态对象
      //选中事件在选中后执行,当lis中有两个选中时,使用setCheckedKeys方法,选中一个节点
      if (list.checkedNodes.length > 0) {
        this.listData.menuid = node.id;
        this.debid = node.id;
        this.roleid = node.id;
        this.getRole();
        if (list.checkedKeys.length == 2) {
          //单选实现
          this.$refs.treeForm.setCheckedKeys([node.id]);
        }
      } else {
        this.debid = null;
        this.roleid = null;
        this.tableData = [];
        this.usertableData = [];
      }
    },
    addConfirm() {
      this.$confirm('确定是否新增', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          let arr = [];
          this.addmultipleSelection.forEach((e) => {
            arr.push({ menuid: this.roleid, authid: e.id });
          });
          const data = await menuAuthinserts(arr);
          if (data.code !== 200) {
            return this.$message.error('新增失败');
          }
          this.$message({
            type: 'success',
            message: '新增成功!',
          });
          this.dialogTableVisible = false;
          this.getRole();
        })
        .catch(() => {});
    },
    adduser() {
      this.dialogTableVisible = true;
      this.getadduserList();
    },
    //用户删除
    async deletesUser() {
      let arr = [];
      this.usermultipleSelection.forEach((e) => {
        arr.push(e.id);
      });
      const data = await menuAuthDeletes({ ids: arr.toString() });
      if (data.code !== 200) {
        return this.$message.error('删除失败');
      }
      this.$message({
        message: '删除成功',
        type: 'success',
      });
      this.getRole();
    },
    async getadduserList() {
      this.addlistData.menuid = this.roleid;
      const data = await select_AuthMenu_ByPageAndCount(this.addlistData);
      if (data.code !== 200) {
        return this.$message.error('新增用户列表请求错误');
      }
      this.gridData = data.result;
      this.addcount = data.count;
    },
    //用户表多选
    handleSelectionChange(val) {
      this.usermultipleSelection = val;
    },
    //新增用户表多选
    addhandleSelectionChange(val) {
      this.addmultipleSelection = val;
    },
    // æ–°å¢žç”¨æˆ·è¡¨åˆ†é¡µ
    addhandleSizeChange(val) {
      this.addlistData.pageSize = val;
      this.getadduserList();
    },
    // æ–°å¢žç”¨æˆ·è¡¨åˆ†é¡µ
    addhandleCurrentChange(val) {
      this.addlistData.pageIndex = val;
      this.getadduserList();
    },
    // ç”¨æˆ·è¡¨åˆ†é¡µ
    userhandleSizeChange(val) {
      this.userlistData.pageSize = val;
      this.getRole();
    },
    // ç”¨æˆ·è¡¨åˆ†é¡µ
    userhandleCurrentChange(val) {
      this.userlistData.pageIndex = val;
      this.getRole();
    },
    // è§’色表请求
    async getRole() {
      const data = await select_menuAuth_ByPageAndCount(this.listData);
      if (data.code !== 200) {
        return this.$message.error('用户角色请求错误');
      }
      this.tableData = data.result;
      this.usercount = data.count;
    },
  },
  created() {
    this.getMenuTree();
  },
};
</script>
<style lang="less" scoped>
//@import url(); å¼•入公共cssç±»
.menuSettings_box {
  //   background: rgb(240, 242, 245);
  border-radius: 10px;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  .menuSettings_tree {
    position: relative;
    width: 30%;
    height: 100%;
    background: rgb(240, 242, 245);
    padding: 20px;
    border-radius: 10px;
    box-sizing: border-box;
    overflow: auto;
    .saveBtn {
      position: absolute;
      left: 250px;
      top: 23px;
    }
    .menuTreeBox {
      height: 90%;
      overflow: auto;
      .el-tree {
        background: transparent;
        font-size: 15px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        // /deep/ .el-tree-node__label {
        //   font-size: 18px;
        // }
        /deep/ .el-tree-node {
          padding-top: 10px;
          // padding-bottom: 10px;
        }
        /deep/ .el-tree-node:focus > .el-tree-node__content {
          background-color: #b9b9b9;
        }
        /deep/ .el-tree-node__content:hover {
          background-color: rgb(153, 153, 153);
        }
        .btnBox {
          margin-left: 5px;
          .el-button + .el-button {
            margin-left: 5px;
          }
        }
      }
    }
  }
  .menuSettings {
    width: 70%;
    border-radius: 10px;
    background: rgb(240, 242, 245);
    margin-left: 10px;
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
    .title_box {
      background: #fff;
      padding: 10px;
      margin-bottom: 24px;
      display: flex;
      border-radius: 10px;
      border: 1px solid rgb(202, 201, 204);
      box-sizing: border-box;
    }
  }
  .table_box {
    padding: 10px;
    background: #fff;
    border-radius: 5px;
    border: 1px solid rgb(202, 201, 204);
    overflow: auto;
    height: 85%;
  }
  .divider {
    margin-top: 8px;
  }
}
.el-table,
.el-table /deep/ .el-table__expanded-cell {
  background-color: transparent;
}
.el-table /deep/ th,
.el-table /deep/ tr {
  background-color: transparent;
}
</style>
src/views/AuthorizationManagement/roleResAuthorization.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,540 @@
<template>
  <div class="menuSettings_box">
    <div class="menuSettings_tree">
      <My-bread
        :list="[
          `${$t('operatManage.operatManage')}`,
          `${$t('operatManage.UserRoleAuthorization')}`,
        ]"
      ></My-bread>
      <el-divider />
      <div class="menuTreeBox">
        <el-tree
          :data="depList"
          :props="defaultProps"
          :show-checkbox="true"
          :check-on-click-node="true"
          :check-strictly="true"
          node-key="id"
          @check="treeCheck"
          ref="treeForm"
        >
        </el-tree>
      </div>
    </div>
    <div
      class="menuSettings_tree"
      style="margin-left: 10px; width: calc(50% - 172px)"
    >
      <div
        style="
          font-size: 14px;
          color: #606266;
          line-height: 1;
          cursor: text;
          position: relative;
          top: 10px;
          margin-left: 10px;
        "
      >
        {{ $t('operatManage.UserRoleAuthorizationObj.RoleTable') }}
      </div>
      <el-divider />
      <el-table
        :data="tableData"
        style="width: 100%"
        @row-click="singleElection"
        highlight-current-row
        height="85%"
        :header-cell-style="{
          background: 'transparent',
        }"
      >
        <el-table-column align="center" width="55">
          <template slot-scope="scope">
            <!-- å¯ä»¥æ‰‹åŠ¨çš„ä¿®æ”¹label的值,从而控制选择哪一项 -->
            <el-radio
              class="radio"
              v-model="templateSelection"
              :label="scope.row.id"
              >&nbsp;</el-radio
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="id"
          :label="$t('operatManage.UserRoleAuthorizationObj.serialNumber')"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          :label="$t('operatManage.UserRoleAuthorizationObj.name')"
        >
        </el-table-column>
      </el-table>
      <div style="text-align: center; margin-top: 20px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listData.pageIndex"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="userlistData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
        >
        </el-pagination>
      </div>
    </div>
    <div class="menuSettings">
      <!-- <div class="title_box">
        <h4>详细信息</h4>
      </div> -->
      <div
        style="
          font-size: 14px;
          color: #606266;
          line-height: 1;
          cursor: text;
          position: relative;
          top: 5px;
          margin-left: 10px;
          display: flex;
          align-items: center;
        "
      >
        <span>
          {{ $t('operatManage.UserRoleAuthorizationObj.userTable') }}</span
        >
        <div class="btn" style="margin-left: auto">
          <el-button
            type="primary"
            icon="el-icon-circle-plus-outline"
            size="small"
            :disabled="roleid == null ? true : false"
            @click="adduser"
            >{{ $t('operatManage.UserRoleAuthorizationObj.Added') }}</el-button
          >
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="small"
            @click="deletesUser"
            :disabled="roleid == null ? true : false"
            >{{ $t('operatManage.UserRoleAuthorizationObj.delete') }}</el-button
          >
        </div>
      </div>
      <el-divider class="divider" />
      <el-table
        :data="usertableData"
        stripe
        style="width: 100%"
        height="85%"
        @selection-change="handleSelectionChange"
        :header-cell-style="{
          background: 'transparent',
        }"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="id"
          :label="$t('operatManage.UserRoleAuthorizationObj.serialNumber')"
        >
        </el-table-column>
        <el-table-column
          prop="resName"
          :label="$t('operatManage.UserRoleAuthorizationObj.name')"
        >
        </el-table-column>
        <el-table-column
          prop="server"
          :label="$t('operatManage.UserRoleAuthorizationObj.server')"
        >
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px; text-align: center" class="pagination_box">
        <el-pagination
          @size-change="userhandleSizeChange"
          @current-change="userhandleCurrentChange"
          :current-page="userlistData.pageIndex"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="userlistData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="usercount"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      :title="$t('operatManage.UserRoleAuthorizationObj.Added')"
      :visible.sync="dialogTableVisible"
    >
      <el-table
        :data="gridData"
        height="40vh"
        @selection-change="addhandleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="id"
          :label="$t('operatManage.UserRoleAuthorizationObj.serialNumber')"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          :label="$t('operatManage.UserRoleAuthorizationObj.name')"
        >
        </el-table-column>
        <el-table-column
          prop="server"
          :label="$t('operatManage.UserRoleAuthorizationObj.server')"
        >
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px; text-align: center" class="pagination_box">
        <el-pagination
          @size-change="addhandleSizeChange"
          @current-change="addhandleCurrentChange"
          :current-page="addlistData.pageIndex"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="addlistData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="addcount"
        >
        </el-pagination>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">{{
          $t('dataManage.dictionaryManageObj.cancel')
        }}</el-button>
        <el-button type="primary" @click="addConfirm">{{
          $t('dataManage.dictionaryManageObj.confirm')
        }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import MyBread from '../../components/MyBread.vue';
import {
  queryDepTree,
  select_Role_ByPageAndCount,
  roleReselectByPageAndCount,
  roleResDeletes,
  resSelectCountForRole,
  roleResInserts,
} from '../../api/api';
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    MyBread,
  },
  data() {
    return {
      addcount: 0,
      gridData: [],
      addlistData: {
        pageIndex: 1,
        pageSize: 10,
      },
      dialogTableVisible: false,
      usertableData: [],
      userlistData: {
        pageIndex: 1,
        pageSize: 10,
      },
      usercount: 0,
      tableData: [],
      //   å½“前选择的行的id
      templateSelection: '',
      //   å½“前选择的行的数据
      checkList: [],
      defaultProps: {
        children: 'children',
        label: 'name',
      },
      oriData: [], //原始树数据
      depList: [], //el树数据
      backUpData: {},
      formLabelWidth: '170px',
      listData: {
        pageIndex: 1,
        pageSize: 10,
      },
      count: 0,
      usermultipleSelection: [],
      debid: null,
      roleid: null,
      addmultipleSelection: [],
    };
  },
  methods: {
    addConfirm() {
      this.$confirm('确定是否新增', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          let arr = [];
          this.addmultipleSelection.forEach((e) => {
            arr.push({ resid: e.id, roleid: this.roleid });
          });
          const data = await roleResInserts(arr);
          if (data.code !== 200) {
            return this.$message.error('新增失败');
          }
          this.$message({
            type: 'success',
            message: '新增成功!',
          });
          this.dialogTableVisible = false;
          this.getuserList();
        })
        .catch(() => {});
    },
    adduser() {
      this.dialogTableVisible = true;
      this.getadduserList();
    },
    //用户删除
    async deletesUser() {
      let arr = [];
      this.usermultipleSelection.forEach((e) => {
        arr.push(e.id);
      });
      const data = await roleResDeletes({ ids: arr.toString() });
      if (data.code !== 200) {
        return this.$message.error('删除失败');
      }
      this.$message({
        message: '删除成功',
        type: 'success',
      });
      this.getuserList();
    },
    //用户表多选
    handleSelectionChange(val) {
      this.usermultipleSelection = val;
    },
    //新增用户表多选
    addhandleSelectionChange(val) {
      this.addmultipleSelection = val;
    },
    // æ–°å¢žç”¨æˆ·è¡¨åˆ†é¡µ
    addhandleSizeChange(val) {
      this.addlistData.pageSize = val;
      this.getadduserList();
    },
    // æ–°å¢žç”¨æˆ·è¡¨åˆ†é¡µ
    addhandleCurrentChange(val) {
      this.addlistData.pageIndex = val;
      this.getadduserList();
    },
    // ç”¨æˆ·è¡¨åˆ†é¡µ
    userhandleSizeChange(val) {
      this.userlistData.pageSize = val;
      this.getuserList();
    },
    // ç”¨æˆ·è¡¨åˆ†é¡µ
    userhandleCurrentChange(val) {
      this.userlistData.pageIndex = val;
      this.getuserList();
    },
    // è§’色表分页
    handleSizeChange(val) {
      this.listData.pageSize = val;
      this.getRole();
    },
    // è§’色表分页
    handleCurrentChange(val) {
      this.listData.pageIndex = val;
      this.getRole();
    },
    // è§’色单选
    singleElection(row) {
      this.templateSelection = row.id;
      this.checkList = this.tableData.filter((item) => item.id === row.id);
      this.userlistData.roleid = row.id;
      this.roleid = row.id;
      this.getuserList();
    },
    // éƒ¨é—¨è¯·æ±‚
    async getMenuTree() {
      //获取目录树最大ID,新建节点使用
      const data = await queryDepTree();
      if (data.code !== 200) {
        return this.$message.error('请求单位报错');
      }
      this.depList = this.treeData(data.result);
    },
    treeData(source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // å¯¹æºæ•°æ®æ·±åº¦å…‹éš†
      return cloneData.filter((father) => {
        // å¾ªçŽ¯æ‰€æœ‰é¡¹
        let branchArr = cloneData.filter((child) => father.id == child.pid); // å¯¹æ¯”ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ''; // ç»™çˆ¶çº§æ·»åŠ ä¸€ä¸ªchildren属性,并赋值
        return father.pid == 0; // è¿”回一级菜单
      });
    },
    // éƒ¨é—¨æ ‘单选
    treeCheck(node, list) {
      //node è¯¥èŠ‚ç‚¹æ‰€å¯¹åº”çš„å¯¹è±¡ã€list æ ‘目前的选中状态对象
      //选中事件在选中后执行,当lis中有两个选中时,使用setCheckedKeys方法,选中一个节点
      if (list.checkedNodes.length > 0) {
        this.listData.depid = node.id;
        this.debid = node.id;
        this.getRole();
        if (list.checkedKeys.length == 2) {
          //单选实现
          this.$refs.treeForm.setCheckedKeys([node.id]);
        }
      } else {
        this.debid = null;
        this.roleid = null;
        this.tableData = [];
        this.usertableData = [];
      }
    },
    async getadduserList() {
      this.addlistData.roleid = this.roleid;
      // this.addlistData.debid = this.debid;
      const data = await resSelectCountForRole(this.addlistData);
      if (data.code !== 200) {
        return this.$message.error('新增资源列表请求错误');
      }
      this.gridData = data.result;
      this.addcount = data.count;
    },
    // ç”¨æˆ·è¡¨è¯·æ±‚
    async getuserList() {
      const data = await roleReselectByPageAndCount(this.userlistData);
      if (data.code !== 200) {
        return this.$message.error('用户资源列表请求错误');
      }
      this.usertableData = data.result;
      this.usercount = data.count;
    },
    // è§’色表请求
    async getRole() {
      const data = await select_Role_ByPageAndCount(this.listData);
      if (data.code !== 200) {
        return this.$message.error('用户角色请求错误');
      }
      this.tableData = data.result;
      this.count = data.count;
      if (data.result == null) {
        this.usertableData = [];
        this.usercount = 0;
      }
    },
  },
  created() {
    this.getMenuTree();
  },
};
</script>
<style lang="less" scoped>
//@import url(); å¼•入公共cssç±»
.menuSettings_box {
  //   background: rgb(240, 242, 245);
  border-radius: 10px;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  .menuSettings_tree {
    position: relative;
    width: 344px;
    height: 100%;
    background: rgb(240, 242, 245);
    padding: 20px;
    border-radius: 10px;
    box-sizing: border-box;
    overflow: auto;
    .saveBtn {
      position: absolute;
      left: 250px;
      top: 23px;
    }
    .menuTreeBox {
      height: 90%;
      overflow: auto;
      .el-tree {
        background: transparent;
        font-size: 15px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        // /deep/ .el-tree-node__label {
        //   font-size: 18px;
        // }
        /deep/ .el-tree-node {
          padding-top: 10px;
          // padding-bottom: 10px;
        }
        /deep/ .el-tree-node:focus > .el-tree-node__content {
          background-color: #b9b9b9;
        }
        /deep/ .el-tree-node__content:hover {
          background-color: rgb(153, 153, 153);
        }
        .btnBox {
          margin-left: 5px;
          .el-button + .el-button {
            margin-left: 5px;
          }
        }
      }
    }
  }
  .menuSettings {
    width: calc(50% - 172px);
    border-radius: 10px;
    background: rgb(240, 242, 245);
    margin-left: 10px;
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
    .title_box {
      background: #fff;
      padding: 10px;
      margin-bottom: 24px;
      display: flex;
      border-radius: 10px;
      border: 1px solid rgb(202, 201, 204);
      box-sizing: border-box;
    }
  }
  .table_box {
    padding: 10px;
    background: #fff;
    border-radius: 5px;
    border: 1px solid rgb(202, 201, 204);
    overflow: auto;
    height: 85%;
  }
  .divider {
    margin-top: 8px;
  }
}
.el-table,
.el-table /deep/ .el-table__expanded-cell {
  background-color: transparent;
}
.el-table /deep/ th,
.el-table /deep/ tr {
  background-color: transparent;
}
</style>