feat(仓库管理): 实现两级懒加载树结构并重构库位选择组件

- 在 actualWarehouse.js 中新增两级树结构 API
- 重构 real.vue 使用懒加载方式展示仓库树
- 将 ActualWarehouseSelect 组件从 el-select 改为 el-cascader 实现级联选择
- 优化树形表格的展开逻辑和加载性能
This commit is contained in:
砂糖
2025-11-25 10:58:32 +08:00
parent 5d4eac555a
commit 67dbb34c28
3 changed files with 180 additions and 117 deletions

View File

@@ -65,8 +65,11 @@
:data="filteredTreeData"
row-key="actualWarehouseId"
:default-expand-all="isExpandAll"
:expand-row-keys="expandRowKeys"
class="warehouse-table"
:tree-props="{ children: 'children' }"
lazy
:load="handleLoad"
>
<el-table-column label="层级" align="center">
<template slot-scope="scope">
@@ -331,10 +334,12 @@ import {
addActualWarehouse,
updateActualWarehouse,
createActualWarehouseHierarchy,
importActualWarehouse
importActualWarehouse,
treeActualWarehouseTwoLevel
} from "@/api/wms/actualWarehouse";
import QRCode from "../print/components/QRCode.vue";
import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect";
import { listActualWarehouse } from "../../../api/wms/actualWarehouse";
const LEVELS = [1, 2, 3];
const LEVEL_LABELS = {
@@ -350,7 +355,7 @@ export default {
return {
showSearch: true,
loading: false,
isExpandAll: true,
isExpandAll: false,
warehouseTree: [],
filteredCache: [],
nodeIndex: {},
@@ -416,6 +421,9 @@ export default {
return this.warehouseTree;
}
return this.filterTree(this.warehouseTree, keyword, levelFilter);
},
expandRowKeys() {
return this.warehouseTree.map(item => item.actualWarehouseId);
}
},
created() {
@@ -442,9 +450,17 @@ export default {
},
getTreeData() {
this.loading = true;
listActualWarehouseTree({ actualWarehouseName: this.queryParams.keyword })
treeActualWarehouseTwoLevel({ actualWarehouseName: this.queryParams.keyword })
.then(res => {
const list = res.data || [];
const list = res.data.map(item => {
// 便利item的children中的每一项
item.children = item.children || [];
item.children.forEach(child => {
delete child.children;
child.hasChildren = true;
});
return item;
}) || [];
this.decorateTree(list);
})
.finally(() => {
@@ -500,6 +516,21 @@ export default {
this.toggleTreeRows(this.filteredTreeData, this.isExpandAll);
});
},
handleLoad(treeData, treeNode, resolve) {
console.log(treeData, treeNode);
listActualWarehouse({ parentId: treeData.actualWarehouseId })
.then(res => {
const list = res.data.map(item => {
item.hasChildren = false;
item.level = treeData.level + 1;
return item;
}) || [];
resolve(list);
})
.catch(() => {
resolve([]);
});
},
toggleTreeRows(nodes, expand) {
const table = this.$refs.treeTable;
if (!table || !Array.isArray(nodes)) return;