若依VUE3.0获取子部门流程

前端:

在ruoyi-ui/src/api/system/dept.js文件中加入:

// 查询子部门列表
export function listDeptChild(deptId) {
  return request({
    url: '/system/dept/list/child/' + deptId,
    method: 'get'
  })

在需要获取的.vue文件中加入:

import { listDeptChild } from "@/api/system/dept"; 

然后在data中加入:

const deptList = ref([]);

并加入函数:

function getDeptList() {
  loading.value = true;
  listDeptChild('102').then(response => {
    deptList.value = response.rows;
    loading.value = false;
  });
}

其中,我这里需要获取的是父节点ID为102的所有部门。

如果没定义过loading和proxy,需要定义:

const { proxy } = getCurrentInstance();
const loading = ref(true);

前端就能获取到子部门的信息到deptList中。

后端:

在ruoyi-admin/src/main/java/com/ruoyi/web/system/SysDeptController文件中加入:

    /**
     * 根据父节点获取子部门列表
     */
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list/child/{deptId}")
    public TableDataInfo getchilddeptlist(@PathVariable(value = "deptId", required = false) Long deptId)
    {
        List<SysDept> depts = deptService.selectChildrenDeptById(deptId);
        return getDataTable(depts);
    }

在ruoyi-system/src/main/java/com/ruoyi//system/mapper/SysDeptMapper中加入:

    List<SysDept> selectChildrenDeptById(Long deptId);

在ruoyi-system/src/main/java/com/ruoyi//system/service/ISysDeptService中加入:

    List<SysDept> selectChildrenDeptById(Long deptId);

在ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl中加入:

     /**
     * 获取子节点所有部门信息
     */
    @Override
    public List<SysDept> selectChildrenDeptById(Long deptId) {
        return deptMapper.selectChildrenDeptById(deptId);
    }

在resources中对应的SysDeptMapper.xml中有了对应的查询语句,所以不需要再加入。

	<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
		select * from sys_dept where find_in_set(#{deptId}, ancestors)
	</select>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值