月球大数据地理空间分析展示平台-【中台】
Surpriseplus
2023-07-21 195d6ddb7cb975cd60e61830812282d7017b7e20
src/views/AuthorizationManagement/roleResAuthorization.vue
@@ -123,50 +123,15 @@
          </div>
        </div>
        <el-divider class="divider" />
        <el-table
          :data="usertableData"
          border
          style="width: 100%"
          height="calc(100% - 80px)"
          @selection-change="handleSelectionChange"
        <el-tree
          ref="tree"
          :props="defaultLayerrops"
          node-key="resid"
          :data="layerData"
          show-checkbox
          :default-expanded-keys="[1]"
        >
          <el-table-column
            type="selection"
            width="55"
          > </el-table-column>
          <el-table-column
            align="center"
            type="index"
            :label="$t('dataManage.styleObj.index')"
          />
          <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: 10px; text-align: center"
          class="pagination_box"
        >
          <el-pagination
            @size-change="userhandleSizeChange"
            @current-change="userhandleCurrentChange"
            :current-page="userlistData.pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="userlistData.pageSize"
            layout="prev, pager, next"
            :total="usercount"
          >
          </el-pagination>
        </div>
        </el-tree>
      </div>
    </div>
@@ -243,6 +208,10 @@
  roleResDeletes,
  resSelectCountForRole,
  roleResInserts,
  res_selectAll,
  roleRes_selectResByRole,
  roleRes_inserts,
  roleRes_deletes
} from '../../api/api';
export default {
  //import引入的组件需要注入到对象中才能使用
@@ -275,7 +244,10 @@
      templateSelection: '',
      //   当前选择的行的数据
      checkList: [],
      defaultLayerrops: {
        children: "children",
        label: "cnName",
      },
      defaultProps: {
        children: 'children',
        label: 'name',
@@ -293,6 +265,9 @@
      debid: null,
      roleid: null,
      addmultipleSelection: [],
      layerData: [],
      layeroption: []
    };
  },
  methods: {
@@ -321,50 +296,91 @@
        })
        .catch(() => { });
    },
    adduser() {
      this.dialogTableVisible = true;
      this.getadduserList();
    async adduser() {
      var val = this.$refs.tree.getCheckedNodes(false, true); // 利用这个方法就可以获取到子节点+父节点)
      var std = [];
      for (var i in val) {
        if (val[i].id == 0) {
          val[i].roleid = this.roleid
          std.push(val[i])
        }
      }
      if (std.length == 0) {
        return
      }
      const data = await roleRes_inserts(std)
      if (data.code != 200) {
        this.$message.error('授权失败');
      } else {
        this.$message({
          type: 'success',
          message: '授权成功!',
        });
      }
      this.getuserList();
      // this.dialogTableVisible = true;
      // this.getadduserList();
    },
    //用户删除
    async deletesUser() {
      let arr = [];
      this.usermultipleSelection.forEach((e) => {
        arr.push(e.id);
      });
      this.$confirm('此操作将永久删除该权限, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = await roleResDeletes({ ids: arr.toString() });
        if (data.code == 200) {
          this.InsertFormdialog = false;
          this.$message({
            message: '删除成功!',
            type: 'success',
          });
          this.getuserList();
      var val = this.$refs.tree.getCheckedNodes(false, true); // 利用这个方法就可以获取到子节点+父节点)
      var std = [];
      for (var i in val) {
        if (val[i].id > 0) {
          std.push(val[i].id)
        }
      }
      var res = this.layeroption;
      var arr = [];
      for (var i in res) {
        if (res[i].id > 0 && std.indexOf(res[i].id) == -1) {
          arr.push(res[i].id)
        }
      }
      if (arr.length == 0) {
        return
      }
      const data = await roleRes_deletes({ ids: arr.toString() });
      if (data.code != 200) {
        this.$message.error('授权失败');
        } else {
          this.$message({
            message: '删除失败!',
            type: 'warning',
          type: 'success',
          message: '授权成功!',
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
      this.getuserList()
      // let arr = [];
      // this.usermultipleSelection.forEach((e) => {
      //   arr.push(e.id);
      // });
      // this.$confirm('此操作将永久删除该权限, 是否继续?', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(async () => {
      // const data = await roleResDeletes({ ids: arr.toString() });
      // if (data.code !== 200) {
      //   return this.$message.error('删除失败');
      // }
      //   if (data.code == 200) {
      //     this.InsertFormdialog = false;
      // this.$message({
      //   message: '删除成功',
      //       message: '删除成功!',
      //   type: 'success',
      // });
      // this.getuserList();
      //   } else {
      //     this.$message({
      //       message: '删除失败!',
      //       type: 'warning',
      //     });
      //   }
      // }).catch(() => {
      //   this.$message({
      //     type: 'info',
      //     message: '已取消删除'
      //   });
      // });
    },
    //用户表多选
    handleSelectionChange(val) {
@@ -403,6 +419,35 @@
    handleCurrentChange(val) {
      this.listData.pageIndex = val;
      this.getRole();
    },
    //获取资源列表
    async getlayerTree() {
      this.layerData = []
      const data = await res_selectAll();
      if (data.code != 200) {
        return this.$message.error("图层列表查询失败");
      }
      var val = this.setTreeData(data.result);
      val.sort(function (a, b) {
        return a.sort - b.sort
      })
      this.layerData = val
    },
    setTreeData(source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
      return cloneData.filter((father) => {
        // 循环所有项
        let branchArr = cloneData.filter((child) => father.resid == child.pid);
        if (branchArr.length > 0) {
          branchArr.sort(function (a, b) {
            return a.sort - b.sort
          })
        }
        branchArr.length > 0 ? (father.children = branchArr) : ""; // 给父级添加一个children属性,并赋值
        // 属于同一对象问题,例如:令 a=b、c=1 ,然后再令 b.c=c , 那么 a.c=b.c=c=1 ;同理,后续令 c.d=2 ,那么 a.c.d 也是=2;
        // 由此循环多次后,就能形成相应的树形数据结构
        return father.pid == 0; // 返回一级菜单
      });
    },
    // 角色单选
    singleElection(row) {
@@ -452,25 +497,41 @@
      }
    },
    async getadduserList() {
      this.addlistData.roleid = this.roleid;
      // 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.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;
      // this.gridData = data.result;
      // this.addcount = data.count;
    },
    // 用户表请求
    async getuserList() {
      const data = await roleReselectByPageAndCount(this.userlistData);
      this.layerData = [];
      this.layeroption = [];
      const data = await roleRes_selectResByRole({ roleid: this.userlistData.roleid });
      if (data.code !== 200) {
        return this.$message.error('用户资源列表请求错误');
        return this.$message.error('根据ID查询资源失败');
      }
      this.usertableData = data.result;
      this.usercount = data.count;
      var std = [];
      this.layeroption = data.result;
      for (var i in data.result) {
        if (data.result[i].id > 0 && data.result[i].type != 1) {
          std.push(data.result[i].resid)
        }
      }
      var val = this.setTreeData(data.result);
      val.sort(function (a, b) {
        return a.sort - b.sort
      })
      this.layerData = val
      this.$refs.tree.setCheckedKeys(std);
    },
    // 角色表请求
    async getRole() {
@@ -508,6 +569,7 @@
      }
    }
    this.getMenuTree();
    // this.getlayerTree();
  },
};
</script>