优化分类树加载逻辑,新增批量查询子节点接口以减少数据库往返,提升性能。重构相关服务和控制器,确保系统的可维护性和扩展性。

This commit is contained in:
geht
2026-05-15 09:58:30 +08:00
parent bc1de2c765
commit ffc390f3de
8 changed files with 85 additions and 13 deletions

View File

@@ -114,6 +114,8 @@ const { tableContext, onExportXls, onImportXls } = useListPage({
title: '密炼物料信息',
api: list,
columns,
// 避免:表格默认 immediate 请求一次 + onMounted 末尾 reload 再请求一次(进入页列表闪两次)
immediate: false,
canResize: true,
formConfig: { labelWidth: 120, schemas: searchFormSchema, autoSubmitOnEnter: true, showAdvancedButton: true },
actionColumn: { width: 120 },
@@ -227,9 +229,8 @@ function findNodeByKey(nodes: Recordable[], key: string): Recordable | null {
async function loadCategoryTree() {
treeLoading.value = true;
try {
const root = await fetchMaterialCategoryRoot();
const [root, res] = await Promise.all([fetchMaterialCategoryRoot(), loadCategoryTreeRoot({ async: false, pcode: 'XSLMES_MATERIAL' })]);
materialCategoryRootId.value = root?.id != null ? String(root.id) : '';
const res = await loadCategoryTreeRoot({ async: false, pcode: 'XSLMES_MATERIAL' });
rawCategoryTree.value = Array.isArray(res) ? res : [];
if (!materialCategoryRootId.value || !rawCategoryTree.value.length) {
createMessage.warning('未加载到物料分类树,请确认分类字典根编码 XSLMES_MATERIAL 已存在。');