RuoYi
2022-08-21 2952cb2c4fd1c51e28c6a6d6728f505155d4ee47
优化多角色数据权限匹配规则
已修改5个文件
63 ■■■■■ 文件已修改
src/api/system/dept.js 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/system/role.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/system/user.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/role/index.vue 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/user/index.vue 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/system/dept.js
@@ -25,22 +25,6 @@
  })
}
// 查询部门下拉树结构
export function treeselect() {
  return request({
    url: '/system/dept/treeselect',
    method: 'get'
  })
}
// 根据角色ID查询部门树结构
export function roleDeptTreeselect(roleId) {
  return request({
    url: '/system/dept/roleDeptTreeselect/' + roleId,
    method: 'get'
  })
}
// 新增部门
export function addDept(data) {
  return request({
src/api/system/role.js
@@ -109,3 +109,11 @@
    params: data
  })
}
// 根据角色ID查询部门树结构
export function deptTreeSelect(roleId) {
  return request({
    url: '/system/role/deptTree/' + roleId,
    method: 'get'
  })
}
src/api/system/user.js
@@ -125,3 +125,11 @@
    params: data
  })
}
// 查询部门下拉树结构
export function deptTreeSelect() {
  return request({
    url: '/system/user/deptTree',
    method: 'get'
  })
}
src/views/system/role/index.vue
@@ -262,9 +262,8 @@
</template>
<script setup name="Role">
import { addRole, changeRoleStatus, dataScope, delRole, getRole, listRole, updateRole } from "@/api/system/role";
import { addRole, changeRoleStatus, dataScope, delRole, getRole, listRole, updateRole, deptTreeSelect } from "@/api/system/role";
import { roleMenuTreeselect, treeselect as menuTreeselect } from "@/api/system/menu";
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
const router = useRouter();
const { proxy } = getCurrentInstance();
@@ -462,8 +461,8 @@
  });
}
/** 根据角色ID查询部门树结构 */
function getRoleDeptTreeselect(roleId) {
  return roleDeptTreeselect(roleId).then(response => {
function getDeptTree(roleId) {
  return deptTreeSelect(roleId).then(response => {
    deptOptions.value = response.depts;
    return response;
  });
@@ -543,12 +542,12 @@
/** 分配数据权限操作 */
function handleDataScope(row) {
  reset();
  const roleDeptTreeselect = getRoleDeptTreeselect(row.roleId);
  const deptTreeSelect = getDeptTree(row.roleId);
  getRole(row.roleId).then(response => {
    form.value = response.data;
    openDataScope.value = true;
    nextTick(() => {
      roleDeptTreeselect.then(res => {
      deptTreeSelect.then(res => {
        nextTick(() => {
          if (deptRef.value) {
            deptRef.value.setCheckedKeys(res.checkedKeys);
src/views/system/user/index.vue
@@ -350,8 +350,7 @@
<script setup name="User">
import { getToken } from "@/utils/auth";
import { treeselect } from "@/api/system/dept";
import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser } from "@/api/system/user";
import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser, deptTreeSelect } from "@/api/system/user";
const router = useRouter();
const { proxy } = getCurrentInstance();
@@ -429,8 +428,8 @@
  proxy.$refs["deptTreeRef"].filter(val);
});
/** 查询部门下拉树结构 */
function getTreeselect() {
  treeselect().then(response => {
function getDeptTree() {
  deptTreeSelect().then(response => {
    deptOptions.value = response.data;
  });
};
@@ -550,15 +549,6 @@
function submitFileForm() {
  proxy.$refs["uploadRef"].submit();
};
/** 初始化部门数据 */
function initTreeData() {
  // 判断部门的数据是否存在,存在不获取,不存在则获取
  if (deptOptions.value === undefined) {
    treeselect().then(response => {
      deptOptions.value = response.data;
    });
  }
};
/** 重置操作表单 */
function reset() {
  form.value = {
@@ -585,7 +575,6 @@
/** 新增按钮操作 */
function handleAdd() {
  reset();
  initTreeData();
  getUser().then(response => {
    postOptions.value = response.posts;
    roleOptions.value = response.roles;
@@ -597,7 +586,6 @@
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  initTreeData();
  const userId = row.userId || ids.value;
  getUser(userId).then(response => {
    form.value = response.data;
@@ -631,6 +619,6 @@
  });
};
getTreeselect();
getDeptTree();
getList();
</script>