This commit is contained in:
zlwu committed 2025-12-23 23:11:27 +08:00
1 parent fca7096e9f
commit 86401c7753
2 files changed
+62 -37

No files matched your search

@@ -122,6 +122,12 @@ public class XgStudentMsgController extends BaseController {
deptIdValue = requestBody.get("dept_id");
}
// 如果请求体中显式包含 dept_id 且值为 null,则按需求返回空数据
if (requestBody.containsKey("dept_id") && requestBody.get("dept_id") == null) {
log.info("listByDeptId - 请求中 dept_id 为 null,返回空分页数据");
return TableDataInfo.build(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>());
}
if (deptIdValue != null) {
deptParams.put("dept_id", deptIdValue);
}
@@ -786,6 +792,11 @@ public class XgStudentMsgController extends BaseController {
@PostMapping("/advancedSearch")
public TableDataInfo<XgStudentMsgVo> advancedSearch(@RequestBody XgStudentMsgAdvancedSearchBo bo) {
log.info("接收到高级检索请求,检索条件: {}", bo);
// 如果前端显式传入 deptIds 且为一个空列表,按需求直接返回空分页数据
if (bo != null && bo.getDeptIds() != null && bo.getDeptIds().isEmpty()) {
log.info("advancedSearch - 请求中 deptIds 为空列表,返回空分页数据");
return TableDataInfo.build(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>());
}
return xgStudentMsgService.advancedSearch(bo);
}
@@ -12,27 +12,30 @@
<el-radio-button label="normal">{{ normalClassStatusLabel }}</el-radio-button>
</el-radio-group>
</div>
<el-tree
ref="deptTreeRef"
class="mt-2 dept-tree"
node-key="id"
:data="deptOptions"
:props="{ label: 'label', children: 'children', disabled: 'disabled' }"
:expand-on-click-node="false"
:filter-node-method="filterNode"
highlight-current
default-expand-all
@node-click="handleNodeClick"
>
<template #default="{ data }">
<div class="dept-tree-node">
<span class="dept-tree-node__label">{{ data.label }}</span>
<el-tag v-if="isClassNode(data) && data.classStatus" size="small" effect="light" :type="getClassStatusTagType(data.classStatus)">
{{ getClassStatusLabel(data.classStatus) }}
</el-tag>
</div>
</template>
</el-tree>
<template v-if="deptOptions && deptOptions.length > 0">
<el-tree
ref="deptTreeRef"
class="mt-2 dept-tree"
node-key="id"
:data="deptOptions"
:props="{ label: 'label', children: 'children', disabled: 'disabled' }"
:expand-on-click-node="false"
:filter-node-method="filterNode"
highlight-current
default-expand-all
@node-click="handleNodeClick"
>
<template #default="{ data }">
<div class="dept-tree-node">
<span class="dept-tree-node__label">{{ data.label }}</span>
<el-tag v-if="isClassNode(data) && data.classStatus" size="small" effect="light" :type="getClassStatusTagType(data.classStatus)">
{{ getClassStatusLabel(data.classStatus) }}
</el-tag>
</div>
</template>
</el-tree>
</template>
<div v-else class="no-dept-placeholder" style="padding: 20px; color: #909399; text-align: center">暂无数据</div>
</el-card>
</div>
@@ -2423,20 +2426,24 @@ const getDeptTree = async () => {
await rebuildDeptTree(treeData, true);
return;
}
console.warn('部门树数据格式不符合预期,尝试使用备选接口');
const backup = await api.deptTreeSelect();
const backupTree = extractDeptTreeData(backup);
if (backupTree.length > 0) {
await rebuildDeptTree(backupTree, true);
}
// 主接口返回空数据:保持树为空,但仍需触发学生列表查询(dept_id 为 null)
rawDeptOptions.value = [];
deptOptions.value = [];
currentSelectedNode.value = null;
queryParams.deptId = undefined;
deptTreeRef.value?.setCurrentKey(undefined);
// 触发学生列表查询(允许后端根据 dept_id 为 null 返回空或全部数据)
getList();
} catch (error) {
console.error('获取部门树失败:', error);
// 如果API调用失败,可以使用默认的deptTreeSelect作为备选
const backup = await api.deptTreeSelect();
const backupTree = extractDeptTreeData(backup);
if (backupTree.length > 0) {
await rebuildDeptTree(backupTree, true);
}
// 出错时也不要调用备选接口或使用 mock 数据,保持树为空,但仍触发学生列表查询
rawDeptOptions.value = [];
deptOptions.value = [];
currentSelectedNode.value = null;
queryParams.deptId = undefined;
deptTreeRef.value?.setCurrentKey(undefined);
getList();
}
};
@@ -2473,12 +2480,19 @@ const setDefaultRootNode = (treeData: any[]) => {
// 触发数据查询
getList();
} else {
// 如果没有找到可用节点,则直接查询全部数据
getList();
// 如果没有找到可用节点(例如仅有占位节点或所有节点都被禁用),不要自动查询学生列表
currentSelectedNode.value = null;
queryParams.deptId = undefined;
deptTreeRef.value?.setCurrentKey(undefined);
}
} else {
// 如果没有树数据,则直接查询全部数据
getList();
// 如果没有树数据,则保持树数据为空并且不要触发学生列表查询
currentSelectedNode.value = null;
queryParams.deptId = undefined;
rawDeptOptions.value = [];
deptOptions.value = [];
// 清除树选择
deptTreeRef.value?.setCurrentKey(undefined);
}
};